akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

int main(){
    ll A,B,N;
    cin >> A >> B >> N;
    if(B-1<=N){
        cout << (A*(B-1LL))/B << enld;
    }else{
        cout << (A*N)/B << enld;
    }
    return 0;
}

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

int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a+b<c+d) cout<<"Right"<<endl;
  else if(a+b>c+d) cout<<"Left"<<endl;
  else cout<<"Balanced"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>

using namespace std;

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

    int Arr[N] = {0};
    for (int i = 0; i < N; i++){
        cin >> Arr[i];
    }

    int Cnt = 0;
    int MinIndex = 0;
    for (int i = 0; i < N; i++){
        MinIndex = i;
        for (int j = i; j < N; j++){
            if (Arr[j] < Arr[MinIndex]){
                MinIndex = j;
            }
        }
        swap(Arr[i], Arr[MinIndex]);
        if (i != MinIndex) Cnt++;
    }

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

    return 0;
}



Measured memory_bytes: 3104
n, a, b, c = map(int, input().split())
ABC = [a, b, c]
l = []
for i in range(n):
	l.append(int(input()))
# = input()
# = list(map(int, input().split()))

mi = -1
for i in range(4**n):
	j = i
	p = []
	m = n-1
	while m >= 0:
		p.append(j//(4**m))
		j = j%(4**m)
		m -= 1
	abc = [0 for k in range(3)]
	cnt = -30
	for k in range(n):
		if p[k] != 3:
			cnt += 10
			abc[p[k]] += l[k]
	if 0 not in abc:
		for k in range(3):
			cnt += abs(ABC[k] - abc[k])
		if mi == -1:
			mi = cnt
		else:
			mi = min(cnt, mi)
print(mi)


Measured memory_bytes: 3064
private fun readInts() = readLine()!!.split(" ").map { it.toInt() }
private fun readLongs() = readLine()!!.split(" ").map { it.toLong() }

fun main(args: Array<String>) {
    val (A, B) = readInts()

    println(if (B % A == 0) A + B else B - A)
}

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

vector<int> ans;
int solve(int n, int k)
{
    if (n % k == 0)
        return solve(n / k, k);
    return n % k;
}

signed main()
{
    int n;
    cin >> n;
    int ans = 1 + (n > 2 ? 1 : 0);
    for (int k = 2; k * k <= n; k++)
        if (solve(n, k) == 1)
        {
            if (n % k == 0 && k * k != n)
            {
                if (solve(n, n / k) == 1)
                    ans++;
            }
            else if (n % k == 1 && k * k != n - 1)
            {
                if (solve(n, (n - 1) / k) == 1)
                    ans++;
            }
            ans++;
        }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

def main():
    N, x = LI()
    A = [0] + LI()
    ans = 0
    for i in range(1, N + 1):
        red = A[i] + A[i - 1] - x
        if red > 0:
            ans += red
            A[i] -= red

    return ans

print(main())

Measured memory_bytes: 14620
#include<stdio.h>
#define N 100

void selection(int *,int);

int main(){

  int i,n,array[N];

  scanf("%d",&n);

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


  selection(array,n);

  return 0;
}

void selection(int A[],int n){
  int i,j,cnt=0,minj,tmp;

  for(i=0;i<n-1;i++){
    minj=i;
    for(j=i;j<n;j++){
      if(A[j]<A[minj]){
	minj=j;
      }
    }
    tmp=A[i];
      A[i]=A[minj];
      A[minj]=tmp;
    if(minj!=i)cnt++;
  }

  for(i=0;i<n;i++){
    printf("%d",A[i]);
    if(i!=n-1)printf(" ");
  }
  printf("\n%d\n",cnt);
}



Measured memory_bytes: 2104
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>
#include <stack>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

const ll mod = 1e9 + 7;
const ll mmod = 998244353;

vector<ll> dx = {1, -1, 0, 0};
vector<ll> dy = {0, 0, 1, -1};

vector<vector<ll>> g;
vector<vector<ll>> par;
vector<vector<ll>> dp;
vector<ll> d;


int main() {
    
    
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    
    ll x, n;
    cin >> x >> n;
    
    set<ll> s;
    
    for (int i = 0; i < n; ++i)
    {
        ll tmp;
        cin >> tmp;
        s.insert(tmp);
    }
    for (int i = 0; i < 105; ++i)
    {
        if (s.count(x - i) == 0)
        {
            cout << x - i << endl;
            return 0;
        }
        if (s.count(x + i) == 0)
        {
            cout << x + i << endl;
            return 0;
        }
    }
    
    return 0;
}

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

int main() {
    ll K, A, B;
    cin >> K >> A >> B;

    ll ans = 0;
    if (B - A <= 2) ans = K + 1;
    else {
        ll sell_num = (K - (A - 1)) / 2;
        ans = sell_num * (B - A) + A;
        if (K - 2 * sell_num - (A - 1) == 1) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define faster cin.tie(0);ios_base::sync_with_stdio(0)
#define ll long long

int n,k;
ll arr[3004];


// fun(i,j)=arr[i]+fun(i+1,j),arr[j]+fun(i,j-1);

ll dp[3004][3004];

ll find(int i,int j)
{
	if(i>j) return 0;
	if(i==j) return arr[i];
	if(i+1==j) return max(arr[i],arr[j]);
	
	
	if(dp[i][j]!=-1) return dp[i][j];
	
	// player 1 picks left
	ll cost1=arr[i]+min(find(i+1,j-1),find(i+2,j));

	// player 2 picks right
	ll cost2=arr[j]+min(find(i+1,j-1),find(i,j-2));

	return dp[i][j]=max(cost1,cost2);
	
}

int main()
{
	memset(dp,-1,sizeof(dp));
	int n;cin>>n;
	ll sum=0;
	for(int i=0;i<n;i++) 
	{
		cin>>arr[i];
		sum+=arr[i];
	}
	// cout<<sum<<endl;
	ll x=find(0,n-1);
	ll y=sum-x;
	cout<<(x-y)<<endl;
	
}
	


Measured memory_bytes: 70912
fun main(args: Array<String>) {
    a93(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}


fun a93(args: Array<String>) {
    if (args.size != 1) {
        throw IllegalArgumentException()
    }
    val strSet = args[0].toSet()
    println(if (strSet.toSet().containsAll(listOf('a', 'b', 'c'))) "Yes" else "No")
}

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

int main(){
  int n;
  char s[110];
  cin >> n;
  
  int y = 0;

  for(int i = 0; i < n; ++i){
	cin >> s[i];
	if(s[i] == 'Y') ++y;
	}

  if(y != 0) cout << "Four" << endl;
  else cout << "Three" << endl;
  
  return 0;
}

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

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    int N, K;
    cin >> N >> K;

    vector<ll> a(N);
    REP(i, N) cin >> a[i];

    REP(i, N-K) {
        if (a[i] < a[K+i]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 4784
#include <bits/stdc++.h>
using std::cout;
using std::endl;
using std::cin;

int main(){
	std::string s; cin >> s;
	int k; cin >> k;
	
	for(char i = 'a'; i <= 'z'; i++){
		std::set<std::string> st;
		for(int j = 0; j < s.size(); j++){
			for(int k = j; k < std::min(j + 5, (int)s.size()); k++){
				if(s[j] != i) continue;
				std::string w = s.substr(j, k - j + 1);
			
				st.insert(w);
			}
		}
		
		if(st.size() < k){
			k -= st.size();
			continue;
		}
		
		int c = 0;
		for(auto s : st){
			c++;
			if(c == k){
				cout << s << endl;
				break;
			}
		}
		break;
	}
	
	return 0;
}


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

struct work {
	int a, b;
};

int compare_int(const struct work *p, const struct work *q)
{
	return p->b - q->b;
}

int main()
{
	unsigned int i, n, time;
	struct work *joblist;

	scanf("%d", &n);

	if ((joblist = (struct work *)malloc(sizeof(struct work) * n)) == NULL)
		return 1;

	for (i = 0; i < n; i++)
		scanf("%d%d", &(joblist[i].a), &(joblist[i].b));

	qsort(joblist, n, sizeof(struct work),
		  compare_int);

	for (i = 0, time = 0; i < n; i++) {
		if (time + joblist[i].a > joblist[i].b) {
			printf("No\n");
			return 0;
		} else
			time += joblist[i].a;
	}

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


Measured memory_bytes: 3324
n = int(input())
s = [int(i) for i in input().split()]
a = []
count = 0
for i in range(n):
    if s[i]%2 == 0:
        a.append(s[i])
for i in range(len(a)):
    while a[i]%2 == 0:
        a[i] = a[i]/2
        count += 1
print(count)

Measured memory_bytes: 4148
#include <bits/stdc++.h>
using namespace std;
const int MAXn = 1e5 + 10, INF = 1e9;

long long last[2 * MAXn], cnt[2 * MAXn], n, ar[MAXn], psum[MAXn];

bool check(int a) {
	fill_n(last, 2 * MAXn, -1);
	fill_n(cnt, 2 * MAXn, 0);
	fill_n(psum, MAXn, 0);
	long long psum1 = 0, ans = 0;
	for (int i = 0; i < n; i++) {
		if (ar[i] > a)
			psum1--;
		else
			psum1++;
		int hp = last[psum1 + MAXn] + 1;
		
		if (psum[hp] < psum1) {
			cnt[psum1 + MAXn] += (i - hp);
		}
		ans += cnt[psum1 + MAXn] + (psum1 > 0);
		last[psum1 + MAXn] = i;
		psum[i] = psum1;
	}
//	cout << ans << endl;
	long long hp2 = (n * (n + 1)) / 2;
	return hp2 / 2 < ans;
}
int main() {
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> ar[i];
	if (n == 1)
		return cout << ar[0],0;
	
	int st = 0, en = INF + 10;
	while(st + 1 < en) {
		int med = (st + en) / 2;
		if (check(med))
			en = med;
		else
			st = med;
	}
	cout << en;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
 
using namespace std;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef long long ll;
typedef long double ld;
 
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define fi first
#define se second
 
template<class T> bool ckmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<class T> bool ckmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

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

    int n;
    cin >> n;
    vi v(n);
    for(auto &z : v)
        cin >> z;

    int maksi = 0;
    ll ans = 0;

    for(int i = 0; i < n; ++i)
    {
        ckmax(maksi, v[i]);
        ans += maksi - v[i];
    }

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


Measured memory_bytes: 3912
N = int(input())
count_AC = 0
count_WA = 0
count_TLE = 0
count_RE = 0 


for i in range(N):
    tmp = str(input())
    if tmp == "AC":
        count_AC += 1
    elif tmp == "WA":
        count_WA += 1
    elif tmp == "TLE":
        count_TLE += 1
    else:
        count_RE += 1

print("AC x " + str(count_AC))
print("WA x " + str(count_WA))
print("TLE x " + str(count_TLE))
print("RE x " + str(count_RE))

Measured memory_bytes: 9204
#include<stdio.h>
#include<algorithm>
int main()
{
	int n,x,y,t;
	int a[100][100],f[100][100];
	while(scanf("%d",&n),n)
	{
		for(y=0;y<n;++y)for(x=0;x<n;++x)f[y][x]=scanf("%d",&a[y][x]);
		for(y=0;y<n;++y)
		{
			t=~(1<<31);
			for(x=0;x<n;++x)t=std::min(t,a[y][x]);
			for(x=0;x<n;++x)if(t==a[y][x])++f[y][x];
		}
		for(x=0;x<n;++x)
		{
			t=1<<31;
			for(y=0;y<n;++y)t=std::max(t,a[y][x]);
			for(y=0;y<n;++y)if(t==a[y][x])++f[y][x];
		}
		for(t=y=0;y<n;++y)for(x=0;x<n;++x)if(f[y][x]>2)t=std::max(t,a[y][x]);
		printf("%d\n",t);
	}
	return 0;
}

Measured memory_bytes: 0
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={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; }

struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};




signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;
    
    
    ll n;
    cin>>n;
    ll ans=0;
    rep2(i,1,n+1){
        ll cnt=0;
        for(ll j=1;j*j<=i;j++){
            if(i%j==0){
                if(j==i/j) cnt++;
                else cnt+=2;
            }
        }
        if(cnt==8&&i%2==1) ans++;
    }
    cout<<ans<<endl;


    return 0;
}


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

struct Node{
  int key;
  Node *n;
  Node *p;
};

Node *nill;

Node init(){
  nill = new Node;
  nill->n = nill;
  nill->p = nill;
}

Node insert_node(int k){
  Node *x = new Node;
  x->key = k;

  x->n = nill->n;
  nill->n->p = x;
  nill->n = x;
  x->p = nill;
}

Node* search_node(int k){
  Node *se = nill->n;
  while(1){
    if(se == nill) break;
    if(se->key == k) break;
    se = se->n;
  }
  return se;
}

void delete_node(Node *k){
  if(k == nill) return;
  k->p->n = k->n;
  k->n->p = k->p;
  delete k;
}

void deleteLast(){
  delete_node(nill->p);
}

void deleteFirst(){
  delete_node(nill->n);
}

void print_node(){
  Node *pri = nill->n;
  bool flag = false;
  while(1){
    if(pri == nill) break;
    if(flag) cout << " ";
    cout << pri->key;
    pri = pri->n;
    flag = true;
  }
  cout << endl;
}

int main(){
  init();
  ios::sync_with_stdio(false);


  int n;
  string str;
  cin >> n;

  for(int i = 0; i < n; i++){
    int k;
    cin >> str;
    if(str == "insert"){
      cin >> k;
      insert_node(k);
    }else if(str == "delete"){
      cin >> k;
      delete_node(search_node(k));
    }else if(str == "deleteFirst"){
      deleteFirst();
    }else if(str == "deleteLast"){
      deleteLast();
    }
  }
  print_node();

}

Measured memory_bytes: 32476
N,M,X,Y=map(int,input().strip().split(" "))
x=input().strip().split(" ")
y=input().strip().split(" ")
x=[int(i) for i in x]
y=[int(i) for i in y]
count=0

x.sort()
y.sort()

for i in range(X+1,Y+1):
    if(x[-1]<i and y[0]>=i):
        count+=1

if(count>0):
    print("No War")
else:
    print("War")


Measured memory_bytes: 3064
#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
#define ck(a) (0<=a&&a<n)
using namespace std;
int main(){
	int n,m,s[100],f; char b[2];
	while(cin>>n>>m,n){
		rep(i,n)s[i]=0;
		rep(i,m){
			cin>>b;
			switch(b[0]){
			case 'A':
				rep(i,n)if(!s[i]){
					s[i]=1; break;
				}
				break;
			case 'B':
				f=1;
				rep(i,n)if(!s[n-1-i])
				if((!ck(n-2-i)||s[n-2-i]!=1)&&(!ck(n-i)||s[n-i]!=1)){
					s[n-1-i]=2,f=0; break;
				}
				if(f)rep(i,n)if(!s[n-1-i]){
					s[n-1-i]=2; break;
				}
				break;
			case 'C':
				f=1;
				rep(i,n)if(s[i]&&(ck(i+1)&&!s[i+1]||ck(i-1)&&!s[i-1])){
					if(ck(i+1)&&!s[i+1])s[i+1]=3;
					else s[i-1]=3;
					f=0; break;
				}
				if(f)s[n/2]=3;
				break;
			case 'D':
				int d,md=0,mdi=0;
				rep(i,n)if(!s[i]){
					for(d=1;i-d>=0||i+d<n;d++)if(ck(i+d)&&s[i+d]||ck(i-d)&&s[i-d])break;
					if(d>md)md=d,mdi=i;
				}
				s[mdi]=4;
				break;
			}
		}
		rep(i,n)cout<<char(s[i]?'A'-1+s[i]:'#'); cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
fun main(args: Array<String>) {
  val input1 = readLine()!!.toInt()
  val result = when (input1 % 10) {
    2, 4, 5, 7, 9 -> "hon"
    0, 1, 6, 8 -> "pon"
    3 -> "bon"
    else -> ""
  }
  println(result)
}


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

int main(){
  int n;
  ll y;
  cin >> n >> y;
  for(int a=0; a<=n; a++)
    for(int b=0; b<=n-a; b++){
    int c = max(0,n-a-b);
    if(y == a*10000+b*5000+c*1000){
      cout << a <<" " << b <<" "<< c;
      return 0;
    }
  }
  cout << -1 <<" " << -1 <<" " << -1;
  return 0;
}

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

int main(){
    int n,m;    cin >> n >> m;
    cout << n*(n-1)/2 + m*(m-1)/2 << endl;
}


Measured memory_bytes: 256
import std.algorithm;
import std.conv;
import std.exception;
import std.stdio;
import std.string;
import std.typecons;
 
struct Queue(T){
    T[900] content;
    size_t head;
    size_t tail;

    T front(){
        enforce(head != tail);
        return content[head];
    }

    void popFront(){
        enforce(head != tail);
        ++head;
    }

    void pushBack(T value){
        content[tail] = value;
        ++tail;
    }

    void clear(){
        head = 0;
        tail = 0;
    }

    size_t length(){
        return tail - head;
    }
}

void main(){
    bool[900][900] M;
    Queue!int queue;
    int[900] d;
    while(true){
        auto input = readln.split;
        if(input[0] == "0" && input[1] == "0"){
            break;
        }
        int w = input[0].to!int;
        int h = input[1].to!int;

        foreach(i; 0..h){
            {
                auto line = readln.split;
                foreach(j; 0..w - 1){
                    if(line[j] == "0"){
                        M[i * w + j][i * w + j + 1] = true;
                        M[i * w + j + 1][i * w + j] = true;
                    }else{
                        M[i * w + j][i * w + j + 1] = false;
                        M[i * w + j + 1][i * w + j] = false;
                    }
                }
            }
            {
                if(i == h - 1){
                    break;
                }
                auto line = readln.split;
                foreach(j; 0..w){
                    if(line[j] == "0"){
                        M[i * w + j][(i + 1) * w + j] = true;
                        M[(i + 1) * w + j][i * w + j] = true;
                    }else{
                        M[i * w + j][(i + 1) * w + j] = false;
                        M[(i + 1) * w + j][i * w + j] = false;
                    }
                }
            }
        }

        d[1..w * h] = 0;
        d[0] = 1;

        queue.clear;
        queue.pushBack(0);

        while(queue.length){
            int v = queue.front;
            queue.popFront;
            if(v - w >= 0 && M[v][v - w] && !d[v - w]){
                d[v - w] = d[v] + 1;
                queue.pushBack(v - w);
            }
            if(v % w + 1 < w && M[v][v + 1] && !d[v + 1]){
                d[v + 1] = d[v] + 1;
                queue.pushBack(v + 1);
            }
            if(v + w < w * h && M[v][v + w] && !d[v + w]){
                d[v + w] = d[v] + 1;
                queue.pushBack(v + w);
            }
            if(v % w - 1 >= 0 && M[v][v - 1] && !d[v - 1]){
                d[v - 1] = d[v] + 1;
                queue.pushBack(v - 1);
            }
        }
        d[w * h - 1].writeln;
    }
}

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

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;

#define endl '\n'
#define ff first
#define ss second
#define int long long
#define pb push_back
#define f(i,l,r) for(ll i=l;i<=r;i++)
#define rf(i,r,l) for(ll i=r;i>=l;i--)
#define Max 5000001
#define inf 2147483647
#define llinf 9223372036854775807
#define all(v) v.begin(),v.end()
#define bp(n) __builtin_popcountll(n)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

#define d0(a) cout<<a<<' ';
#define d1(a) cout<<a<<endl;
#define d2(a,b) cout<<a<<' '<<b<<endl;
#define d3(a,b,c) cout<<a<<' '<<b<<' '<<c<<endl;
#define d4(a,b,c,d) cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
#define d5(a,b,c,d,e) cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<endl;
#define d6(a,b,c,d,e,f) cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<' '<<f<<endl;

const ll N=100,mod=1e9+7,bit=61;
const ld PI=acos(-1.00);

ll a,b,n;

ll fun(ll x)
{
    assert(x<=n);
    ll ans=((a*x)/b)-a*(x/b);
    return ans;
}

signed main()
{
    fast;

    ll t=1;
    //cin>>t;
    while(t--)
    {
        scanf("%lld %lld %lld",&a,&b,&n);
        ll mx=(a*n)/b;
        ll l=0,r=n,x=n;
        while(l<=r)
        {
            ll mid=(l+r)>>1;
            ll nw=(a*mid)/b;
            if(nw==mx)
            {
                x=min(x,mid);
                r=mid-1;
            }
            else
            {
                l=mid+1;
            }
        }
        ll ans=fun(x);
        f(i,0,min(5000000ll,n))
        {
            ans=max(ans,fun(i));
            ans=max(ans,fun(n/max(1ll,i)));
        }
//        f(i,1,5000000)
//        {
//            ll x=i;
//            ll k=min(b*x+b-1,n);
//            ans=max(ans,fun(k));
//            x=b/i;
//            k=min(b*x+b-1,n);
//            ans=max(ans,fun(k));
//        }
        ans=max(ans,fun(min(n,b-1)));
        ans=max(ans,fun(min(n,a)));
        ans=max(ans,fun(n));
        //assert(ans<=fun(min(a,b-1)));
        printf("%lld\n",ans);
    }
    return 0;
}


















Measured memory_bytes: 3852
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 (ll)1E9+7
#define i_5 (ll)1E9+5
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;/*10^12*/
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}

/////////////////////////////////////////////////////
bool check(ll a,ll b){
    while(a>0&&b>0){
        if((a&1)&(b&1))return false;
        a/=2;
        b/=2;
    }
    return true;
}


int main(){
    int n;cin>>n;
    int a[n];rep(i,0,n-1)cin>>a[i];
    ll ans=0;
    int s=0,t=0;//[s,t]
    ll sum=a[0];
    while(t<=n-1){
        while(t<=n-2){
            if(check(sum,a[t+1])){
                sum+=a[t+1];
                t++;
            }else break;
        }
        ans+=t-s+1;
      //  cout<<s<<" "<<ans<<endl;
        sum-=a[s];
        s++;
        if(s>t){
            t=s;
            sum+=a[t];
        }
    }
    
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll LINF = 0x1fffffffffffffff;
template<class T> bool chmin(T& a, const T& b){ if(a > b){ a = b; return 1; } return 0; }

struct SegmentTree{
  ll size = 1;
  vector<ll> data;
  SegmentTree(ll n){
    while(size < n) size *= 2;
    data.assign(size * 2, LINF);
  }
  void update(ll at){
    while(at /= 2) data[at] = min(data[at * 2], data[at * 2 + 1]);
  }
  void set(ll at, ll val){
    at += size;
    data[at] = val;
    update(at);
  }
  ll get(ll l, ll r){
    l += size; r += size;
    ll ans = LINF;
    while(l < r){
      if(l & 1) chmin(ans, data[l++]);
      if(r & 1) chmin(ans, data[--r]);
      l /= 2; r /= 2;
    }
    return ans;
  }
  ll operator[](ll at){ return data[at + size]; }
  void _chmin(ll at, ll val){
    at += size;
    if(::chmin(data[at], val)) update(at);
  }
};

int main(){
  ll n, m;
  cin >> n >> m;
  vector<array<ll, 3>> a(m);
  for(auto& i : a) for(auto& j : i) cin >> j;
  sort(a.begin(), a.end(), [](auto& a, auto& b){ return a[1] < b[1]; });
  SegmentTree seg(n);
  seg.set(0, 0);
  for(auto i : a){
    i[0]--; i[1]--;
    seg._chmin(i[1], seg.get(i[0], i[1]) + i[2]);
  }
  if(seg[n - 1] == LINF) return puts("-1") & 0;
  cout << seg[n - 1] << endl;
}

Measured memory_bytes: 4608
#include <stdio.h>
#include <math.h>

int	main(void)
{
  	int	r;
  	double c;
  	
  	scanf("%d", &r);
  
  	c = 3.1415926535 * r * 2;
  
  	printf("%f", c);
  	return (0);
}

Measured memory_bytes: 1752
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n=0;
  string s;
  cin >> s;
  for (long unsigned int i=0;i<s.size();i++) {
    n+=s.at(i)-'0';
  }
  if(n%9==0){
  cout << "Yes" << endl;
  }
  else{
  cout << "No" << endl;
  }
}

Measured memory_bytes: 3720
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int e[15][15];
int n;
int dp1[1<<15];
int dp2[1<<15][15];
int tmp[15];
void upd(int&x,int y){
	if(x==-1 || x<y)x=y;
}
int main(){
	int m, tot = 0;
	scanf("%d%d",&n,&m);
	while(m--){
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		--x;--y;
		e[x][y] = e[y][x] = z;
		tot += z;
	}
	for(int mask=1; mask < (1<<n); mask ++){
		int t;
		for(t=0; (mask&(1<<t)) == 0; t++);
		dp1[mask] = dp1[mask-(1<<t)];
		for(int i=t+1; i<n; i++)if(mask&(1<<i))
			dp1[mask] += e[t][i];
	}
	memset(dp2,-1,sizeof(dp2));
	for(int mask=1; mask < (1<<n); mask++)if((mask&1)!=0&&(mask&(1<<(n-1)))==0)
		dp2[mask][0] = dp1[mask];

	for(int mask=1; mask < (1<<n); mask++){
		memset(tmp,-1,sizeof(tmp));
		for(int i=0; i<n; i++)if((mask&(1<<i))!=0 && dp2[mask][i] != -1)
		for(int j=0; j<n; j++)if((mask&(1<<j)) == 0 && e[i][j] != 0)
			upd(tmp[j], dp2[mask][i] + e[i][j]);
		int comp = (1<<n) - 1 - mask, b = 0;
		do{
			for(int i=0; i<n; i++)if((b & (1<<i))!=0 && tmp[i]!=-1){
				upd(dp2[mask + b][i], tmp[i] + dp1[b]);
			}
		}while(b=(b-comp)&comp);
	}
	printf("%d\n",tot - dp2[(1<<n)-1][n-1]);
	return 0;
}

Measured memory_bytes: 2176
n,k = map(int, input().split())
r,s,p = map(int, input().split())
t = input()
ans = t.count("r") * p + t.count("s") * r + t.count("p") * s
R,S,P = 0,0,0
ok = [0] * (n+1)
for key,(i,j) in enumerate(zip(t[:-k],t[k:])):
  if i == j:
    if i == "r":
      if ok[key] == 0:
        ans -= p
        ok[key+k] = 1
    elif i == "s":
      if ok[key] == 0:
        ans -= r
        ok[key+k] = 1
    else:
      if ok[key] == 0:
        ans -= s
        ok[key+k] = 1
print(ans)

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

int main() {
	int a,b,c,d;
	int ab,cd;
	cin >> a >> b >> c >> d;
	ab=a*b;
	cd=c*d;
	if(ab>=cd){
		cout << ab;
	}
	else{
		cout << cd;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int array[45];

int Fibonacci(int n){
    if(n == 0 || n == 1) return array[n] = 1;

    if(array[n] != -2) return array[n];

    return array[n] = Fibonacci(n - 2) + Fibonacci(n - 1);
}

int main(){

    int num,i,result;

    scanf("%d",&num);
    for(i=0; i<45; i++) array[i] = -2; /*ｎの範囲は0<n<44なので、てきとうなマイナスの値を配列に入れておく*/
    result = Fibonacci(num);
    printf("%d\n",result);

    return 0;
}



Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define wi(t) int t;cin>>t;while(t--)
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
int mpow(int base, int exp); 
void ipgraph(int n, int m);
void dfs(int u, int par);

const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];

void solve()
    {
     ll int n,k;
     cin>>n;
     bool ok=false;
     for(int i=1;i<=9;i++)
     {
         if(n%i==0&&n/i<=9&&n/i>=1)
         {
             cout<<"Yes"<<endl;
             return;
         }
     }
     cout<<"No"<<endl;

  
  
  
  
    }

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

   // wi(t)
    {
      solve();
    }

    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
    u--, v--;
		g[u].pb(v);
		g[v].pb(u);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}







Measured memory_bytes: 10684
a = list(map(int,input().split()))
N = a[0]
K = a[1]
bucket = [0 for i in range(100001)]
for i in range(N):
    temp = list(map(int,input().split()))
    bucket[temp[0]] += temp[1]
sum = 0
for i in range(100001):
    sum += bucket[i]
    if K <= sum:
        print(str(i))
        break

Measured memory_bytes: 5928
from math import ceil
D,G = map(int,input().split())
P,C,A = [],[],[]
for i in range(D):
    p,c = map(int,input().split())
    P.append(p)
    C.append(c)
    A.append((i+1)*100*p+c)

Ans = []
# 全問解答する得点をbit全探索
for i in range(2**D):
    bits = bin(2**D+i)[3:]
    # 全問解いた時の得点と問題数を計算
    total,ans = 0,0
    for i,b in enumerate(bits):
        if b=="1":
            total += A[i]
            ans += P[i]
    # 目標を超えているなら解答候補に追加
    if total >= G:
        Ans.append(ans)
    # 目標を超えていないなら残りのうち一番得点が高い問題を順次解答
    else:
        j = 0 # 問題の前提から0で問題ない
        for i,b in enumerate(bits):
            if b=="0":
                j = i
        # 必要な残得点が問題数で達成可能かどうか
        res =  G - total
        if res/((j+1)*100) <= P[j]:
            ans += ceil(res/((j+1)*100))
            Ans.append(ans)

# 候補のうち最小のものが答え
print(min(Ans))


Measured memory_bytes: 3064
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,q;
    cin >> n;
    vector<ll> a(n);
    rep(i,n)cin>>a[i];
    int ans=0;
    while(true){
        rep(i,n){
            if(a[i]%2)return cout<<ans<<"\n",0;
            else a[i]/=2;
        }
        ans++;
    }
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc067/tasks/arc078_a
// 5min ~ 10min
#include <stdio.h>

int main(void) {
    int N;
    scanf("%d", &N);

    int ai[N];
    for (int i=0; i<N; i++) {
        scanf("%d", &ai[i]);
    }

    long long total = 0;
    long long sum = 0;
    long long sums[N] = {0};

    // sums[i] is 0 ~ i | i+1 ~ N-1
    for (int i=0; i<N; i++) {
        total += ai[i];

        sum += ai[i];
        sums[i] = sum;
    }

    long long min = 0x7FFFFFFFFFFFFFFFL;
    for (int i=0; i<N-1; i++) {
        long long left = sums[i];
        long long right = total - sums[i];
        
        long long diff = left - right;
        if (diff < 0) {
            diff *= -1;
        }

        if (diff < min) {
            min = diff;
        }
    }

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

    return 0;
}

Measured memory_bytes: 2560
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define f first
#define s second
#define pb push_back
#define pp pop_back
#define mp make_pair
#define ll long long
#define ld double
#define ull unsigned long long
#define PI pair < int, int > 

const int N = 1e6 + 123;
const int M = 123;
const ld Pi = acos(-1);
const ll Inf = 1e18;
const int inf = 1e9;
const int mod = 1e9 + 7;
const int Sz = 501;
const int MOD = 1e9 + 7;

void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
int mult(int a, int b) {
  return 1ll * a * b % mod;
}
int sum(int a, int b) {
  add(a, b);
  return a;
}

int n, m, a[N];
ll Add[N], val[N], cnt[N], AddL[N];

void AddSeg(int l, int r, ll val) {
  Add[l] += val;
  Add[r + 1] -= val;
}
void AddLad(int l, int r, ll val) {
  cnt[l]++;
  cnt[r + 1]--;
  AddL[l] += val;
  AddL[r + 1] -= val;
}

void Duyet(int l, int r) {
  int val;
  //cout << "l = " << l << " r = " << r << " val = " << val << endl;
  if (l <= r) {
    val = r - l;
   // cout << "val = " << val << endl;
    AddSeg(1, l, val);
    if (r < m) AddSeg(r + 1, m, val);
    if (l < r) AddLad(l + 1, r, val + l + 1);
  } else {
    val = r + m - l;
    AddSeg(r + 1, l, val);
    if (l < m) AddLad(l + 1, m, val + l + 1);
    val -= m - l;
    AddLad(1, r, val + 1);
  }
}
void solve() {
  cin >> n >> m;
  for (int i = 1;i <= n;i++) {
    cin >> a[i];
    if (i > 1) {
      Duyet(a[i - 1], a[i]);
    }
  } 
  ll curCnt = 0;
  ll curS = 0;
  ll curL = 0;
  ll ans = 1e18;
  for (int i = 1;i <= m;i++) {
    curCnt += cnt[i];
    curS += Add[i];
    curL += AddL[i];
    ll now = curS + curL - 1ll * curCnt * i;
    ans = min(ans, now);
 //   cout << now << " " << cnt[i] << " curS = " << curS << " curL = " << curL << endl;
  }
  cout << ans << endl;
}

int main() {
  #ifdef wws
   freopen("in", "r", stdin);
  // freopen("out", "w", stdout);
  #endif 
  ios_base::sync_with_stdio(0);
  int tt = 1; 
  while(tt--) solve();
  return 0;
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for(int i=m; i<n; i++)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <typename T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0; }
template <typename T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1;} return 0; }
 
 
int main() {
  int a,b,c,d; cin>>a>>b>>c>>d;
  int i=0;
  while(a>0&&c>0){
      if(i%2==0) c-=b;
      else a-=d;
      i++;
  }
  if(a<=0) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
 
}

Measured memory_bytes: 3596
import collections
n,m = map(int,input().split())
directIn = [set() for _ in range(n+1)]
directOut = [set() for _ in range (n+1)]
value =[0 for _ in range(n+1)]
dq = collections.deque()
for i in range(m):
    a,b = map(int,input().split())
    directOut[a].add(b)
    directIn[b].add(a)
for i in range(1,n+1):
    if not len(directOut[i]):
        dq.append(i)
while len(dq):
    next = dq.popleft()
    for node in directIn[next]:
        directOut[node].remove(next)
        value[node]= max(value[node],value[next]+1)
        if not len(directOut[node]):
            dq.append(node)
print(max(value))

Measured memory_bytes: 90416
#include <stdio.h>

int main(void)
{
	int i;
	int station[10];
	int input_data;
	
	i = 0;
	
	while (scanf("%d", &input_data) != EOF){
		if (input_data != 0){
			station[i] = input_data;
			i++;
		}
		else {
			printf("%d\n", station[i - 1]);
			i--;
		}
	}
	
	return (0);
}

Measured memory_bytes: 0
#include <stdio.h>
int main ()
{
  int W,H,x,y,r;
  scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);

  if(x-r >= 0 && x+r <= W){
    if(y-r >= 0 && y+r <= H){
      printf("Yes\n");
    }
    else{
    printf("No\n");
    }
  }
  else{
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 584
n,m=map(int,input().split())
xxx=list(map(int,input().split()))
yyy=list(map(int,input().split()))
mod=10**9+7

x=[]
y=[]

for i in range(len(xxx)-1):
    x.append(xxx[i+1]-xxx[i])

for i in range(len(yyy)-1):
    y.append(yyy[i+1]-yyy[i])

cnt=0
cnt2=0


for i in range(1,len(x)+1):
    cnt+=x[i-1]*(i)*(len(x)-i+1)
    cnt%=mod

for i in range(1,len(y)+1):
    cnt2+=y[i-1]*(i)*(len(y)-i+1)
    cnt2%=mod

print((cnt*cnt2)%mod)

Measured memory_bytes: 102276
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    ll n; cin>>n;

    cout << n * (n + 1) / 2 - n << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
/////////////////// TYPES & MACROS ///////////////////////////////
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define vv vector
#define exist(s,e) (s.find(e)!=s.end())
#define SZ(x) ((int)(x).size())
#define ll long long
#define int ll
#define el '\n'
template<class T> bool inline rmn(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool inline rmx(T &a, T b) { return a < b ? (a = b, true) : false; }
typedef long double ld; typedef double dd; typedef pair<int, int> pii;
const ll INFLL=0x7f7f7f7f7f7f7f7f, MOD=1e9+7; const int INF=0x7f7f7f7f;

//////////////////// DEBUG /////////////////////////////////////////
#define D(x) cerr<<#x<<" is:\t"<<x<<'\n';
#define DD(x,y) cerr<<'('<<#x<<','<<#y<<") are:\t"<<x<<' '<<y<<'\n';
#define DDD(x,y,z) cerr<<'('<<#x<<','<<#y<<','<<#z<<") are:\t"<<x<<' '<<y<<' '<<z<<'\n';

/////////////////// VARIABLES & FUNCTIONS//////////////////////////
vv<vv<int>> adj; vv<int> vis, color; 
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1},dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
inline ll mexp(ll x,ll n,ll m=MOD){ll res=1;x%=m;while(n){if(n&1)res=(res*x)%m;n>>=1;x=(x*x)%m;}return res;}
inline ll gcd(ll a, ll b){if(a<0) a=-a; if(b<0) b=-b; while (a>0 && b>0){if(a>b)a%=b;else b%=a;}return a+b;}

///////////////////// MAIN STARTS //////////////////////////////////
int32_t main(void){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cout<<fixed;cerr<<fixed; cout<<setprecision(10); cerr<<setprecision(3);

int n; cin>>n;
string s; cin>>s;
vv<vv<int>> pos(10);
for(int i=0;i<n;++i){
	pos[s[i]-'0'].pb(i);
}
int ans=0;
for(int i=0;i<10;++i){
	if(pos[i].empty())
		continue;
	for(int j=0;j<10;++j){
		int p1 = pos[i][0];
		auto p2 = upper_bound(all(pos[j]), p1);
		if(p2 == pos[j].end())
			continue;
		for(int k=0;k<10;++k){
			auto p3 = upper_bound(all(pos[k]), *p2);
			if(p3 == pos[k].end())
				continue;
			ans++;
		}
	}
}
cout<<ans<<el;

return 0;
}


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    string s; cin >> s;

    string t = "";

    for (int i = s.size()-1; i >= 0; --i) {
        t += s[i];

        if (t.size() == 8) {
            puts("NO");
            return 0;
        }

        if (t.size() == 7 && t == "remaerd") {
            t = "";
        }

        if (t.size() == 6 && t == "resare") {
            t = "";
        }

        if (t.size() == 5 && (t == "maerd" || t == "esare")) {
            t = "";
        }
    }

    if (t == "") {
        puts("YES");
    } else {
        puts("NO");
    }
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;

	vector<int> water;
	for (int i = 0; i < f; i += a * 100) {
		for (int j = 0; i + j < f; j += b * 100) {
			water.emplace_back(i + j);
		}
	}

	int w_s_max;
	int w_t;
	int mx = 0;
	int t;
	int ans_s = 0;
	int ans_w = 0;
	for (int i = 0; i < water.size(); i++) {
		w_t = 0;
		w_s_max = water[i] * e / 100;
		for (int j = 0; j <= w_s_max; j += c) {
			for (int k = 0; j + k <= w_s_max; k += d) {
				if (water[i] + j + k <= f) {
					t = 100.0 * (j + k);
					if (t * ans_w >= mx * (water[i] + j + k)) {
						mx = t;
						ans_s = j + k;
						ans_w = ans_s + water[i];
					}
				}
			}
		}
	}
	if (ans_w == 0) {
		printf("%d %d\n", 100 * a, 0);
	}
	else {
		printf("%d %d\n", ans_w, ans_s);
	}

	return 0;
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fr			 first
#define sc			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"
db cal_angle(int h, int m){
	db H,M,angle;
	H = 0.5*(h*60.0+ m);
	M = 6.0*m;
	angle = abs(H-M);
	angle = min(360-angle,angle);
	return angle;
	}
int main()
{
	int a,b,h,m;
	db angle,x;
	cin>>a>>b>>h>>m;
	angle = cal_angle(h,m);
	angle *= (pi)/180;
	//cout<<angle<<nw;
	x = sqrt((sq(a) + sq(b))- 2*a*b*cos(angle));
	pf("%.9lf\n",x);
	return 0;
}

Measured memory_bytes: 4248
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DFriends solver = new DFriends();
        solver.solve(1, in, out);
        out.close();
    }

    static class DFriends {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int N = Integer.parseInt(in.next());
            int M = Integer.parseInt(in.next());

            UnionFind G = new UnionFind(N);

            for (int i = 0; i < M; i++) {
                int a = Integer.parseInt(in.next()) - 1;
                int b = Integer.parseInt(in.next()) - 1;
                G.unite(a, b);
            }

            // 出力
            long ans = 0;
            for (int i = 0; i < N; i++) {
                long tmp = G.getSize(i);
                ans = Math.max(ans, tmp);
            }
            out.println(ans);

        }

        public class UnionFind {
            private int[] parent;
            private int[] rank;
            private int[] elmsize;

            public UnionFind(int size) {
                parent = new int[size];
                rank = new int[size];
                elmsize = new int[size];

                for (int i = 0; i < size; i++) {
                    makeSet(i);
                }
            }

            public void makeSet(int x) {
                parent[x] = x;
                rank[x] = 0;
                elmsize[x] = 1;
            }

            public void unite(int x, int y) {
                final int xRoot = root(x);
                final int yRoot = root(y);

                if (rank[xRoot] > rank[yRoot]) {
                    parent[yRoot] = xRoot;
                    elmsize[xRoot] += elmsize[yRoot];
                } else if (rank[xRoot] < rank[yRoot]) {
                    parent[xRoot] = yRoot;
                    elmsize[yRoot] += elmsize[xRoot];
                } else if (xRoot != yRoot) {
                    parent[yRoot] = xRoot;
                    rank[xRoot]++;
                    elmsize[xRoot] += elmsize[yRoot];
                }
            }

            public int root(int x) {
                if (x != parent[x]) {
                    parent[x] = root(parent[x]);
                }
                return parent[x];
            }

            public long getSize(int x) {
                return elmsize[root(x)];
            }

        }

    }
}



Measured memory_bytes: 62988