akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Linq.Enumerable;
using static System.Math;

class Program
{
    static void Main()
    {
        var (N, M) = ReadLine().Split(' ').Select(long.Parse).ToArray();

        var (S, L) = (Min(N, M), Max(N, M));

        var ans = 0L;

        if (S == 1 && L == 1)
            ans = 1;
        else if (S == 1 && 3 <= L)
            ans = L - 2;
        else if (3 <= S && 3 <= L)
            ans = (S - 2) * (L - 2);

        WriteLine(ans);
    }
}

static class ArrayDeconstructExtensions
{
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2) => (i1, i2) = (a[0], a[1]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3) => (i1, i2, i3) = (a[0], a[1], a[2]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4) => (i1, i2, i3, i4) = (a[0], a[1], a[2], a[3]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4, out T i5) => (i1, i2, i3, i4, i5) = (a[0], a[1], a[2], a[3], a[4]);
}


Measured memory_bytes: 28164
import itertools
import math
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
L = list(map(list,list(itertools.permutations(list(i for i in range(1,N+1)),N))))
a = L.index(P)
b = L.index(Q)
print(abs(a-b))






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

int main(){
    int h, w;
    cin >> h >> w;

    int cnt = 0;
    char x;
    for(int i = 0; i < w*h; i++){
        cin >> x;
        if(x == '#') cnt++;
    }

    if(cnt == h+w-1)    cout << "Possible" << endl;
    else                cout << "Impossible" << endl;
/*
    char mat[h][w];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> mat[i][j];
        }
    }

    int posi = 0, posj = 0;
    bool proceed = true;
    while(proceed && (posi != h-1 || posj != w-1)){
        proceed = false;

        while(posj < w-1 && mat[posi][posj+1] == '#'){
            proceed = true;
            mat[posi][posj] = '.';
            posj++;
        }

        while(posi < h-1 && mat[posi+1][posj] == '#'){
            proceed = true;
            mat[posi][posj] = '.';
            posi++;
        }

    }

    if(posi != h-1 || posj != w-1){
        cout << "Impossible" << endl;
    }else{
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if(i+j == 0 || i+j == h+w-2)    continue;
                if(mat[i][j] == '#'){
                    cout << "Impossible" << endl;
                    return 0;
                }
            }
        }

        cout << "Possible" << endl;
    }
*/
    return 0;
}

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

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

int main()
{
	int n;
	cin >> n;
	vector<int> h(n + 1, 0);
	rep(i, n)  cin >> h[i + 1];

	vector<int> dp(n + 1, 0);
	dp[1] = 0;
	dp[2] = abs(h[2] - h[1]);
	for (int i = 1; i < n - 1; i++) {
		dp[i + 2] = min(dp[i] + abs(h[i + 2] - h[i]), dp[i + 1] + abs(h[i + 2] - h[i + 1]));
	}
	cout << dp[n] << endl;
}

Measured memory_bytes: 1024
n,x = map(int,input().split())
a = list(input().split())
ans = 0

if int(a[0]) > x:
    ans += int(a[0])-x
    a[0] = x
for i in range(n-1):
    c = int(a[i+1]) + int(a[i])
    if c > x:
        ans += c-x
        a[i+1] = int(a[i+1])-(c-x)
print(ans)

Measured memory_bytes: 13744
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){
    vector<int> v(5,0);
    rep(i,5){cin>>v[i];}

    rep(i,5){
        if(v[i]==0)cout<<i+1<<endl;

    }
return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
using ll = long long;

int main() {
	int A, B;
	cin >> A >> B;
	for (int i = 1;i < 20000;i++) {
		if (i * 2 / 25 == A && i / 10 == B) {
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}

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


int main()
{
	int i;
	long long int N;
	int keta = 0;
	long long int tasikame = 0;
	long long int ketaketa = 1;
	int kotae = 0;

	scanf("%lld", &N);
	long long int m = N;
	while (m != 0) {
			m /= 10;
			keta++;
			tasikame += 9 * ketaketa;
			ketaketa *= 10;
	}
	ketaketa /= 10;

	while (tasikame > N) {
		tasikame -= 1 * ketaketa;
	}
	while (tasikame != 0) {
		kotae += tasikame % 10;
		tasikame /= 10;
	}

	printf("%u", kotae);
	return 0;
}
/*受け取るｎ１６けたもある時は、long long int で宣言して、%lluで受け取る。*/

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 5050,inf=0x3f3f3f3f;
int n,f[N][N],res;
struct node{
	int p,h;
}a[N];
bool cmp(node a, node b){
//	return a.p+a.h<b.p+b.h;
	return min(a.h,b.h-a.p)>min(b.h,a.h-b.p);
}
int main() {
	read(n);rep(i,1,n)read(a[i].h),read(a[i].p);
	sort(a+1,a+n+1,cmp);
	rep(i,0,n)rep(j,0,n)f[i][j]=inf;f[0][0]=0;
	rep(i,0,n-1)rep(j,0,i)if(f[i][j]<inf){
		umin(f[i+1][j],f[i][j]);
		if(f[i][j]<=a[i+1].h)umin(f[i+1][j+1],f[i][j]+a[i+1].p),umax(res,j+1);
	}
	cout<<res;
	return 0;
}


Measured memory_bytes: 98944
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9+ 7;
const int INF = numeric_limits<int>::max() - 1e8;
const ll INFLL = numeric_limits<ll>::max() - 1e17;

signed main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    map<char, int> dif;
    dif['R'] = 0;
    dif['G'] = 1;
    dif['B'] = 2;
    vector<vector<int>> count(3);
    for (int i = 0; i < N; i++) count[dif[S[i]]].push_back(i);
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            if (S[i] == S[j]) continue;
            int dist = j - i;
            vector<bool> check(3, false);
            check[dif[S[i]]] = true;
            check[dif[S[j]]] = true;
            for (int a = 0; a < 3; a++) {
                if (check[a]) continue;
                auto itr = upper_bound(count[a].begin(), count[a].end(), j);
                ans += count[a].size() - distance(count[a].begin(), itr);
                if (j + dist < N && dif[S[j + dist]] == a) ans--;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3644
// Problem: https://codeforces.com/contest/1285/problem/E
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
// using namespace __gnu_pbds;
 
#define ford(i, a, b, c)        for(int i=(a); i<(b); i+=(c))
#define fori(i, a, b)           ford(i,a,b,1)
#define rep(i, n)               fori(i,0,n)
#define ifor(i, a, b)           for(int i=(a); i>=(b); i--)
#define si(x)                   ((int)x.size())
#define SS                      ({int x;scanf("%d",&x);x;})
#define pb                      push_back
#define mp                      make_pair
#define all(a)                  a.begin(),a.end()
#define inf                     (int)1e9
#define linf                    (long long)1e18
#define V                       vector
#define S                       string
#define XX                      first
#define YY                      second
#define P(x)                    cout<<x<<"\n"
#define PVI(v)                  rep(i, si(v)) cout<<v[i]<<" "; puts("")
#define PPI(p)                  cout<<"("<<p.first<<", "<<p.second<<")\n"
#define PVPI(v)                 rep(i, si(v)) cout<<"("<<v[i].first<<", "<<v[i].second<<")"<<(i==si(v)-1?"":", ");puts("")
#define PA(arr1, arr2)          for(auto it = arr1; it != arr2; it++) cout<<*it<<" "; puts("");
typedef V<int> vi;
typedef V<S> vs;
typedef long long ll;
typedef pair<int,int> pii;
const int MOD7 = 1000000000+7;
const int MOD9 = 1000000000+9;
/* ################### Program Body starts here ################ */

int main() {
    char c;
    cin>>c;
    cout<<char(c+1)<<"\n";
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<map>
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<time.h>
#include<limits.h>
#include<unordered_map>
#include<set>
#include<queue>
#include<stack>
#include <iomanip>
using namespace std;
#define inf LLONG_MAX
const int N = 1e5 + 1;
#define int long long

vector<int> d(N, 0);
void solve() {
    int n; cin >> n;
    for (int i = 1; i<=100; i++) {
        for (int j = 1;j<=100;j++) {
            for (int c = 1; c<=100;c++) {
                int a = i*i+j*j+c*c +i*j+i*c+j*c;
                d[a]++;
            }
        }
    }
    for (int i = 1; i <= n; i ++) {
        cout << d[i] << endl;
    }


}

int32_t main() {
        solve();
}


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

using namespace std;

pair<int, int> solve(vector<int> &vl, int a, int state) {
  // 消費したmp, 使用後の状態
  pair<int, int> ans{-1, -1};
  for (int i = 1; i < (1 << vl.size()); ++i) {
    if (state & i) {
      continue;
    }

    int sum = 0, cnt = 0;
    for (int j = 0; j < vl.size(); ++j) {
      if (i & (1 << j)) {
        sum += vl[j];
        cnt++;
      }
    }

    int mp = abs(sum - a) + (cnt - 1) * 10;
    if (ans.first < 0 || mp < ans.first) {
      ans.first = mp;
      ans.second = state | i;
    }
  }

  return ans;
}

int main(int argc, const char *argv[]) {
  int n;
  cin >> n;
  vector<int> abc(3);
  for (int i = 0; i < abc.size(); ++i) {
    cin >> abc[i];
  }

  sort(abc.begin(), abc.end());

  vector<int> vl(n);
  for (int i = 0; i < n; ++i) {
    cin >> vl[i];
  }

  int ans = -1;
  do {
    int mp = 0, state = 0;
    bool ok = true;
    for (auto a : abc) {
      auto res = solve(vl, a, state);
      if (res.first < 0) {
        ok = false;
        break;
      }

      mp += res.first;
      state = res.second;
    }

    if (ok && (ans < 0 || mp < ans)) {
      ans = mp;
    }

  } while (next_permutation(abc.begin(), abc.end()));

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long int ll;

int N;

int M[200005];

int main(){
    cin>>N;
    for(int i=0;i<N-1;++i){
        int a;
        cin>>a;
        a--;
        M[a]++;
    }
    for(int i=0;i<N;++i)cout<<M[i]<<endl;
}


Measured memory_bytes: 4368
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define YESNO(i) puts((i)?"YES":"NO");
#define YesNo(i) puts((i)?"Yes":"No");
#define yesno(i) puts((i)?"yes":"no");
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;cin>>s;
  bool isok=true;
  ll num=0;
  if(s[0]!='A') isok=false;
  if(!islower(s[1])) isok=false;
  for(ll i=2;i<s.length()-1;i++) {
    if(s[i]=='C') num++;
    else {
      if(!islower(s[i])) isok=false;
    }
  }
  if(!islower(s[s.length()-1])) isok=false;
  if(isok) isok=(num==1);
  print(isok?"AC":"WA");
  return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
// DONT USE MEMSET, USE VECTORS

void solve(){
	string s;
	cin>>s;
	if(s[2] == s[3] && s[4]==s[5]){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}

int main(){
	fastread;
	int t = 1;
	// cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


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

using namespace std;

int main(int argc, char const *argv[]) {
	unsigned long long x,y;
	std::cin >> x >> y;
	int count = 0;
	while (x <= y) {
		count++;
		x *= 2;
	}
	std::cout << count << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    ll ans = 0;
    for(ll x = 1; x <= n; x+=2){
        ll nd = 0;
        for(ll y = 1; y <= x; ++y){
            nd += (x % y == 0);
        }
        if(nd == 8){ ans++; }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 888
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
//#define int long long
using namespace __gnu_pbds;
using namespace std;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

signed main()
{
	ios::sync_with_stdio(false);
	int x,y;
	cin>>x>>y;
	if(y%2==0&&y>=x*2&&y<=x*4) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;	
	return 0;
}

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

typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define endl "\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

ll const inf = 1e18;
ll const maxn = 1e6+5;
ll const mod = 998244353;

// code begins here

#define MAX 50

void printString(ll n) 
{ 
    char str[MAX]; // To store result (Excel column name) 
    ll i = 0; // To store current index in str which is result 
  
    while (n > 0) { 
        // Find remainder 
        ll rem = n % 26; 
  
        // If remainder is 0, then a 'Z' must be there in output 
        if (rem == 0) { 
            str[i++] = 'z'; 
            n = (n / 26) - 1; 
        } 
        else // If remainder is non-zero 
        { 
            str[i++] = (rem - 1) + 'a'; 
            n = n / 26; 
        } 
    } 
    str[i] = '\0'; 
  
    // Reverse the string and print result 
    reverse(str, str + strlen(str)); 
    cout << str << endl; 
  
    return; 
} 
int main(){
    fast;
    
    ll n;
    cin>>n;

        
    printString(n);

    
    return 0;
}

Measured memory_bytes: 3636
// RAM RAM

#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define ppb pop_back
#define vi vector<int>
#define mp make_pair
#define arrayin(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define N 55

using namespace std;

int num[N];
int dp[N][N][N*N];
int solve(int i,int d,int sum,int n){

	if(sum==0 && d==0){
		return 1;
	}

	if(i>=n || d==0){
		return 0;
	}

	if(dp[i][d][sum]!=-1){
		return dp[i][d][sum];
	}
	int pos1=solve(i+1,d-1,sum-num[i],n);
	int pos2=solve(i+1,d,sum,n);

	dp[i][d][sum]=pos2+pos1;
	return pos1+pos2;
}
int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);
	
    for(int i=0;i<N;i++){
    	for(int j=0;j<N;j++){
    		for(int k=0;k<N*N;k++){
    			dp[i][j][k]=-1;
    		}
    	}
    }
	int n,a;cin>>n>>a;
	arrayin(num,n)
	//cout<<solve(0,1,5,n);	
	int res=0;

	for(int i=1;i<=n;i++){
		int temp=solve(0,i,i*a,n);
		//cout<<temp<<endl;
		res+=(temp);
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 71808
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,m,k,x,y,ans;
int f[N],cnt[N],size[N];

int find(int x)
{
	if (f[x]==x) return x;
	return f[x]=find(f[x]);
}

int main(){
	scanf("%d%d%d",&n,&m,&k);
	for (register int i=1; i<=n; ++i) f[i]=i;
	for (register int i=1; i<=m; ++i) 
	{
		scanf("%d%d",&x,&y);
		cnt[x]++; cnt[y]++;
		int xx=find(x),yy=find(y);
		if (xx!=yy) f[xx]=yy;
	}
	for (register int i=1; i<=k; ++i)
	{
		scanf("%d%d",&x,&y);
		int xx=find(x),yy=find(y);
		if (xx==yy) cnt[x]++,cnt[y]++;
	}
	for (register int i=1; i<=n; ++i) size[find(i)]++;
	for (register int i=1; i<=n; ++i)
	{
		ans=size[find(i)]-cnt[i]-1;
		printf("%d ",ans);
	}
return 0;
}

Measured memory_bytes: 2304
<?php
//error_reporting(0);
$N = trim(fgets(STDIN));
//list($H,$W) = explode(" ",trim(fgets(STDIN)));
//$a = array_map('intval',explode(" ",trim(fgets(STDIN))));

dfs("",0);

function dfs($s,$mx)
{
  $bs="abcdefghijklmnopq";
  global $N;
  if (strlen($s)==$N)
    printf("%s\n",$s);
  else {
    for($i=0;$i<=$mx;$i++) {
      dfs($s.$bs[$i],(($i==$mx)?$mx+1:$mx));
    }
  }
}


Measured memory_bytes: 5880
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
//#define pb push_back
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define td(v) v.begin(),v.end()
#define rep(i,a,n) for (int i=(a);i<(n);i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define re(v) {for(auto &_re : v) cin >> _re;}
#define pr(v) {for(auto _pr : v) cout << _pr << " "; cout << endl;}
#define prr(v) {for(auto _prr : v) cout << _prr.ff << " " << _prr.ss << endl;}
using namespace std;
const ll M = 1e9 + 7;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n,m,k;
    cin >> n >> m >> k;
    vector<ll> a(n), b(m);
    re(a); re(b);
    vector<ll> pa(n+1), pb(m+1);
    for(int i=1;i<=n;i++) pa[i] = pa[i-1] + a[i-1];
    for(int i=1;i<=m;i++) pb[i] = pb[i-1] + b[i-1];
   	ll ans = 0;
    for(int i=0;i<=n;i++){
    	if(pa[i] > k) break;
    	int p = upper_bound(td(pb), k - pa[i]) - pb.begin();
    	ans = max(ans, (ll)i + p - 1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 9556
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#include <string.h>
#include <map>
#define Z class
#define ln cout<<'\n'
#define ll long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
//ASCII a=97, A=65
// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
// sort(vec.begin(), vec.end()); std::greater<>()
// reverse(vec.begin(), vec.end());
// scanf("%s",s);
// printf("%d\n",end-start+1);
using namespace std;
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;}
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;

int main(){
    int a; cin >> a;
    string s; cin >> s;
    int now=0;
    int max=0;
    rep(i,a){
        if(s[i]=='I') now++;
        if(s[i]=='D') now--;
        if(now>max) max=now;
    }
    pr(max);
}


Measured memory_bytes: 256
#include <cstdio>
#include <cassert>
#include <algorithm>    
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <bitset>
#define pb push_back
#define mk make_pair
#define int long long
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long double ld;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef tuple<int, int, int> tiii;
typedef vector<int> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const int INF = 1e18;
const int M = 1e9 + 7;
int a, b, c, d;

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

int run(int x){
	return x - (x / c + x / d - x / (c * d / gcd(c, d)));
}



signed main()
{
#ifndef ONLINE_JUDGE
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif
	cin >> a >> b >> c >> d;
	cout << run(b) - run(a - 1) << endl;
	int res = 0;
	for(int i = 1; i <= b; ++i){
		if(i % c == 0 || i % d == 0) continue;
		++res;
	}


    
	return 0;
}

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


int32_t main()
{
  int n;cin>>n;
  vector<int>arr(n);
  for(int i=0;i<n;i++)
    cin>>arr[i];
  
  sort(arr.begin(),arr.end(),greater<int>());
  int ans=0;
  for(int i=1;i<n;i++)
    ans+=arr[i/2];
  
  cout<<ans<<endl;
}

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

void bubble(char ch[],char A[], int n){
  int i,j;
  char t;
  for(i=0;i<n;i++){
    for(j=n-1;i<j;j--){
      if (A[j]<A[j-1]){
        t=A[j];
        A[j]=A[j-1];
        A[j-1]=t;
        t=ch[j];
        ch[j]=ch[j-1];
        ch[j-1]=t;
      }
    }
  }
}

void selection(char ch[],char A[], int n){
  int i,j,mini;
  char t;

  for(i=0;i<n;i++){
    mini=i;
    for(j=i;j<n;j++){
      if (A[j]<A[mini]){
        mini=j;
      }
    }
    t=A[i];
    A[i]=A[mini];
    A[mini]=t;
    t=ch[i];
    ch[i]=ch[mini];
    ch[mini]=t;
  }
}

int main(){

  int n,i;
  char ori_num[36],ori_ch[36],num1[36],ch0[36],num2[36],ch1[36];
  char str[2];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",str);
    ch0[i]=str[0];
    num1[i]=str[1];
    ori_ch[i]=str[0];
    ori_num[i]=str[1];
  }

  bubble(ch0,num1,n);

  for(i=0;i<n-1;i++){
    printf("%c%c ",ch0[i],num1[i]);
  }
  printf("%c%c\n",ch0[n-1],num1[n-1]);

  printf("Stable\n");

  for(i=0;i<n;i++){
    ch1[i]=ori_ch[i];
    num2[i]=ori_num[i];
  }

  selection(ch1,num2,n);
  for(i=0;i<n-1;i++){
    printf("%c%c ",ch1[i],num2[i]);
  }

  printf("%c%c\n",ch1[n-1],num2[n-1]);

  if ((strncmp(num1,num2,n)==0) && (strncmp(ch0,ch1,n)==0)){
    printf("Stable\n");
  }
  else{
    printf("Not stable\n");
  }

  return 0;
}



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

void solve()
{
    string s;
    cin >> s;
    string ans = "";
    rep(i, s.size())
    {
        if (s[i] == '0')
        {
            ans += "0";
        }
        else if (s[i] == '1')
        {
            ans += "1";
        }
        else
        {
            if (!ans.empty())
            {
                int b = ans.size() - 1;
                ans.erase(b);
            }
        }
    }
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}

Measured memory_bytes: 3632
def resolve():
    n, k = map(int, input().split())
    l = [0] * n
    for i in range(k):
        di = int(input())
        a = list(map(int, input().split()))
        for i in a:
            l[i - 1] += 1
    print(l.count(0))


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9176
#include <iostream>
#include <string>
using namespace std;
 
int main() {
	string S, T, U;
	int A, B;
	cin >> S >> T;
	cin >> A >> B;
	cin >> U;
 
	if(U == S) {
		cout << A - 1 << " " << B;
	}
	else {
		cout << A << " " << B - 1;
	}
 
}

Measured memory_bytes: 256
N,M = list(map(int, input().split()))
cities = [0]*N
roads = []

for i in range(M):
    roads.append(list(map(int, input().split())))

for i in range(M):
    city1 = roads[i][0]
    city2 = roads[i][1]
    cities[city1-1] += 1
    cities[city2-1] += 1

for i in range(N):
    print(cities[i])

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



int main() {
	int n,m,count;
	cin >> n >> m;
	vector<bool> yoi(n,true);
    vector<long long> high(n,0);
	for(int i=0;i<n;i++)
	{
		cin >> high.at(i);
	}
	for(int i=0;i<m;i++)
	{
		int a,b;
		cin >> a >> b;
		if(high.at(a-1)>high.at(b-1))
		{
			yoi.at(b-1)=false;
		}
		else if(high.at(a-1)<high.at(b-1))
		{
			yoi.at(a-1)=false;
		}
		else
		{
		   yoi.at(a-1)=false;
           yoi.at(b-1)=false;		   
		}
	}
	for(int i=0;i<n;i++)
	{
		if(yoi.at(i)==true)
		{
			count++;
		}
	}
	cout <<count;
}


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

#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;

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 (a>b) { a=b; return 1; } return 0; }


void solve(long long N, std::vector<long double> x, std::vector<std::string> u){
    long double a=0;
    rep(i,N){
        (u[i]=="JPY")?a+=x[i]:a+=x[i]*380000;
    }
    cout<<a<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
      cout << fixed << setprecision(6) <<  endl;
    long long N;
    scanf("%lld",&N);
    std::vector<long double> x(N);
    std::vector<std::string> u(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%Lf",&x[i]);
        std::cin >> u[i];
    }
    solve(N, std::move(x), std::move(u));
    return 0;
}


Measured memory_bytes: 256
#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;
    cin >> n;
    vector<int>a(n);
    vector<int>b(n);
    rep(i,n)  cin >>a[i];
    rep(i,n)  b[a[i]-1] = i+1;
    
    for(int i = 0; i < n; i++)cout << b[i] <<" " ;

    return 0;
}


Measured memory_bytes: 1536
from heapq import heappop, heappush, heapify

n, k = map(int, input().split())
vlist = list(map(int, input().split()))

ans = 0
for i in range(min(n, k+1)):  #　右から
  for j in range(min(k-i+1, n-i+1)):  # 左から
    if i == 0:
      tmpl = vlist[:j]
    else:
      tmpl = vlist[:j] + vlist[-i:]
    heapify(tmpl)
    for _ in range(min(k - len(tmpl), len(tmpl))):
      _h = heappop(tmpl)
      if _h > 0:
        tmpl.append(_h)
        break
    tmpa = sum(tmpl)
    if tmpa > ans:
      ans = tmpa

print(ans)


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

    int ord (const void*a, const void *b){

        int x = *((int*)a), y = *((int *)b);

        if (x > y)
            return -1;
        if (x < y)
            return 1;
        else
            return 0;
    }

    int main(){

        int n, k, total = 0;
        int t[1500];

        scanf("%d %d", &n, &k);

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

        qsort(t, n, sizeof(t[0]), ord);

        for (int i = 0; i < k; i++) {
            total += t[i];
        }

        printf("%d\n", total );
    return 0;
    }


Measured memory_bytes: 128
using System;

class E
{
	static void Main()
	{
		var a = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
		long h = a[0], w = a[1], k = a[2];

		Func<MInt, MInt, MInt> c = (x, y) => x * (x * x - 1) / 6 * y * y;
		Console.WriteLine(((c(h, w) + c(w, h)) * MInt.MNcr(h * w - 2, k - 2)).V);
	}
}

struct MInt
{
	const int M = 1000000007;
	public long V;
	public MInt(long v) { V = (v %= M) < 0 ? v + M : v; }

	public static implicit operator MInt(long v) => new MInt(v);
	public static MInt operator +(MInt x) => x;
	public static MInt operator -(MInt x) => -x.V;
	public static MInt operator +(MInt x, MInt y) => x.V + y.V;
	public static MInt operator -(MInt x, MInt y) => x.V - y.V;
	public static MInt operator *(MInt x, MInt y) => x.V * y.V;
	public static MInt operator /(MInt x, MInt y) => x * y.Inv();

	public MInt Pow(int i) => MPow(V, i);
	public MInt Inv() => MPow(V, M - 2);

	static long MPow(long b, int i)
	{
		for (var r = 1L; ; b = b * b % M)
		{
			if (i % 2 > 0) r = r * b % M;
			if ((i /= 2) < 1) return r;
		}
	}

	public static long MFactorial(long n) { for (long x = 1, i = 1; ; x = x * ++i % M) if (i >= n) return x; }
	public static long MNpr(long n, long r)
	{
		if (n < r) return 0;
		for (long x = 1, i = n - r; ; x = x * ++i % M) if (i >= n) return x;
	}
	public static MInt MNcr(long n, long r) => n < r ? 0 : n - r < r ? MNcr(n, n - r) : (MInt)MNpr(n, r) / MFactorial(r);
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

using namespace std;
using ll = long long;

int main()
{
    // 整数の入力
    int a,b;
    cin >> a>>b;
    cout << a * b<< endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  ll N, M;
  cin >> N >> M;
  ll sum = 0;
  rep(i,M){
    ll a;
    cin >> a;
    sum += a;
  }

  if(sum <= N){
    cout << N-sum << endl;
  }else{
    cout << -1 << endl;
  }
  
  return 0;
}



Measured memory_bytes: 3636
#line 1 "main.cpp"

#include <bits/stdc++.h>

using ll = int64_t;

constexpr ll mod = 1000000007;
constexpr auto fib = [] {
  std::array<ll, 89> res{};
  res[0] = res[1] = 1;
  for (int i = 2; i < 89; ++i) res[i] = res[i - 1] + res[i - 2];
  return res;
}();

std::pair<ll, ll> calc(const std::string &str) {
  ll a = 1, b = str[0] - '0';
  for (int i = 1; i < str.size(); ++i) {
    a += b * (str[i] - '0');
    std::swap(a, b);
  }
  return { a, b };
}
auto memo = [] { 
  std::array<std::vector<std::pair<ll, ll>>, 88> res{};
  for (int i = 2; i < 88; ++i) {
    std::string ask(i - 1, '1');
    ask[0] = '2';
    res[i].push_back(calc(ask));
    for (int j = 1; j + 1 < i; ++j) {
      ask[j] = '2';
      res[i].push_back(calc(ask));
      ask[j] = '1';
    }
    ask[0] = '3';
    res[i].push_back(calc(ask));
  }
  return res;
}();

int main() {
  int Q; std::cin >> Q;
  while (Q--) {
    ll X, Y; std::cin >> X >> Y;
    if (X > Y) std::swap(X, Y);
    if (X == 1) { std::cout << 1 << ' ' << Y % mod << '\n'; continue; }
    if (Y == 2) { std::cout << "1 4\n"; continue; }
    int pos = 0;
    while (fib[pos + 1] <= X && fib[pos + 2] <= Y) ++pos;
    ll ans = 0;
    for (auto [a, b]: memo[pos]) {
      if (b <= X && a <= Y) (ans += (Y - a) / b) %= mod;
      if (b <= Y && a <= X) (ans += (X - a) / b) %= mod;
    }
    std::cout << pos << ' '<< ans << '\n';
  }
  return 0;
}


Measured memory_bytes: 4420
#N = int(input())
#A = list(map(int, input().split()))
import sys
N = int(input())
D1 = list()
D2 = list()
for i in range (N):
    a , b = input().split()
    D1.append(a)
    D2.append(b)
s = 0
for i in range (N):
    if D1[0] == D2[0]:
        s = s + 1
    else:
        s = 0
    if s == 3:
        print("Yes")
        sys.exit()        
    del D1[0]
    del D2[0]
print('No')


Measured memory_bytes: 9188
class uf:

    def __init__(self, n):
        self.table = [-1] * (n + 1)
        self.size = [1] * (n + 1)

    def merge(self, r1, r2):
        self.table[r1] = r2
        self.size[r2] += self.size[r1]
        self.size[r1] = 0

    def find_root(self, k):
        path = []
        curr = k
        while self.table[curr] != -1:
            path.append(curr)
            curr = self.table[curr]
        return curr, path

    def defrag(self, r, p):
        for i in p:
            self.table[i] = r

    def in_same_group(self, k1, k2):
        r1, p1 = self.find_root(k1)
        r2, p2 = self.find_root(k2)
        if r1 == r2:
            self.defrag(r1, p1 + p2)
        else:
            self.defrag(r1, p1)
            self.defrag(r2, p2)
        return r1 == r2


def solve(string):
    n, m, *ab = map(int, string.split())
    ab = ab[::-1]
    ans = [n * (n - 1) // 2]
    table = uf(n)
    for _b, _a in zip(ab[:2 * m - 2:2], ab[1:2 * m - 2:2]):
        if table.in_same_group(_b, _a):
            ans.append(ans[-1])
        else:
            r_a, p_a = table.find_root(_a)
            r_b, p_b = table.find_root(_b)
            ans.append(ans[-1] - table.size[r_a] * table.size[r_b])
            table.merge(r_a, r_b)
            table.defrag(r_b, p_a)
            table.defrag(r_b, p_b)
    return "\n".join([str(a) for a in ans[::-1]])


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(m)])))


Measured memory_bytes: 26672
#include <iostream>
#include <string> 
#include <algorithm>
#include <numeric>
#include <cmath>
using namespace std;

int main() {

	long res;
	string N; cin >> N;
	long mylen = N.length();
	res = accumulate(N.begin(), N.end(), 0);
	res -= mylen * 48;
	if (res == 1) res = 10;

	cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll N;
    cin >> N;
    VL d(N);
    rep(i, 0, N){
        ll a;
        cin >> a;
        a--;
        d[i] = a;
    }
    VB seen(N, false);
    ll ans = 0;
    rep(i, 0, N){
        if(d[d[i]] == i){
            if(!seen[i]){
                ans++;
                seen[d[i]] = true;
            } 
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

// longlong??§??£?¨?????????¨??????INT_MAX???????????´
template<typename V> class segtree {
private:
    int n,sz;
    vector<V> node;
public:
    segtree(vector<V> v){
        sz = (int)v.size();
        n = 1;
        while(n < sz){
            n *= 2;
        }
        node.resize(2*n-1);
        rep(i,sz){
            node[i+n-1] = v[i];
        }
        for(int i=n-2; i>=0; i--){
            node[i] = min(node[i*2+1],node[i*2+2]);
        }
    }
    void update(int k,int a)
    {
    	k += n-1;
    	node[k] = a;
    	while(k>0){
    		k = (k-1)/2;
    		node[k] = min(node[2*k+1],node[2*k+2]);
    	}
    }
    V query(int a,int b,int k=0,int l=0,int r=-1)
    {
        if(r < 0) r = n;
    	if(r <= a || b <= l){
    		return INT_MAX;
    	}
    	if(a <= l && r <= b){
    		return node[k];
    	}else{
    		V vl = query(a,b,2*k+1,l,(l+r)/2);
    		V vr = query(a,b,2*k+2,(l+r)/2,r);
    		return min(vl,vr);
    	}
    }
    void print()
    {
        rep(i,sz){
            cout << query(i,i+1) << " ";
        }
        cout << endl;
    }
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,q;
    cin >> n >> q;
    segtree<int> st(vector<int>(n,INT_MAX));
    rep(i,q){
        int a,b,c;
        cin >> a >> b >> c;
        if(a == 0){
            st.update(b,c);
        }else{
            cout << st.query(b,c+1) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4144
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		int[] N = new int[n.length()+1];
		int x=0;
		for(int i=0;i<n.length();i++) {
			x=x+Integer.parseInt(n.substring(i, i+1));
		}
		if(Integer.parseInt(n)%x == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}

}

Measured memory_bytes: 21844
class Dice
  attr_reader :labels

  def initialize(args)
    @labels = args
  end

  def top
    @labels[0]
  end

  def move(a,b,c,d)
    arr = [@labels[a], @labels[b], @labels[c], @labels[d]]
    t = arr.shift
    arr << t
    @labels[a], @labels[b], @labels[c], @labels[d] = arr
  end

  def move_n
    move(0,1,5,4)
  end

  def move_e
    move(0,3,5,2)
  end

  def move_s
    move(4,5,1,0)
  end

  def move_w
    move(2,5,3,0)
  end

  def move_to_input(ch)
    case ch
    when 'E'
      move_e
    when 'N'
      move_n
    when 'S'
      move_s
    when 'W'
      move_w
    end
  end
end

input = gets.split.map(&:to_i)
dice1 = Dice.new(input)
input = gets.split.map(&:to_i)
dice2 = Dice.new(input)

f = 'No'

10000.times do
  dice2.move_to_input('ENSW'.chars.sample)
  if dice1.labels == dice2.labels
    f = 'Yes'
    break
  end
end

puts f

Measured memory_bytes: 6136
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	double a,b,x;
	cin>>a>>b>>x;
	if(x<=a*a*b/2){
		float f=atan(a*b*b/(2*x))*(180.0/acos(-1));
		printf("%0.6f\n",f);
	}
	else{
		float f=atan(2*(a*a*b-x)/(a*a*a))*(180/acos(-1));
		printf("%0.7f\n",f);
	}
	return 0;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

def main():
    K = int(readline())
    A, B = map(int, readline().rstrip().split())
    for i in range(A, B+1):
        if i % K == 0:
            print('OK')
            exit()
    
    print('NG')


if __name__ == '__main__':
    main()

Measured memory_bytes: 9172
#include <iostream>
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
    int n;
    cin>>n;
    int a[n];
    map<int,int> mp;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        mp[a[i]]++;
    }
    ll sum=0;
    for(auto itr:mp)
    {
        if(itr.first<itr.second)
        sum+=itr.second-itr.first;
        else if(itr.first>itr.second)
        sum+=itr.second;
        
    }
    cout<<sum;

}


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

namespace ABC122_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var NQ = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var N = NQ[0];
            var Q = NQ[1];
            var S = Console.ReadLine();

            var ac = new int[N];
            for (int i = 0; i < S.Length - 1; i++)
            {
                if (S[i] == 'A' && S[i + 1] == 'C')
                {
                    ac[i]++;
                }
            }
            var cnt = new int[N];
            cnt[N - 1] = 0;
            for (int i = N - 2; i >= 0; i--)
            {
                cnt[i] = cnt[i + 1] + ac[i];
            }

            var ans = new int[Q];
            for (int i = 0; i < Q; i++)
            {
                var lr = Console.ReadLine().Split().Select(int.Parse).ToArray();
                var l = lr[0];
                var r = lr[1];

                ans[i] = cnt[l - 1] - cnt[r - 1];
            }

            for (int i = 0; i < Q; i++)
            {
                Console.WriteLine(ans[i]);
            }
        }
    }
}


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

#define debug(x) cout << #x << ": " << (x) << endl

long long cost(int n, int a[], bool flag) {
  long long sum = 0;
  long long res = 0;

  for (int i = 0; i < n; ++i) {
    sum += a[i];
    if (flag and sum <= 0) {
      res += 1 - sum;
      sum = 1;
    } else if (not flag and sum >= 0) {
      res += 1 + sum;
      sum = -1;
    }
    flag = not flag;
  }

  return res;
}

int main(int argc, char *argv[]) {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }

  cout << min(cost(n, a, 0), cost(n, a, 1)) << endl;

  return 0;
}


Measured memory_bytes: 640
import sys
import re
 
 
 
def check(Sda, T, Slen, Tlen):
    matarr=[]
    endarr=[]
 
    getS = 'UNRESTORABLE'
 
    if(Slen<Tlen):
        return getS
 
    for i in reversed(range(0, Slen-Tlen+1)):
 
 
        mat = re.match(Sda[i:i+Tlen],T)
        try:
            if(mat.group() == T):
                matarr.append(Sda[:i]+T+Sda[i+Tlen:])
 
        except AttributeError:
            pass
 
        mat = 'None'
 
    if(matarr != []):
        for x in matarr:
            x = x.replace('.', 'a')
            endarr.append(x)
 
        getS = min(endarr)
 
    return getS
 
 
 
def main():
    Sda = input()
    T = input()
    Slen = len(Sda)
    Tlen = len(T)
 
    Sda = Sda.replace('?', '.')
 
    print(check(Sda, T, Slen, Tlen))
 
 
main()

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

int H, W;
char c[60][60];
int dist[60][60];

int main() {
    cin >> H >> W;

    int cnt = 0;
    for (int h = 1; h <= H; ++h)
        for (int w = 1; w <= W; ++w) {
            cin >> c[h][w];
            if (c[h][w] == '.')
                ++cnt;
        }

    memset(dist, -1, sizeof(dist));
    dist[1][1] = 1;
    queue<pair<int, int>> Q;
    Q.push(make_pair(1, 1));

    int dh[] = {0, 0, 1, -1};
    int dw[] = {1, -1, 0, 0};

    while (!Q.empty()) {
        int h = Q.front().first, w = Q.front().second;
        Q.pop();

        for (int i = 0; i < 4; ++i) {
            int nh = h + dh[i], nw = w + dw[i];
            //if (c[nh][nw] == '#') continue;
            //if (dist[nh][nw] != -1) continue;
            if (c[nh][nw] == '.' && dist[nh][nw] == -1) {
                dist[nh][nw] = dist[h][w] + 1;
                Q.push(make_pair(nh, nw));
            }
        }
    }

    if (dist[H][W] != -1)
        cout << cnt - dist[H][W] << endl;
    else
        cout << -1 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define f(c,d)for(c=d%2;c<d;c+=2)
p[2<<19],a,b,m,i,j,o;
x(i,j){if(a)p[i]=60,p[i+1]=62,a--;}
y(i,j){if(b)p[i]=94,p[i+m]=118,b--;}
main(n){
	scanf("%d%d%d%d",&n,&m,&a,&b);
	if(n&1)f(j,m)x(j);
	if(m&1)f(i,n)y(i*m);
	if(n>2&m>2&n&m&a&a>0&b>0)a++,x(0),x(2*m+1),y(2);
	f(i,n)f(j,m)if(p[(o=i*m+j)+1]);else if(a)x(o),x(o+m);else y(o),y(o+1);
	//puts(a|b?"NO":"YES");if(1-a-b)for(i=0;i<n*m;++i%m||puts(""))putchar(p[i]?:46);
	if(a|b)puts("NO");
	else{
		puts("YES");
		for(i=0;i<n;puts(""),i++)
			for(j=0;j<m;)putchar(p[i*m+j++]?:46);
	}
}

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

int main(){
     int i, j, k;
     int n;
     cin >> n >> j;
     vector< int > vt;
     for(i=0; i<n; ++i){
          cin >> k;
          vt.push_back(k);
     }
     sort(vt.begin(), vt.end());
     ll tot=0;
     for(i=0; i<j; ++i) tot+=vt[i];
     cout << tot << endl;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define LL long int
#define ULL unsigned long int
#define MOD (long int)10e9 + 7


int main(){
    int n;
    cin >> n;
    LL ans = 0;

    for(int i = 1; i <= n; ++i){
        if(i % 3 != 0 && i % 5 != 0) ans += i;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3684
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long int ll;

vector<int> E[100005];

int solve(int cur){
    int res=0,pl=0;
    vector<int> tmp;
    for(auto nxt :E[cur]){
        tmp.push_back(solve(nxt));
    }
    sort(tmp.begin(),tmp.end());
    for(int i=tmp.size()-1;i>=0;i--){
        res=max(res,tmp[i]+(++pl));
    }
    return res;
}

int main(){
    int n; cin >> n;
    vector<int> a(n+1);
    for(int i=2;i<=n;i++){
        cin >> a[i];
        E[a[i]].push_back(i);
    }
    cout << solve(1) << endl;
}

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

#define rep_(v, f, l) for (int v = (f); v < (l); ++v)
#define rep(v, n) rep_(v, 0, n)
#define lep(v, n) rep_(v, 1, n + 1)

using namespace std;

typedef long long int lint;
typedef pair<int, int> pii;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }

int main()
{
    int p, q;
    while (~scanf("%d %d", &p, &q)){
        map<int, int> mod;
        int index;
        p *= 10;
        for (index = 1; p != 0 && !mod[p]; index++){
            mod[p] = index;
            printf("%d", p / q);
            p %= q;
            p *= 10;
        }
        puts("");
        if (p){
            rep_(j, 1, index) printf("%c", "^ "[j < mod[p]]);
            puts("");
        }
    }

	return (0);
}

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

int main(void) {
  string s;
  int k;
  cin >> s >> k;
  int n = s.size();

  int tmp = 0;
  rep(i, n) {
    tmp = 'z' - s[i] + 1;
    if (s[i] != 'a' && tmp <= k) {
      s[i] = 'a';
      k -= tmp;
    }
    if (k < 0) break;
    if (i == n - 1) {
      tmp = 'z' - s[i] + 1;
      while (k >= tmp) {
        k -= 26;
      }
      s[n-1] += k;
    }
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 512