akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	string s;cin >> s;
	vector<bool> a(n);
	vector<pair<bool,bool>> b = {{true, true}, {true, false}, {false, true}, {false, false}};
	bool ok = false;
	rep(i,4){
		bool ok1 = true;
		a.at(0) = b.at(i).first;
		a.at(1) = b.at(i).second;
		for(int j = 1; j < n - 1; j++){
			if(s.at(j) == 'o'){
				if(a.at(j)) a.at(j + 1) = a.at(j - 1);
				else a.at(j + 1) = (a.at(j - 1) ^ 1);
			}
			else{
				if(!a.at(j)) a.at(j + 1) = a.at(j - 1);
				else a.at(j + 1) = (a.at(j - 1) ^ 1);
			}
		}
		rep(j,n){
			if(s.at(j) == 'o'){
				if(a.at(j)){
					if(a.at((j - 1 + n) % n) != a.at((j + 1) % n)) ok1 = false;
				}
				else{
					if(a.at((j - 1 + n) % n) == a.at((j + 1) % n)) ok1 = false;
				}
			}
			else{
				if(a.at(j)){
					if(a.at((j - 1 + n) % n) == a.at((j + 1) % n)) ok1 = false;
				}
				else{
					if(a.at((j - 1 + n) % n) != a.at((j + 1) % n)) ok1 = false;
				}
			}
		}
		if(ok1){
			ok = true;
			break;
		}
	}
	if(ok){
		rep(i,n){
			if(a.at(i)) cout << 'S';
			else cout << 'W';
		}
		cout << endl;
	}
	else cout << -1 << endl;
}

Measured memory_bytes: 592
/*       _________
        /|______/ \
        ||  _|_|\  |
        || |_|   | /
        ||    _ / |
        ||  _| \\  \    
        ||_|_|\ || |
        |/_|/ | /|_/
              /__/      Written by: Rishabh Roshan
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int            	long long
#define integer        	int32_t
#define mod         	1000000007
#define vint        	vector<int>
#define pint        	pair<int, int>
#define umint        	unordered_map<int, int>
#define mint        	map<integer, integer>
#define in(x)        	int x; cin>>x
#define setbits(x)    	__builtin_popcountll(x)
#define zerobits(x)    	__builtin_ctzll(x)
#define w(x)        	int x; cin>>x; while(x--)
#define sp(x, y)    	fixed<<setprecision(y)<<x
#define poll(x)        	x.front(); x.pop()
#define f(x)        	for(int i=0; i<x; i++)
#define fj(x)			for(int j=0; j<x; j++)
#define fn(n, x)			for(int i=n; i<x; i++)
#define endl         	'\n'
#define inf         	1e9 
#define order_set     	tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

// #include "functions.h"

void om_shree_ganeshaya_namah(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

void print(vector<vint> arr){
	f(arr.size()){
		fj(arr[i].size()) cout<<arr[i][j]<<" ";
		cout<<endl;
	}
	cout<<endl;
}

int32_t main() {

    om_shree_ganeshaya_namah();

    in(n);
    vint arr(n);
    f(n) cin>>arr[i];

    vector<vint> dp(n, vint(n));

    for(int l=n-1; l>=0; l--){
    	for(int r=l; r<n; r++){
    		if(l==r)
    			dp[l][r] = arr[l];
    		else
    			dp[l][r] = max(arr[l]-dp[l+1][r], arr[r]-dp[l][r-1]);
    	}
    }

    // print(dp);

    cout<<dp[0][n-1];

}

Measured memory_bytes: 73672
def main():
    s = list(input())
    cnt = 0
    for i in range(len(s)):
        if i % 2 == 0 and s[i] in ['R', 'U', 'D']:
            cnt += 1
        elif i % 2 == 1 and s[i] in ['L', 'U', 'D']:
            cnt += 1
    if cnt == len(s):
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

Measured memory_bytes: 9040
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n; cin >> n;
    string X; cin >> X;

    int popbase = 0;
    REP(i,n) if (X[i] == '1') popbase++;
    //int ap = 0, am = 0; // f(X)
    int mp = 0, mm = 0; // あまり
    int popp = popbase+1, popm = popbase-1;
    REP(i,2) {
        int p = (i == 0) ? popp:popm; 
        if (p == 0) continue;
        ll a = 0;
        int j = 0;
        while(j < X.size()) {
            a = (a << 1) + (X[j] == '1'? 1:0);
            j++;
            a %= p;
        }
        if (i == 0) {
            mp = a;
        } else {
            mm = a;
        }
    }

    // int tx = bitset<32>(X).to_ulong();
     cerr << popp << " " << popm << endl;
     cerr << mp << " " << mm << endl;
    // cerr << tx << endl;

    auto calc = [](int x,int m){
        // cerr << x << " " << m << endl;
        int ret = 0;
        while (x > 0) {
            x %= m;
            bitset<32> bs(x);
            m = bs.count();
            ret++;
        }
        return ret;
    };

    reverse(ALL(X));
    int powp = 1,powm = 1;
    vector<int> ans(n);
    REP(i,n) {
        int a=0;
        if (X[i] == '0') {
            a = (mp + powp);
            if (a == 0) ans[i] = 1;
            else ans[i] = calc(a,popp);
            // cerr << "p:" << a << " " <<ans[i] << " " << powp << endl;
        } else {
            if (popm == 0) continue;
            
            a = (mm - powm);
            if (a < 0) a += popm;
            
            if (a == 0) ans[i] = 1;
            else ans[i] = calc(a,popm);
            // cerr << "m:" << a << " " <<ans[i] << " " << powm << endl;
        }
        powp = powp * 2 % popp;
        if (popm != 0) powm = powm * 2 % popm;
        // cerr << powm << " " << (int)(pow(2,i+1)) % popm << endl;
    }

    reverse(ALL(ans));
    REP(i,n) cout << ans[i] << '\n';


    return 0;
}

Measured memory_bytes: 4456
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()



int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> a(n+1, 0);
  rep(i, m) {
    int b;
    cin >> b;
    a[b] = 1;
  }
  int cnt1 = 0, cnt2 = 0;
  for (int i = x+1; i <= n; i++) {
    cnt1 += a[i];
  }
  for (int i = x-1; i >= 0; i--) {
    cnt2 += a[i];
  }
  cout << min(cnt1, cnt2) << endl;
  return 0;
}

Measured memory_bytes: 256
def solve(N, V, C):
    val = 0
    for i in range(N):
        if V[i] - C[i] > 0:
            val += V[i] - C[i]
    return val

N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))


print(solve(N, V, C))

Measured memory_bytes: 3060
N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7


duplicate_x = None
checked = set()
for a in A:
    if a in checked:
        duplicate_x = a
    checked.add(a)


x_l_index = A.index(duplicate_x)
x_r_index = N + 1 - A[::-1].index(duplicate_x) - 1


# 逆元の前計算
factorial = [1, 1]
inverse = [1, 1]
invere_base = [0, 1]
for i in range(2, N + 2):
    factorial.append((factorial[-1] * i) % MOD)
    invere_base.append((-invere_base[MOD % i] * (MOD // i)) % MOD)
    inverse.append((inverse[-1] * invere_base[-1]) % MOD)


def nCr(n, r):
    if not 0 <= r <= n:
        return 0
    return factorial[n] * inverse[r] * inverse[n - r] % MOD


for k in range(1, N + 1 + 1):
    print((nCr(N + 1, k) - nCr(max(0, x_l_index) + max(N + 1 - x_r_index - 1, 0), k - 1)) % MOD)


Measured memory_bytes: 31324
n=int(input())
w=[]

for i in range(n):
            w.append(input())

for j in range(n-1):
            if w[j][-1]!=w[j+1][0]:
                        print('No')
                        exit()
if len(w)!=len(set(w)):
            print('No')
            exit()
            
else:
            print('Yes')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
#define SELECTOR(_1, _2, _3, SELECT, ...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__, _rep1, _rep0)(__VA_ARGS__)
#define _rep0(i, n) for (ll i = 0; i < n; ++i)
#define _rep1(i, k, n) for (ll i = k; i < n; ++i)

void solve() {
  // input
  ll n,m; cin>>n>>m;
  vector<vector<int>> E(n);
  rep(_,m) {
    ll a,b; cin>>a>>b;
    --a; --b; // 0-indexed
    E.at(a).push_back(b);
  }

  function<vector<ll>(ll)> bfs=[&](ll sv){
    vector<ll> prev(n,-1); // also as visited
    ll last=-1;
    queue<ll> q;
    q.push(sv);
    while(!q.empty()) {
      ll v=q.front(); q.pop();
      for(ll nv:E.at(v)) {
        if(nv==sv) { // loop detected
          last=v;
          break;
        } else if(prev.at(nv)==-1) { // unvisited
          prev.at(nv)=v;
          q.push(nv);
        }
      }
    }
    // return loop
    if(last!=-1) {
      vector<ll> loop;
      while(last!=-1) {
        loop.push_back(last);
        last=prev.at(last);
      }
      reverse(loop.begin(),loop.end());
      return loop;
    }
    else return vector<ll>(n+1);
  };
  // shortest loop
  vector<ll> ans(n+1);
  rep(v,n) {
    vector<ll> now=bfs(v);
    if(now.size()<ans.size()) ans=now;
  }
  // output
  if(ans.size()==n+1) cout<<-1<<"\n";
  else {
    cout<<ans.size()<<"\n";
    for(ll v:ans) cout<<v+1<<"\n"; // 1-indexed
  }

}

int main() {
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  solve();
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define		int 			long long int
#define		pb				push_back
#define		fi(n)			for(int i=0;i<n;i++)
#define		fi1(n)			for(int i=1;i<n;i++)
#define		fj(n)			for(int j=0;j<n;j++)
#define		clr(x)			memset(x, 0, sizeof(x))
#define 	print(x)		for(auto a:x) cout<<a<<" ";cout<<"\n"
#define		nl 				"\n"
#define		vi				vector<int>
#define		si 				set<int>
#define		mp 				make_pair
#define		pairi			pair<int,int>
#define		vpairi			vector<pair<int,int>>
#define		ff				first
#define		ss				second
#define		inf 			1e9+10
#define 	input 			"C://Users//Piyush Aggarwal//Documents//Cpp files//input-output//input.txt"
#define 	output 			"C://Users//Piyush Aggarwal//Documents//Cpp files//input-output//output.txt"
#define 	error 			"C://Users//Piyush Aggarwal//Documents//Cpp files//input-output//error.txt"

int ctoi(char a){ int x=a-48 -49;return x;}
string itos(int a){
	string out_string;
	stringstream ss;
	ss<<a;
	out_string=ss.str();
	return out_string;
}
char itoc(int a){ return itos(a)[0];}
int pow(int e,int x){
	int ans=1;
	while(x>0){
		if(x&1) ans*=e;
		e*=e;
		x>>=1;
	}return ans;
}
string bin(int x){
	bitset<sizeof(1)*CHAR_BIT> bits(x);
	string b=bits.to_string(); return b;
}

vi a(200005);
vi parent(200005);

int find(int x){
	if(parent[x]==-1) return x;
	else return parent[x]=find(parent[x]);
}

void union1(int x,int y){
	int a1=find(x);
	int b=find(y);
	if(a1!=b){
		parent[a1]=b;
		a[b]+= a[a1];
	}
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen(input, "r", stdin);
	freopen(output, "w", stdout);
	freopen(error, "w", stderr);
	#endif
	int T=1;
	// cin>>T;
	while(T--){
		int n,k,m,x,y,z;
		cin>>n>>m;
		// vi a(n);
		// fi(n) cin>>a[i];
		// vi a(n);
		// vi parent(n);
		fi(n){
			parent[i]=-1;
			a[i]=1;
		}
		fi(m){
			cin>>x>>y;
			union1(x-1,y-1);
			// print(a);
		}
		int ans=-1;
		fi(n){
			ans=max(ans,a[i]);
		}
		cout<<ans<<nl;

	}
	return 0;
}


Measured memory_bytes: 6172
#ifdef __GNUC__
#pragma GCC target("avx2")
#pragma GCC optimize ("O30")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC optimize("unroll-loops")
#define iss std::cin
#endif
#include "bits/stdc++.h"
#define rep(i, times) for(ll i = 0; i < (times); ++i)
#define p(x) (cout << (x) << "\n")
using ll = long long; using ld = long double; using namespace std;

ll N, cnt;
void all( ) {
	vector<vector<ll>> A;
	iss >> N; A.resize(3, vector<ll>(N));
	for (auto &abc : A) {
		for (auto &a : abc)  iss >> a;
	}		
	sort(begin(A[0]), end(A[0]));
	sort(begin(A[2]), end(A[2]));
	for (auto &b : A[1]) {
		cnt += (end(A[2]) - upper_bound(begin(A[2]), end(A[2]), b))
			* (lower_bound(begin(A[0]), end(A[0]), b) - begin(A[0]));
	}
	p(cnt);
}
int main( ) {
	cin.tie(0);	ios::sync_with_stdio(0);
	all( );
}

Measured memory_bytes: 6296
#include <stdio.h>


int main (void){
    int n,h,w;
    scanf("%d%d%d",&n,&h,&w);
    int count = 0;
    for(int i = 0; i < n;i++){
        int a,b;
        scanf("%d%d",&a,&b);
        if(a >= h && b >= w){
            count++;
        }
    }

    printf("%d",count);

    return 0;
}


Measured memory_bytes: 128
n,m = map(int, input().split())
ans = [10 for i in range(n)]
flag = 0
for i in range(m):
    s,c = map(int, input().split())
    if s==1 and c==0 and n!=1:
        flag = -1
    if ans[s-1]!=10 and ans[s-1]!=c:
        flag = -1
    ans[s-1] = c
#print(ans)
if ans[0]==10 and n!=1:
    ans[0]=1
    if n==2 or n==3:
        if ans[1]==10:
            ans[1]=0
            if n==3:
                if ans[2]==10:
                    ans[2]=0
for i in range(n):
    if ans[i]==10:
        ans[i]=0
map_ans = map(str, ans)
answer =''.join(map_ans)

print(-1 if flag==-1 else answer)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String word = scan.next();
        char[] data = word.toCharArray();
        int result = 0;
        for(int i = 0; i < data.length; i++) {
            if (data[i] == 'a') {
                result |= 1;
            }
            if (data[i] == 'b') {
                result |= 2;
            }
            if (data[i] == 'c') {
                result |= 4;
            }
        }
        System.out.println(result == 7 ? "Yes" : "No");
    }
}

Measured memory_bytes: 22356
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
int main(){
    ll n,W,ans;
    cin >> n >> W;
    vector<ll> w(n),v(n),vsum(n);
    ll dp[n][100001];//i番目,v以上の時の重さの最小値
    //こうすることで,重さの最小値<=Wで 条件を満たす取り方の存在が言えて、
   //その上で価値の添え字の最大値を見ればよい   
    for(ll i=0;i < n;i++)
    {
        cin >> w.at(i) >> v.at(i);
    }//input

    for(int i=0;i < n;i++)
    {
        for(int j=0;j < 100001;j++)
        {
            dp[i][j]=pow(10,13);
        }
    }//initialized
    
    dp[0][0]=0;
    for(int j=1;j <= v.at(0);j++)
    {
        dp[0][j]=w.at(0);
    }

    for(ll i=1;i < n;i++)
    {
        for(ll j=0;j < 100001;j++)
        {   
            if(j-v.at(i)>=0){
                //価値ｊ以上→ひとつ前にすでにそうor加えて価値が増える
                dp[i][j]=min(dp[i-1][j],dp[i-1][j-v.at(i)]+w.at(i));
            }
            else{//加えても足りない→ないのでINF
                dp[i][j]=dp[i-1][j];
            }
        }
    }

    for(ll j=100000;0<=j;j--)
    {
        if(dp[n-1][j]<=W){
            ans = j;
            break;
        }
    }
    cout << ans << endl;
}
//重さを添え字にすると終わらないので価値を添え字にする
//価値の添え字が最も大きいもので、重さが上限を満たすものを取る
//dpの添え字をピッタリにすると更新しづらいので以上（以下）で取った方がよさそう


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

int H, W, dist[59][59], sum; string S[59];

int main() {
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		cin >> S[i];
		for (int j = 0; j < W; j++) { if (S[i][j] == '.') sum++; }
	}
	for (int i = 0; i < 59; i++) { for (int j = 0; j < 59; j++) dist[i][j] = (1 << 30); }
	queue<pair<int, int>>Q; Q.push(make_pair(0, 0)); dist[0][0] = 1;
	while (!Q.empty()) {
		int a1 = Q.front().first, a2 = Q.front().second; Q.pop();
		int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
		for (int i = 0; i < 4; i++) {
			int cx = a1 + dx[i], cy = a2 + dy[i];
			if (cx < 0 || cy < 0 || cx >= H || cy >= W || dist[cx][cy] <= dist[a1][a2] + 1 || S[cx][cy] == '#') continue;
			Q.push(make_pair(cx, cy));
			dist[cx][cy] = dist[a1][a2] + 1;
		}
	}
	if (dist[H - 1][W - 1] == (1 << 30)) cout << "-1" << endl;
	else cout << sum - dist[H - 1][W - 1] << endl;
	return 0;
}

Measured memory_bytes: 764
#include<iostream>
#include<string>

using namespace std;

int main(void){
    long D,N,result;
    int omake=0;
    cin>>D>>N;

    switch(D){
        case 0:
            result=1;
            break;
        case 1:
            result=100;    
            break;
        case 2:
            result=10000;
            break;
    }

    if(D==0&&N==100)omake=1;
    if(D==1&&N==100)omake=100;
    if(D==2&&N==100)omake=10000;

    cout<<result*N+omake<<endl;
    return 0;
}

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

int n, x;

int loop(int cnt, int sum, int plus) {
	if (cnt == 3) {
		if (sum == x) {
			return 1;
		} else {
			return 0;
		}
	}

	if (plus > n) {
		return 0;
	}

	return loop(cnt + 1, sum + plus, plus + 1) + loop(cnt, sum, plus + 1);
}

int main()
{
	while (cin >> n >> x && (n != 0 || x != 0)){
		cout << loop(0, 0, 1) << endl;
	}
}

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

using namespace std;

string a, b;

int main() {
  cin >> b >> a;
  sort(a.begin(), a.end(), greater <char> ());
  sort(b.begin(), b.end());
  for (int i = 0; i < b.size(); ++i) {
    if (i >= a.size()) {
      return !printf("No");
    } else if (b[i] > a[i]) {
      return !printf("No\n");
    } else if (b[i] < a[i]){
      return !printf("Yes\n");
    }
  }
  if (a.size() == b.size()) {
    puts("No");
  } else {
    puts("Yes");
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0);
#define endl '\n'
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
int n, m;
bool ok(int i, int j) {
    return i >= 0 && i < n && j >= 0 && j < m;
}
int main() {
#ifdef LOCAL
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    string s, t;
    cin >> s >> t;
    sort(all(s));
    sort(rall(t));
    if (s < t)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


move = None
tx = None
ty = None


@mt
def slv(S, x, y):
    tx = x
    ty = y
    move = list(map(lambda x: len(x), S.split('T')))
    xm = [move[0]]
    for i in range(2, len(move), 2):
        xm_ = []
        for x in xm:
            xm_.append(x + move[i])
            xm_.append(x - move[i])
        xm = set(xm_)

    ym = [0]
    for i in range(1, len(move), 2):
        ym_ = []
        for y in ym:
            ym_.append(y + move[i])
            ym_.append(y - move[i])
        ym = set(ym_)

    return 'Yes' if tx in xm and ty in ym else 'No'


def main():
    S = read_str().strip()
    x, y = read_int_n()
    print(slv(S, x, y))


if __name__ == '__main__':
    main()


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

using namespace std;

#define INF 2000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;


int main()
{
	int n;
	string s;
	cin >> n >> s;
	string tmp = s;
	int l = 0; // (
	int r = 0; // )
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '(') {
			l++;
		} else {
			l--;
		}
		if (l < 0) {
			l++;
			tmp = '(' + tmp;
		}
	}
	string ans = tmp;

	for (int i = tmp.size()-1; i >= 0; i--) {
		if (tmp[i] == ')') {
			r++;
		} else {
			r--;
		}
		if (r < 0) {
			r++;
			ans = ans + ')';
		}
	}
	cout << ans << endl;
}


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

int main() {
  int n; 
  cin >> n;
  ll ans = 1; 
  constexpr ll div = pow(10, 9) + 7;
  for (int i = 1; i <= n; ++i) {
    ans *= i;
    ans %= div; 
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] arr = new int[n];
		
		for(int i=0; i<n; i++) {
			arr[i] = scan.nextInt();
		}
		System.out.println(maxprof(arr));
	}
	
	public static int maxprof(int[] arr) {
		int maxDiff = arr[1] - arr[0];
		int maxValueSeen = arr[arr.length - 1];
		
		for (int i = arr.length - 2; i >= 0; i--) {
			if (arr[i] > maxValueSeen) {
				maxValueSeen = arr[i];
				continue;
			} else {
				maxDiff = Math.max(maxDiff, maxValueSeen - arr[i]);
			}
		}
		
		return maxDiff;
	}
}



Measured memory_bytes: 100476
n = gets.to_i

arr = gets.split.map(&:to_i)

count = 0

n.times do |i|
  min_pos = i

  i.upto(n - 1) do |j|
    if arr[j] < arr[min_pos]
      min_pos = j
    end
  end

  if min_pos != i
    arr[i], arr[min_pos] = arr[min_pos], arr[i]
    count += 1
  end
end

puts arr.join(' ')
puts count

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

int main(){
    int h,n;
    cin >> h >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i++) cin >> a[i];
    int sum = 0;
    for(int i = 0;i < n;i++){
        sum += a[i];
    }
    if(sum >= h) cout << "Yes" << endl;
    else cout <<"No" <<endl;
    return 0;
}    


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 60;
constexpr auto mod = 1000000007;
constexpr auto MOD = 998244353;
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() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n, x;
    cin >> n >> x;
    VI m(n);
    FOR(i, 0, n) {
        cin >> m[i];
        x -= m[i];
    }

    SORT(m);
    cout << n + x / m[0] << "\n";
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a, b, i;
	cin >> a >> b;
	string s;
	int j, k, count = 0;
	bool ok;
	for(i=a; i<=b; i++){
		s = to_string(i);
		j = 0;
		k = s.length()-1;
		ok = true;
		while(j<k){
			if(s[j]!=s[k]){
				ok = false;
				break;
			}
			j++;
			k--;
		}
		count = (ok) ? count+1 : count;
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;

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

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

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

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

int main()
{
	string s;
	cin>>s;
	int n = s.length();
	vector<int> l(n),r(n);
	int cnt = 0;
	vector<int> ans(n);
	for (int i = 0; i < n; i++){
		if(s[i]=='R') cnt++;
		else{
			l[i] = cnt;
			ans[i] += cnt/2;
			ans[i-1] += cnt/2 + cnt%2;
			cnt = 0;
		}
	}
	cnt = 0;
	for (int i = n-1; i >= 0; i--){
		if(s[i]=='L') cnt++;
		else{
			r[i] = cnt;
			ans[i] += cnt/2;
			ans[i+1] += cnt/2 + cnt%2;
			cnt = 0;
		}
	}

	for(auto x : ans) cout<<x<<" ";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <cstdio>

using namespace std;

int main() {
    while (true) {
        int a, b;
        char op;
        scanf("%d %c %d", &a, &op, &b);

        switch (op) {
            case '+':
                printf("%d\n", a+b);
                break;
            case '-':
                printf("%d\n", a-b);
                break;
            case '*':
                printf("%d\n", a*b);
                break;
            case '/':
                printf("%d\n", a/b);
                break;
            case '?':
                return 0;
        }
    }
}

Measured memory_bytes: 2708
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
long long pw[5000005],fact[5000005],inv[5000005];
long long pow_log(long long x,int y)
{
	if (!y)
	return 1;
	long long ret=pow_log(x,y/2);
	ret=(ret*ret)%mod;
	if (y%2)
	ret=(ret*x)%mod;
	return ret;
}
int ncr(int n,int r)
{
	return ((fact[n]*inv[r])%mod*inv[n-r])%mod;
}
int main()
{
	int n;
	scanf("%d",&n);
	n/=2;
	fact[0]=1;
	pw[0]=1;
	for (int i=1;i<=n;i++)
	{
		fact[i]=(i*fact[i-1])%mod;
		pw[i]=(2*pw[i-1])%mod;
	}
	inv[n]=pow_log(fact[n],mod-2);
	for (int i=n-1;i>=0;i--)
	inv[i]=((i+1)*inv[i+1])%mod;
	int ans=0,sum=pw[n];
	for (int a=0;a<=n;a++)
	{
		long long tmp=(ncr(n,a)*pw[n-a])%mod;
		ans=(ans+2*tmp*sum-tmp*tmp%mod+mod)%mod;
		if (a!=n)
		{
			sum=(sum+ncr(n,a+1)*pw[n-a-1])%mod;
			sum=(sum-ncr(n,a)*pw[a]%mod+mod)%mod;
		}
	}
	printf("%d",ans);
}

Measured memory_bytes: 120888
#include "iostream"
#include "vector"
#define int long long
using namespace std;

signed main() {
    int n;
    cin >> n;
    vector <int> a(n);
    for (auto &i: a) {
        cin >> i;
    }
    sort(a.begin(), a.end(), greater<int>());
    int ans = a[0], ct = 2; // largest two
    float it = 1;
    while (ct != n) {
        ans += a[(int)it];
        it += 0.5;
        ct++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4496
using System;
using System.Linq;

class D
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		var h = Read();
		var n = h[0];
		var pq = new int[h[1]].Select(_ => Read()).ToArray();
		var rs = new int[h[2]].Select(_ => Read()).ToArray();

		var uf1 = new UF(n);
		var uf2 = new UF(n);
		foreach (var x in pq) uf1.Unite(x[0], x[1]);
		foreach (var x in rs) uf2.Unite(x[0], x[1]);

		var q = Enumerable.Range(1, n).Select(i => (i, g: (uf1.GetRoot(i), uf2.GetRoot(i)))).GroupBy(x => x.g).Select(g => g.ToArray()).SelectMany(g => g.Select(x => (x.i, c: g.Length))).OrderBy(x => x.i).Select(x => x.c);
		Console.WriteLine(string.Join(" ", q));
	}
}

class UF
{
	int[] p;
	public UF(int n) { p = Enumerable.Range(0, n + 1).ToArray(); }

	public void Unite(int a, int b) { if (!AreUnited(a, b)) p[p[b]] = p[a]; }
	public bool AreUnited(int a, int b) => GetRoot(a) == GetRoot(b);
	public int GetRoot(int a) => p[a] == a ? a : p[a] = GetRoot(p[a]);
	public int[][] ToGroups() => Enumerable.Range(0, p.Length).GroupBy(GetRoot).Select(g => g.ToArray()).ToArray();
}


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

int main(){
  string s;
  cin >> s;
  bool check[26]={false};
  for(int i=0;i<s.length();i++){
    check[s[i]-'a']=true;
  }
  for(int i=0;i<26;i++){
    if(!check[i]){
      char ans='a'+i;
      cout<< ans <<endl;
      return 0;
    }
  }
  
  cout<<"None"<<endl;
  
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(),(a).end()
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(ll i = 0;i < (n);i++)
#define rep2(i,n) for(ll i = 0;i < (n);i++)
#define rep3(i,a,b) for(ll i = (a);i < (b);i++)
#define rep4(i,a,b,c) for(ll i = (a);i < (b);i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i = (n)-1;i >= 0;i--)
#define rrep2(i,n) for(ll i = (n)-1;i >= 0;i--)
#define rrep3(i,a,b) for(ll i = (a)-1;i >= (b);i--)
#define rrep4(i,a,b,c) for(ll i = (a)-1;i >= (b);i -= (c))
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;

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

    int n,high = -1;
    cin>>n;
    vector<int>a(n);
    rep(i,n)cin>>a[i];
    ll ans = 0;
    rep(i,n){
        high = max(a[i],high);
        ans += abs(high - a[i]);
    }
    cout<<ans<<endl;

}



Measured memory_bytes: 3936
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringReader;
import java.util.StringTokenizer;

public class Main  implements Runnable {
	int[][] ta = new int[16][4096];
	int ptr = 0;
    public static void main(String[] args) {
        new Thread(null, new Main(), "", 64 * 1024 * 1024).start();
    }

    public void run() {
    	FastScanner sc = new FastScanner(System.in);
    	//int[] ar = new int[3];
    	//ar[0]=Integer.parseInt(sc.next());
    	//Arrays.parallelSort(ar);
		int n = Integer.parseInt(sc.next());
		//long a = Long.parseLong(sc.next());
		//String s = sc.next();
		//String str = sc.next();
		//char c[] = str.toCharArray();
		//char a[][] = new char[n];
		//ArrayList<Str_4> lists = new ArrayList<Str_4>();
		//lists = new ArrayList;
		PrintWriter out = new PrintWriter(System.out);
		//int[] ra = new int[r];
		//ArrayList<ArrayList<Integer>> lists = new ArrayList<>();
		int ans = 0;
		int[] a = new int[n];
		int prea = 0;
		for(int i = 0; i < n; i++)
		{
			a[i] = Integer.parseInt(sc.next());
			if(a[i] > prea)
			{
				a[i]--;
			}
			else
			{
				if(a[i] < prea)
				{
					ans++;
				}
			}
			prea = a[i];
		}
		
		if(ans == 0)
		{
			out.println("Yes");
		}
		else
		{
			out.println("No");
		}
		//out.println(a[5]);
		out.flush();
    }

    static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;
        public FastScanner(String in) {
        	StringReader sr = new StringReader(in);
            reader = new BufferedReader(new BufferedReader(sr));
            tokenizer = null;
        }
        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        public String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public long nextInt() {
            return Integer.parseInt(next());
        }

    }
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    ll a,b,q;cin >>a>>b>>q;
    vector<ll>s(a);
    vector<ll>t(b);
    for (int i = 0; i < a; ++i) {
        cin >>s[i];
    }
    for (int i = 0; i < b; ++i) {
        cin >>t[i];
    }
    for (int i = 0; i < q; ++i) {
        ll x;cin >>x;
        ll sf,sb,tf,tb;
        ll key=lower_bound(all(s),x)-s.begin();
        if(s[key]==x){
            sf=x;sb=x;
        }
        else {
            sb=(s[key]<x)?INFll/3:s[key];
            sf=(key==0)?-INFll/3:s[key-1];
        }
        key=lower_bound(all(t),x)-t.begin();
        if(t[key]==x){
            tf=x;tb=x;
        }
        else {
            tb=(t[key]<x)?INFll/3:t[key];
            tf=(key==0)?-INFll/3:t[key-1];
        }
        sb-=x;
        tb-=x;
        sf=x-sf;
        tf=x-tf;
//        cout <<sf<<" "<<sb<<endl;
//        cout <<tf<<" "<<tb<<endl;
        ll ans;
        ans=max(sb,tb);
        ans=min(ans,max(sf,tf));
        ans=min(ans,2*sf+tb);
        ans=min(ans,sf+2*tb);
        ans=min(ans,2*sb+tf);
        ans=min(ans,sb+2*tf);
        cout <<ans <<endl;
    }
    return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int w,h;
char c[22][22];
int dist[444][444];
int a[22];
int dd[]={-1,0,1,0,-1};

int main(){
	cin.sync_with_stdio(false);
  while(1){
    cin>>w>>h;
    if(w==0)break;
    rep(i,h)cin>>c[i];
    rep(i,h*w)rep(j,h*w)dist[i][j]=i==j?0:INF;
    rep(i,h)rep(j,w){
      if(c[i][j]=='x')continue;
      rep(d,4){
        int ni=i+dd[d],nj=j+dd[d+1];
        if(ni>=0&&ni<h&&nj>=0&&nj<w&&c[ni][nj]!='x'){
          dist[i*w+j][ni*w+nj]=dist[i*w+j][ni*w+nj]=1;
        }
      }
    }
    rep(k,h*w)rep(i,h*w)rep(j,h*w)minch(dist[i][j],dist[i][k]+dist[k][j]);
    //rep(i,h*w)rep(j,h*w)dbg(dist[i][j]);
    map<int,int> v;
    int vmax=1;
    rep(i,h)rep(j,w){
      if(c[i][j]=='o'){
        v[0]=i*w+j;
      }else if(c[i][j]=='*'){
        v[vmax++]=i*w+j;
      }
    }
    rep(i,vmax)a[i]=i;
    ll res=INF;
    do{
      if(a[0]!=0)continue;
      ll sum=0;
      rep(i,vmax-1){
        sum+=dist[v[a[i]]][v[a[i+1]]];
      }
      minch(res,sum);
    }while(next_permutation(a,a+vmax));
    if(res==INF)cout<<-1<<endl;
    else cout<<res<<endl;
  }
	return 0;
}

Measured memory_bytes: 3780
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[1007][1007];
const ll mod = 1000000007;
char mp[1007][1007];

int main(){
    int n, m;
    scanf("%d %d", &n, &m);
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            scanf(" %c", &mp[i][j]);
        }
    }
    dp[0][1] = 1;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(mp[i][j] == '#')dp[i][j] = 0;
            else{
                dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
                dp[i][j] %= mod;
            }
        }
    }
    cout << dp[n][m] << endl;
}

Measured memory_bytes: 12488
#include <bits/stdc++.h>
using namespace std;
int main(){
set<char>s;
string S;
cin>>S;
for(int i=0;i<S.size();i++){
    s.insert(S[i]);
}
if(S.size()==s.size())cout<<"yes";
else cout<<"no";
return 0;
}


Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second

int main(){
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    vector<int> x(N);
    for(int i = 0; i < N; i++) cin >> x[i];
    vector<int> y(M);
    for(int i = 0; i < M; i++) cin >> y[i];
    sort(all(x));
    sort(all(y));
    bool flag = false;
    for(int z = x[x.size()-1] + 1; z <= y[0]; z++){
        if(X < z and z <= Y){
            flag = true;
            break;
        }
    }
    if(flag) puts("No War");
    else puts("War");
}


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

int main()
{
  string s,t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  
  if (s < t)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


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

using namespace std;

int main() {
	int a, b;
	char op;

	while (cin >> a >> op >> b) {
		switch (op) {
			case '+':cout << a + b << endl; break;
			case '-':cout << a - b << endl; break;
			case '*':cout << a * b << endl; break;
			case '/':cout << a / b << endl; break;
			default :return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define repd(i, a, b) for (int i = a; i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    vector<int> h(n);
    rep(i, 0, n) cin >> h[i];
    sort(all(h));
    int lb = 0, ub = h[n - 1] / b + 1;
    while (lb != ub)
    {
        ll t = (lb + ub) / 2;
        if (t == lb)
            break;
        ll count = 0;
        rep(i, 0, n)
        {
            if (h[i] > t * b)
                count += (h[i] - t * b) / (a - b) + ((h[i] - t * b) % (a - b) != 0);
        }
        if (count > t)
            lb = t;
        else
            ub = t;
    }
    cout << ub << endl;
}


Measured memory_bytes: 3800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int countDigit(int n)
{
    int cnt=0;
    while(n)
    {
        cnt++;
        n/=10;
    }
    return cnt;
}
int main()
{
    int n;
    cin >> n;
    int sum=0;
    int ans=0;
    for(int i=1; i<=n; i++)
    {
        if(countDigit(i)%2)
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(unused_variables)]

use itertools::Itertools;
use proconio::marker::*;
use proconio::*;
use std::collections::VecDeque;

#[fastout]
fn main() {
    input! {
        n: usize,
        x: Usize1,
        y: Usize1,
    }
    // annotate for rust-analyzer
    let n: usize = n;
    let x: usize = x;
    let y: usize = y;

    let mut dist = vec![vec![-1i32; n]; n];
    for i in 0..n {
        let mut q = VecDeque::new();
        dist[i][i] = 0;
        q.push_back(i);
        while q.len() > 0 {
            let cur = q.pop_front().unwrap();
            let mut nexts = Vec::new();
            if cur > 0 {
                nexts.push(cur - 1);
            }
            if cur < n - 1 {
                nexts.push(cur + 1);
            }
            if cur == x {
                nexts.push(y);
            }
            if cur == y {
                nexts.push(x);
            }
            for next in nexts {
                if dist[i][next] == -1 {
                    dist[i][next] = dist[i][cur] + 1;
                    q.push_back(next);
                }
            }
        }
    }

    let mut anss = vec![0; n];
    for i in 0..n - 1 {
        for j in i + 1..n {
            anss[dist[i][j] as usize] += 1;
        }
    }
    for i in 1..n {
        println!("{}", anss[i]);
    }
}


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

int main()
{
    int n;
    cin >> n;
    long long ans = 0;
    vector<long long> v;
    for(int i=0; i<n; i++){
        long long a,b;
        cin >> a >> b;
        ans -= b;
        v.push_back(a+b);
    }
    sort(v.rbegin(), v.rend());
    
    for(int i=0; i<n; i++){
        if(i%2 == 0) ans += v[i];
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1400
N = int(input())
d = [list(map(int, input().split())) for _ in range(N)]

check = [[1] * N for _ in range(N)]

for i in range(N):
    for j in range(N):
        if i == j:
            continue
        for k in range(N):
            if i == k or j == k:
                pass
            else:                    
                if d[i][j] > d[i][k] + d[k][j]:
                    print (-1)
                    exit()
                elif d[i][j] == d[i][k] + d[k][j]:
                    check[i][j] = 0

ans = 0
for i in range(N):
    for j in range(N):
        ans += d[i][j] * check[i][j]

print (ans // 2)    

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

int main()
{
  int n,m;
  char s[3];
  int i,p;

  /*入力*/
  scanf("%d",&n);
  scanf("%d",&m);

  int ac[100000]  = {0},wa[100000] = {0};

  /*ac[あってた問],wa[間違った問]*/
  for(i = 0;i < m;i++){
    scanf("%d",&p);
    scanf("%s",s);
    if((strcmp(s,"AC") == 0)&&(ac[p - 1] == 0)){ //acで、まだ一回も正解していない
      ac[p - 1] = 1;
    }
    else if((strcmp(s,"WA") == 0)&&(ac[p - 1] == 0)){//waで、まだ一回も正解していない
      wa[p - 1] += 1;
    }
  }

  int AC = 0,WA = 0;
  
  for(i = 0;i < n;i++){
    AC += ac[i];
    if(ac[i] == 1){
    WA += wa[i];
    }
  }

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

  return 0;
}
    


Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include<bits/stdc++.h>
#include <utility>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

const int MAX = 100010;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// NのP乗をMで割った余りを返す
ll pow_mod(ll n,ll k,ll m){
  if(k==0){
    return 1;
  }else if(k%2==1){
    return pow_mod(n,k-1,m)*n%m;
  }else{
    ll t=pow_mod(n,k/2,m);
    return (t*t)%m;
  }
}

//(10*9*8)/(3*2*1);
//10*9*8 -> ansMul
//3*2*1 -> ansDiv
long calcComb(int a, int b) {
	if (b > a - b) return calcComb(a, a - b);


	long ansMul = 1;
	long ansDiv = 1;
	for (int i = 0; i < b; i++)
	{
		ansMul *= (a - i);
		ansDiv *= (i + 1);
		ansMul %= MOD;
		ansDiv %= MOD;
	}
	//ansMul / ansDivをやりたい
	//ansDivの逆元を使って求めよう！

	long ans = ansMul * pow_mod(ansDiv,MOD - 2,MOD);
	return ans;
}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  vector<int> a;
  cin >> n;
  int t;
  for(int i=0;i<n;i++){
    cin >> t;
    a.push_back(t);
  }
  sort(a.rbegin(),a.rend());
  COMinit();
  int ans1=a[0],ans2=a[n];
  int cnt=a[0]/2;
  for(int i=0;i<n;i++){
    if(abs(a[i]-a[0]/2)<cnt){
      ans2=a[i];
      cnt=abs(a[i]-a[0]/2);
    }
  }
  cout << ans1 << ' ' << ans2 << endl;
  return 0;
}

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	map<int,int> appear;
	int n;
	cin >> n;
	int max1 = 0,max2 = 0;
	for(int a = 0;a < n;a++){
		int x;
		cin >> x;
		if (appear.find(x) == appear.end()) appear[x] = 1;
		else{
			appear[x]++;
			if (appear[x] != 2&&appear[x]!=4) continue; 
			if (x > max1){
			max2 = max1;
			max1 = x;
			} 
			else if (x > max2) max2 = x;
		}
	}
	cout << (long long)max1*max2;
}

Measured memory_bytes: 4992
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> 
#include <iomanip>
#include <unordered_map>
#include <memory.h>

using namespace std;

int main(void)
{
	int a, b;
	string s;
	string A, B;

	cin >> a >> b;
	cin >> s;

	A = s.substr(0, a);
	B = s.substr(a + 1);

	bool ok = true;
	for (int i = 0; i < A.size(); i++)
	{
		if (A[i]<'0' || A[i]>'9')
		{
			ok = false;
			break;
		}
	}

	for (int i = 0; i < B.size(); i++)
	{
		if (B[i]<'0' || B[i]>'9')
		{
			ok = false;
			break;
		}
	}

	if (s[a] != '-')
	{
		ok = false;
	}

	if (ok == true)
	{
		cout << "Yes" << '\n';
	}
	else
	{
		cout << "No" << '\n';
	}
	return 0;
}

Measured memory_bytes: 256
def read():
    N = int(input())
    As = list(map(int, input().split(' ')))
    return N, As


def func(N, As):
    ans = 0
    s = As[-1]
    for i in range(N - 1):
        t = As[-1 * (i+2)]
        ans += s * t
        s += t
    return ans % (10 ** 9 + 7)

if __name__ == '__main__':
    N, As = read()
    print(func(N, As))


Measured memory_bytes: 31432
#include<iostream>
using namespace std;
int main()
{
	int date[12][2] = { {1,31},{2,28},{3,31},{4,30},{5,31},{6,30},{7,31},{8,31},{9,30},{10,31},{11,30},{12,31} };

	int  m1, d1, m2, d2;

	cin >> m1>> d1;
	cin >> m2 >> d2;

	for (int i = 0; i < 12; i++) {
		if (m1 == date[i][0]) {
			if (d1 == date[i][1]) {
				int a = 1;
				cout << a << endl;
				break;
			}
			else {
				int f = 0;
				cout << f << endl;
				break;

			}
		}
		
	}
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

int main() {
    int N;
    cin >> N;
    vector<int> graph[10010];
    for(int i = 0;i < N - 1;i++) {
        int A,B;
        cin >> A >> B;
        A--;
        B--;
        graph[A].push_back(B);
        graph[B].push_back(A);
    }
    vector<int> count(N);
    for(int i = 0;i < N;i++) {
        count.at(i) = graph[i].size();
    }
    vector<ll> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i);
    }
    sort(vec.begin(),vec.end());
    vector<ll> ret(N);
    vector<bool> used(N);
    for(int i = 0;i < N;i++) {
        int cnt = 0;
        int cnt2 = Inf;
        for(int j = 0;j < N;j++) {
            if(used.at(j) == false && cnt2 > count.at(j)) {
                cnt = j;
                cnt2 = count.at(j);
            }
        }
        ret.at(cnt) = vec.at(i);
        used.at(cnt) = true;
        for(int j = 0;j < graph[cnt].size();j++) {
            count.at(graph[cnt].at(j))--;
        }
    }
    ll ret2 = 0;
    for(int i = 0;i < N;i++) {
        for(int j = 0;j < graph[i].size();j++) {
            ret2 += min(ret.at(i),ret.at(graph[i].at(j)));
        }
    }
    cout << ret2 / 2 << endl;
    for(int i = 0;i < N;i++) {
        cout << ret.at(i) << " ";
    }
    cout << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size())

int main()
{
    ll i,j,n;
    cin>>n;
    vector<ll> a(n);
    for(i=0;i<n;i++) cin>>a[i];
    ll ans = 0;
    for(i=1;i<n;i++)
    {
        if(a[i]<a[i-1])
        {
            ans+=a[i-1]-a[i];
            a[i] = a[i-1];
        }
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 4836