akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
 
const int INF = 1e9;
 
int n,m,i,j;
vector <pair<int, int> > edge[100005];
vector <int> st[100005],dist[100005],visited[100005];
vector < vector<int> > R[100005];
bool flag[100005];

#define PP pair<int, int> 
 
PP pq[2000005];
int h = 1000000;
int t = 1000000;
 
int main(){
	scanf("%d%d", &n, &m);
	for(i = 0; i < m; i++){
		int x,y,z;
		scanf("%d%d%d", &x, &y, &z);
		edge[x].push_back({y, z});
		edge[y].push_back({x, z});
		st[x].push_back(z);
		st[y].push_back(z);
	}
	st[1].push_back(0);
	
	for(i = 1; i <= n; i++){
		sort(st[i].begin(), st[i].end());
		st[i].resize(unique(st[i].begin(), st[i].end()) - st[i].begin());
		for(j = 0; j < st[i].size(); j++){
			dist[i].push_back(INF);
			visited[i].push_back(0);
			vector <int> v;
			R[i].push_back(v);
		}
		for(j = 0; j < edge[i].size(); j++){
			int ind = lower_bound(st[i].begin(), st[i].end(), edge[i][j].second) - st[i].begin();
			R[i][ind].push_back(edge[i][j].first);
		}
	}
	
	dist[1][0] = 0;
	pq[--h] = {1, 0};
	
	while(h != t){
		PP now = pq[h];
		h++;
		
		int id = now.first;
		int ind1 = now.second;
		int C = dist[id][ind1];
		
		if(id == n)
		return 0 * printf("%d\n", C);
		
		if(visited[id][ind1]) continue;
		visited[id][ind1] = 1;
		
		if(!flag[id]){
			flag[id] = 1;
			for(int ii = 0; ii < edge[id].size(); ii++){	
				int to = edge[id][ii].first;
				int com = edge[id][ii].second;
				int ind = lower_bound(st[to].begin(), st[to].end(), com) - st[to].begin();
				
				if(st[id][ind1] == com){
					if(dist[to][ind] > C){
						dist[to][ind] = C;
						pq[--h] = {to, ind};
					}
				}
				else{
					if(dist[to][ind] > C + 1){	
						dist[to][ind] = C + 1;
						pq[t++] = {to, ind};
					}
				}
			}
		}
		
		for(int ii = 0; ii < R[id][ind1].size(); ii++){
			int to = R[id][ind1][ii];
			int ind = lower_bound(st[to].begin(), st[to].end(), st[id][ind1]) - st[to].begin();
			
			if(dist[to][ind] > C){
				dist[to][ind] = C;
				pq[--h] = {to, ind};
			}
		}
	}
	
	printf("-1\n");
}

Measured memory_bytes: 56576
c = [[int(x) for x in input().split()] for _ in range(3)]
f = True
from itertools import product
for i,j in product(range(1,3), range(1,3)):
        if c[0][0]+c[i][j] != c[i][0]+c[0][j]:
            f = False
            break

print('Yes' if f else 'No')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define rep(i, n) for (int i = 0; i < (int)n; i++)
typedef long long ll;
const ll MOD = 1e9+7;
const int inf = 1000000;
const int minf = -1000000;
const ll lnf = 1e9;
const ll mlnf = -1e9;

void debug_vector(vector<int>& v){
    int n = v.size();
    for (int i = 0; i < n; i++){
        cout << v[i] << " ";
    }
    cout << endl;
}

void solve();
bool check(string s, string S);

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

void solve(){
    int N; cin >> N;
    string S; cin >> S; 

    // 全探索
    int ans = 0;
    string pin;

    // 00i
    for (int i = 0; i < 10; i++){
        pin = "00";
        pin += ('0' + i);
        // cout << pin << endl;
        if (check(pin, S)) ans++;
    }
    // 0ij
    for (int i = 10; i < 100; i++){
        pin = '0';
        pin += to_string(i);
        // cout << pin << endl;
        if (check(pin, S)) ans++;
    }
    
    // ijk
    for (int i = 100; i < 1000; i++){
        pin = to_string(i);
        // cout << pin << endl;
        if (check(pin, S)) ans++;
    }

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

}

bool check(string s, string S){
    int N = S.size();
    int cnt = 0;
    int now = 0;
    vector<bool> flag(3, false);
    while (cnt < N){
        if (s[now] == S[cnt]){
            flag[now] = true;
            now++;
            cnt++;
        }else{
            cnt++;
        }
    }
    return (flag[2]) ?  true : false;

}

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

int main(void){
    string s;
    string g = "Yes";
    int l;
    cin >> s;
    l = s.length();

    for(int i=0; i<l; i++){
        if((i+1) % 2 == 1){
            if(s[i] == 'L'){
                g = "No";
                break;
            }
        }
        else if((i+1) % 2 == 0){
            if(s[i] == 'R'){
                g = "No";
                break;
            }
        }
    }

    cout << g << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mx 1000000000000000000
#define ll long long int
//ll number[20],used[20];
int main()
{
    ll n,i,a,count,sum;
    cin >> n >> a;
    sum = n/a;
    if(n%a==0)
        cout << sum << endl;
    else
    {
            cout << sum+1 << endl;
    }
    return 0;
}


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

int main(){
  string s; cin>>s;
  int size=s.size();
  if(size%2==1){
    size--;
  }
  int ans=0;
  for(int i=0;i<size/2;i++){
    if(s[i]!=s[s.size()-i-1]){
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] c = sc.next().toCharArray();
		int[] occ = new int[26];
		for (int i = 0; i < c.length; i++)
			occ[c[i] - 'a']++;
		for(int i = 0;i < 26;i++)
			if((occ[i] & 1) != 0){
				System.out.println("No");
				return;
			}
		System.out.println("Yes");
	}

}


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

int main()
{
  string s;
  cin >> s;
  i64 n = s.size() + 1;
  vector<i64> a(n, 0);
  for (i64 i = 0; i < n - 1; i++)
    if (s[i] == '<')
      a[i + 1] = max(a[i + 1], a[i] + 1);
  for (i64 i = n - 2; 0 <= i; i--)
    if (s[i] == '>')
      a[i] = max(a[i], a[i + 1] + 1);
  i64 ans = 0;
  for (i64 i = 0; i < n; i++)
    ans += a[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4740
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <cassert>
#include <deque>
#include <map>
#include <queue>
#include <climits>
#include <set>
#include <stack>

using namespace std;

#define ll long long
#define MAX 200000
#define MAX1 10000
#define MAX2 100000
#define inf 1000000000
#define eps 1e-12
#define MOD 1000000007

string s;
int dp[MAX + 5];

int mul(int a, int b, int mod) {
    ll c = 1LL * a * b;
    if (c >= mod) {
        c %= mod;
    }
    return c;
}

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

int sub(int a, int b, int mod) {
    int c = a - b;
    if (c < 0) {
        c += mod;
    }
    return c;
}

int fastExp(int a, int b, int mod) {
    int c = 1;
    while (b) {
        if (b & 1) {
            c = mul(c, a, mod);
        }
        b >>= 1;
        a = mul(a, a, mod);
    }
    return c;
}

int solve(int n) {
    if (n == 0) {
        return 0;
    }
    int &ret = dp[n];
    if (ret != -1) {
        return ret;
    }
    int rem = __builtin_popcount(n);
    return ret = solve(n % rem) + 1;
}

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif

    int n, i, cnt = 0, cool[2], val;
    cin >> n >> s;
    for (i = 0; i < n; ++i) {
        cnt += s[i] == '1';
    }
    cool[0] = cool[1] = 0;
    for (i = 0; i < n; ++i) {
        if (s[i] == '1') {
            cool[0] = add(cool[0], fastExp(2, n - i - 1, cnt + 1), cnt + 1);
            if (cnt > 1) {
                cool[1] = add(cool[1], fastExp(2, n - i - 1, cnt - 1), cnt - 1);
            }
        }
    }
    for (i = 0; i <= cnt + 2; ++i) {
        dp[i] = -1;
    }
    for (i = 0; i < n; ++i) {
        if (s[i] == '0') {
            val = add(cool[0], fastExp(2, n - i - 1, cnt + 1), cnt + 1);
            cout << solve(val) + 1 << "\n";
        } else {
            val = 0;
            if (cnt > 1) {
                val = sub(cool[1], fastExp(2, n - i - 1, cnt - 1), cnt - 1);
            }
            cout << solve(val) + (cnt > 1) << "\n";
        }
    }

    return 0;
}

Measured memory_bytes: 3700
#include <iostream>

using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;
    string ans = string(N, 'x');

    for (int i = 0; i < M; i++)
    {
        int s, c;
        cin >> s >> c;
        s--;
        if (ans[s] == 'x')
        {
            if (s == 0 && c == 0 && ans.size() > 1)
            {
                cout << -1 << endl;
                return 0;
            }
            ans[s] = c + '0';
        }
        else if (ans[s] == c + '0')
        {
            continue;
        }
        else
        {
            cout << -1 << endl;
            return 0;
        }
    }

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

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define PI       3.1415926535897932384626433832795028841971
#define INF      1000000000.0
#define EPS      1e-10
#define MOD      1000000007
using namespace std;
typedef long long ll;
typedef pair<double,double> P;
typedef pair<double,P> PQ;

string s1, s2;
int dp[1001][1001];

int main(){
    cin >> s1 >> s2;
    rep(i,s1.size()+1) rep(j,s2.size()+1) dp[i][j] = MOD;
    dp[0][0] = 0;
    for(int i = 1; i <= s1.size(); i++) dp[i][0] = i;
    for(int j = 1; j <= s2.size(); j++) dp[0][j] = j;
    for(int i = 1; i <= s1.size(); i++){
        for(int j = 1; j <= s2.size(); j++){
            if(s1[i-1] == s2[j-1]) dp[i][j] = min(dp[i][j],dp[i-1][j-1]);
            dp[i][j] = min(dp[i][j],dp[i-1][j-1]+1);
            dp[i][j] = min(dp[i][j],dp[i-1][j]+1);
            dp[i][j] = min(dp[i][j],dp[i][j-1]+1);
        }
    }
    cout << dp[s1.size()][s2.size()] << endl;
}

Measured memory_bytes: 7100
a,op,b=input().split()
a=int(a);b=int(b)
while op!='?':
    if op=='+':
        print(a+b)
    elif op=='-':
        print(a-b)
    elif op=='*':
        print(a*b)
    elif op=='/':
        print(a//b)
    a,op,b=input().split()
    a=int(a);b=int(b)


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

using namespace std;

#define fRead(x)        freopen(x,"r",stdin)
#define fWrite(x)       freopen (x,"w",stdout)

#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define PI              acos(-1.0)
#define mk              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr);
#ifdef VAMP
     #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template < typename Arg1 >
    void __f(const char* name, Arg1&& arg1){
        cout << name << " = " << arg1 << std::endl;
    }
    template < typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names+1, ',');
        cout.write(names, comma - names) << " = " << arg1 <<" | ";
        __f(comma+1, args...);
    }
#else
    #define debug(...)
#endif

const int N = 400005;
const LL MOD = 998244353;
inline LL BigMod(LL B,LL P,LL M){LL R=1;while(P>0){if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;}return R;}

LL fac[N + 5];void FacGen(){fac[0]=1;FOR(i,1,N)fac[i]=(fac[i-1]*i)%MOD;}
LL COM(LL a,LL b){
if(a < b)return 0;
return ((fac[a]*BigMod((fac[b]*fac[a-b])%MOD,MOD-2,MOD))%MOD+MOD)%MOD;}

int n , m , k;
int main()
{
//    #ifdef VAMP
//        clock_t tStart = clock();
//        freopen("input.txt", "r", stdin);
//        freopen("output.txt", "w", stdout);
//    #endif
    FacGen();
    cin >> n >> m >> k;

    LL ans = 0;
    for(int i = 0;i <= k;i++){
        LL first = m;
        LL ways = COM(n - 1,i);
        LL differ = n - 1 - i;
        LL how = BigMod(m - 1,differ,MOD);
        LL temp = (how * ways) % MOD;
        temp = (temp * first) % MOD;
        ans += temp;
        ans %= MOD;
    }
    cout << ans << "\n";
//    #ifdef VAMP
//        fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
//    #endif
}


Measured memory_bytes: 6748
#include<bits/stdc++.h>
using namespace std;
#define ROOP(i,n)   for(int i=0;i<n;i++)
int main(){
    long long N;
    cin >> N;
    
    vector<long long> A(N), B(N);
    for(long long i=0;i<N;i++){
        cin >> A.at(i);
        B.at(i) = A.at(i) - i - 1;
    }
    sort(B.begin(),B.end());
    
  	long long sum=0, m=N/2;

  	for(long long i=0;i<N;i++)
      	sum += (B.at(i)-B.at(m)>0 ? B.at(i)-B.at(m) : B.at(m)-B.at(i));
  	
  	cout << sum << endl;
}



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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const ll MOD=1e9+7;

int main(){
    string s; cin >> s;
    bool ans=true;
    for(int i=0; i<s.size(); i++){
        if(i%2 == 0 && s[i] == 'L') ans=false;
        if(i%2 == 1 && s[i] == 'R') ans=false;
    }
    cout << (ans ? "Yes":"No")  << endl;
    return 0;
}

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

int main()
{
  int N;
  cin >> N;
  vector<int> T(N);
  for (int i = 0; i < N; i++)
  {
    cin >> T.at(i);
  }
  int M;
  cin >> M;
  vector<vector<int>> data(M, vector<int>(2));
  for (int i = 0; i < M; i++)
  {
    for (int j = 0; j < 2; j++)
    {
      cin >> data.at(i).at(j);
    }
  }
  for (int i = 0; i < M; i++)
  {
    long long int sum = accumulate(T.begin(), T.end(), 0);
    sum -= T.at(data.at(i).at(0) - 1);
    sum += data.at(i).at(1);
    cout << sum << endl;
  }
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    Set<Integer> set = new HashSet<>();
    for(int i = 0; i < N; i++){
      int n = Integer.parseInt(sc.nextLine());
      if(set.contains(n)){
        set.remove(n);
      }else{
        set.add(n);
      }
    }
    System.out.println(set.size());
  }
}

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

#define OnlineJudge1

#define loop(a,n) for(int i = a;i<n;i++)
#define NumofDigits(n) ((int)log10(n)+1)
#define CountofNumber(array,n,x)  (upper_bound(array, array+n, x)-lower_bound(array, array+n, x))
#define readline(s) getline(cin,s)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define EPS 1e-7
#define modulo ll (1e9 + 7)


typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
#ifdef OnlineJudge
    freopen("in.in","r",stdin);
    freopen("out.txt","w",stdout);
#endif
}

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

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

//    int powres[] = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912};

ll power(ll b, ll p){
    if(p == 0)return 1;
    ll res = power(b,p/2);
    res *= res;
    if(p & 1)res *= b;
    return res;
}

set<ll> factors;
set<ll> divisors;

void divide(ll n){
    for(ll i = 2;i * i <= n;i++){
        if(n % i == 0){
            divisors.insert(i);
            divisors.insert(n/i);

        }
    }
}

void factorize(ll n){
        for(ll i = 2;i * i <= n;i++){
        if(n % i == 0){
            factors.insert(i);
            while(n % i == 0)n /= i;
        }
    }
    if(n != 1)factors.insert(n);
}

int Max = 1e7 + 5;
int prime[(int)1e7+7];

void sieve(){
    prime[0] = prime[1] = 1;
    for(ll i = 1;i<=Max;i++){
        if(prime[i])
            continue;
        else{
            for(ll j = i*i;j<=Max;j+=i)
                prime[j] = 1;
        }
    }
}

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

    int p = 0, dp[2][3];
    memset(dp, 0, sizeof dp);

    for(int i = 0;i < n;i++){
        int a,b,c;
        cin >> a >> b >> c;
        p ^= 1;

        dp[p][0] = a + max(dp[p^1][1],dp[p^1][2]);
        dp[p][1] = b + max(dp[p^1][0],dp[p^1][2]);
        dp[p][2] = c + max(dp[p^1][0],dp[p^1][1]);

    }

    cout << max(dp[p][0],max(dp[p][1],dp[p][2]));
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std; 
  #define int long long 
// Prints all stepping numbers reachable from num 
// and in range [n, m] 
int k;
vector<int>v;
void bfs(int n, int m, int num) 
{ 
    // Queue will contain all the stepping Numbers 
    queue<int> q; 
  
    q.push(num); 
  
    while (!q.empty()) 
    { 
        // Get the front element and pop from the queue 
        int stepNum = q.front(); 
        q.pop(); 
  
        // If the Stepping Number is in the range 
        // [n, m] then display 
        if (stepNum <= m && stepNum >= n) 
        {
           
            v.push_back(stepNum);
                
        }
  
        // If Stepping Number is 0 or greater than m, 
        // need to explore the neighbors 
        if (num == 0 || stepNum > m) 
            continue; 
  
        // Get the last digit of the currently visited 
        // Stepping Number 
        int lastDigit = stepNum % 10; 
  
        // There can be 2 cases either digit to be 
        // appended is lastDigit + 1 or lastDigit - 1 
        int stepNumA = stepNum * 10 + (lastDigit- 1); 
        int stepNumB = stepNum * 10 + (lastDigit + 1); 
        int stepNumC = stepNum * 10 + (lastDigit); 
  
        // If lastDigit is 0 then only possible digit 
        // after 0 can be 1 for a Stepping Number 
        if (lastDigit == 0) 
            q.push(stepNumB); 
  
        //If lastDigit is 9 then only possible 
        //digit after 9 can be 8 for a Stepping 
        //Number 
        else if (lastDigit == 9) 
            q.push(stepNumA); 
  
        else
        { 
            q.push(stepNumA); 
            q.push(stepNumB); 
        } 
        q.push(stepNumC); 
    } 
} 
  
// Prints all stepping numbers in range [n, m] 
// using BFS. 
void displaySteppingNumbers(int n, int m) 
{ 
    // For every single digit Number 'i' 
    // find all the Stepping Numbers 
    // starting with i 
    for (int i = 0 ; i <= 9 ; i++) 
        bfs(n, m, i); 
} 
  
//Driver program to test above function 
int32_t main() 
{ 
    int n,m;
    cin>>k;
    n=1;
    m=3234566668;
    displaySteppingNumbers(n,m); 
  sort(v.begin(),v.end());
    
    cout<<v[k-1];
    return 0; 
} 

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

#define int long long
typedef pair<int, int> P;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

/*
#define cin ifs
#define cout ofs
ifstream ifs("in.txt");
ofstream ofs("out.txt");
//*/

int N;
int A[220000];
map<int, int> mp;

signed main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 1; i < N; i++) {
        A[i] += A[i - 1];
    }
    int ans = 0;
    mp[0]++;
    for (int i = 0; i < N; i++) {
        ans += mp[A[i]];
        mp[A[i]]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 14336
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        int n = sc.nextInt();
        if(n == 100)
        n++;
        int ans = (int)Math.pow(100,d)*n;

        System.out.println(ans);
            
    }
}

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

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

struct Node *root, *NIL;

void insert(int);
void inorder(struct Node *);
void preorder(struct Node *);

int main(){
  int str1=0,str2=0;
  int a, b, c;
  char A[10],B[10]="insert",C[10]="print";
  scanf("%d", &a);

  for ( b=0;b<a; b++ ){
    scanf("%s", A);
    if (strcmp(A,B) == 0 )
      str1=1;
     if (strcmp(A,C) == 0 )
       str2=1;
     if(str1==1){
       scanf("%d",&c);
       insert(c);
       str1=0;
     }
     else if(str2==1){
       str2=0;
       inorder(root);
       printf("\n");
       preorder(root);
       printf("\n");
     }
  }
  return 0;
}

void insert(int k){
  struct Node *y = NIL;
  struct Node *x = root;
  struct Node *z;

  z =(struct Node*) malloc(sizeof(struct Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else {x = x->right;
  }
  }
  z->parent = y;

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

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

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





Measured memory_bytes: 25128
fun main(args: Array<String>) {
    val s = readLine()!!
    val n = s.length.toLong()
    val pairCount =('a'..'z')
            .map { c -> val count = s.count { it == c }.toLong(); count * (count + 1) / 2 }
            .sum()
    val ans = 1 + n * (n + 1) / 2 - pairCount
    println(ans)
}

Measured memory_bytes: 35000
#include<stdio.h>

void show(int *hai,int N);

int main(void){
	int hai[100],i,N,j,flag=1;
	int temp,count=0;

	scanf("%d",&N);
	//printf("%d \n",N);

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

	while(flag){
		flag=0;
		for(j=N-1;j>=1;j--){
			if(hai[j]<hai[j-1]){
				temp=hai[j-1];//tempにhaiのj-1を代入
				hai[j-1]=hai[j];//hai[j-1]をhai[j]の値にする
				hai[j]=temp;
				flag=1;
				count++;
			}
		}
	}

	show(hai,N);

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

void show(int *hai,int N){
	int i;
	for(i=0;i<N;i++){
		printf("%d",hai[i]);
		if(i!=N-1)printf(" ");
	}
	printf("\n");
}


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

int main(){
	int n, m;
  cin >> n >> m;
  vector<int> h(n);
  vector<int> res(n);
  
  rep(i, n){
    cin >> h[i];
  }

  rep(i, m){
    int a, b;
    cin >> a >> b;
    a--, b--;
    if(h[a] > h[b]){res[b] = 1;}
    if(h[a] < h[b]){res[a] = 1;}
    if(h[a] == h[b]){res[a] = res[b] = 1;}
  }
  
  int bad = accumulate(res.begin(), res.end(), 0);

  cout << n - bad << endl;        
  
    return 0;
  }

Measured memory_bytes: 4056
#include <bits/stdc++.h>
#define ll long long int
#define F(i,j,k,in) for(int i=j;i<k;i+=in)
#define DF(i,j,k,in) for(int i=j;i>=k;i-=in)
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define PB push_back
#define ub upper_bound
#define lb lower_bound
#define ins insert
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll K,N,A[1000000],sec[1000000];
    cin>>K>>N;
    F(i,0,N,1)
    cin>>A[i];
    ll j=0;
    F(i,0,N-1,1)
    {
       sec[j]=A[i+1]-A[i];
       j++;
    }
    sec[j]=K-(A[N-1]-A[0]);
    ll mini=INT_MAX,sum=0,sumi;
    F(i,0,j+1,1)
    {
        sum+=sec[i];
    }
    F(i,0,j+1,1)
    {
        sumi=sum-sec[i];
        if(mini>sumi)
        {
            mini=sumi;
        }

    }

    cout<<mini;

return 0;
}



Measured memory_bytes: 7424
#include<bits/stdc++.h>
using namespace std;
 
int N,M,T;
 
int main(){
  cin>>N>>M>>T;
  int last=-M;
  int ans=0;
   
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    if( a-last >= M+M){
      ans+=( (a-last)-M-M );
    }
    last=a;
  }
 
  if( last+M <= T){
    ans+=( T-last-M);
  }
 
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,a,b,c,d;
  cin >> n;
  d = n % 10;
  c = n % 100 / 10;
  b = n % 1000 / 100;
  a = n / 1000;

  if (a == b && b == c){ 
    cout << "Yes" << endl;
  }
  else if (b == c && c == d){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
 using namespace std;
 
 int gcd(int a,int b)
 {
 	if(0==b) return a;
 	return gcd(b, a%b);
 }
 
 int main()
 {
 	int a, b;
 	scanf("%d %d", &a, &b);
 	
 	
 		printf("%d\n", gcd(a,b));
 		
	
 	return 0;
 }

Measured memory_bytes: 3184
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using ll = long long;
#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using namespace std;

int func(vector<int> vec, int prevval) {
    if (vec.size() == 0) {
        return 0;
    }

    int minval = vec[0];
    int minidx = 0;
    rep(i, 1, vec.size()) {
        if (vec[i] < minval) {
            minval = vec[i];
            minidx = i;
        }
    }
    vector<int> left;
    vector<int> right;
    rep(i, 0, minidx) {
        left.push_back(vec[i]);
    }
    rep(i, minidx + 1, vec.size()) {
        right.push_back(vec[i]);
    }

    return func(left, minval) + func(right, minval) + (minval - prevval);
}

#define PI 3.141592
// 117 -c
int main() {
    int n;
    cin >> n;

    vector<int> height(n);
    rep(i, 0, n) {
        cin >> height[i];
    }

    // queue<vector<int>> que;
    // que.push(height);
    // while (!que.empty()) {
    //     vector<int> vec = que.front();
    //     que.pop();

    //     // detect min
    //     int minval = vec[0];
    //     rep(i, 1, vec.size()) {
    //         minval = min(minv, vec[i]);
    //     }

    //     // split by minval
    //     int bgn = 0;
    //     vector<int> tmp;
    //     rep(i, bgn, vec.size()) {
    //         if (vec[i] == minval) {
    //             if (tmp.size() != 0) {
    //                 que.push(tmp);
    //                 tmp.clear();
    //             }
    //         }
    //         else{
    //             vec
    //     }
    // }

    cout << func(height, 0) << endl;

    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#pragma warning(disable:4996)

int main() {
	int a, b, c, x;
	scanf("%d", &a);//500
	scanf("%d", &b);//100
	scanf("%d", &c);//50
	scanf("%d", &x);

	int count = 0;
	for (int i = 0; i <= a; i++) 
		for (int j = 0; j <= b; j++) 
			for (int k = 0; k <= c; k++) 
				if (i * 500 + j * 100 + k * 50 == x) count++;

	printf("%d\n", count);
	//while (1);
}

Measured memory_bytes: 128
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k, t;
    cin >> k >> t;
    vi a(t);
    int ma = 0;
    rep(i, t) {
        cin >> a[i];
        ma = max(ma, a[i]);
    }

    if(ma <= k/2) {
        cout << 0 << endl;
    } else {
        if(k&1) {
            cout << ma-1-(k-ma) << endl;
        } else {
            cout << ma-1-(k-ma) << endl;
        }
    }
}

Measured memory_bytes: 256
# 解説AC
from math import sin, sqrt

N = int(input())
XY = [[int(i) for i in input().split()] for _ in range(N)]

INF = 10 ** 6

def circumcenter(i,j,k):
    """ 3点を通る円の中心(外心) """
    a,b = XY[i]
    c,d = XY[j]
    e,f = XY[k]

    aa, bb, cc, dd, ee, ff = a**2, b**2, c**2, d**2, e**2, f**2

    try:
        y = ((e - a) * (aa + bb - cc - dd) - (c - a) * (aa + bb - ee- ff)) / (2 * (e - a)*(b - d) - 2 * (c - a) * (b - f))
        x = (2 * (b - f) * y - aa - bb + ee + ff) / (2 * (e - a)) if (c == a) else (2 * (b - d) * y - aa - bb + cc + dd) / (2 * (c - a))
    except ZeroDivisionError as e:
        return (-INF, -INF)

    return (x,y)

def radius(x,y):
    """ 半径を求める """
    dist = 0
    for X,Y in XY:
        tmp = pow(X-x, 2) + pow(Y-y, 2)
        dist = max(dist, tmp)
    return sqrt(dist)

def midpoint(a,b):
    """ 2点の中点 """
    xa, ya = XY[a]
    xb, yb = XY[b]
    
    x = (xa + xb) / 2
    y = (ya + yb) / 2

    return (x, y)

def main():
    ans = float("inf")

    # 2点を直径とする円
    for a in range(N):
        for b in range(a+1,N):
            x,y = midpoint(a,b)
            r = radius(x,y)
            ans = min(ans, r)

    # 3点を通る円
    for a in range(N):
        for b in range(a+1,N):
            for c in range(b+1,N):
                x,y = circumcenter(a,b,c)
                r = radius(x,y)
                ans = min(ans, r)

    print("{0:.7f}".format(ans))

if __name__ == "__main__":
    main()

Measured memory_bytes: 3192
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#include<random>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (int)(Y);++(X))
#define reps(X,S,Y) for (int (X) = (int)(S);(X) < (int)(Y);++(X))
#define rrep(X,Y) for (int (X) = (int)(Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (int)(Y)-1;(X) >= (int)(S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define NL <<"\n"

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#include "benri.h"
#else
#define out(args...)
#endif
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
const ll MOD=1e9+7; //998244353

void no(){
	cout<<-1 NL;
	exit(0);
}

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout<<fixed<<setprecision(0);
	int n;
	cin>>n;
	vector<int> a(n+1);
	for(auto &x:a) cin>>x;
	const ll INF=2e13;
	ll l=1,r=1;
	vector<pll> ps{{l,r}};
	for(auto x:a){
		ll nl=max(0ll,l-x);
		ll nr=min(INF,(r-x)*2);
		out(l,r,x,nl,nr,1);
		l=nl;
		r=nr;
		if(r<l) no();
		ps.eb(l,r);
	}
	out(ps,1);
	if(l) no();
	ll v=0,re=0;
	rrep(i,n+1){
		v+=a[i];
		ll nxt=min(ps[i].Y,v);
		if(nxt<(v+1)/2 || nxt<ps[i].X) no();
		v=nxt;
		out(i,v,1);
		re+=v;
	}
	cout<<re NL;
  return 0;
}


Measured memory_bytes: 5708
//C - Dubious Document 2: 
//Assunto: 
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100050
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    string s, t, ans = "";
    int start, aux, pos = -1;
    cin >> s >> t;
    start = s.size() - t.size();
    for(int i = start; i >= 0; i--) {
        aux = 0;
        loop(j, 0, t.size()) {
            if(s[i+j] == '?' or s[i+j] == t[j]) aux++;
        }
        if(aux == t.size()) {
            pos = i;
            break;
        }
    }
    if(pos == -1) cout << "UNRESTORABLE\n";
    else {
        int i = 0;
        while(i < s.size()) {
            if(i == pos) {
                ans += t;
                i += t.size();
                continue;
            } 
            else if(s[i] == '?') ans += 'a';
            else ans += s[i];
            i++;
        }
        cout << ans << "\n";
    }
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int scoreT = 0, scoreH = 0;
            for(int i = 0; i < num; i++){
                String strT = sc.next();
                String strH = sc.next();
                if((strT.compareTo(strH)) == 0){
                    scoreT += 1;
                    scoreH += 1;
                }
                else if((strT.compareTo(strH)) > 0){
                    scoreT += 3;
                }
                else scoreH += 3;
            }
            System.out.println(scoreT +" "+ scoreH);
    }
}


Measured memory_bytes: 29748
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,x,y,ans=0;cin>>a>>c>>b>>x>>y;b*=2;
  if(x<y){
    a^=c;c^=a;a^=c;
    x^=y;y^=x;x^=y;
  }
  while(y){
    ans+=min(a+c,b);
    x--;y--;
  }
  while(x){
    ans+=min(a,b);
    x--;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
x = input()
a = len(x)
K = 0
U = 0
P = 0
C = 0

for j in range(a):
    if x[j] == 'K':
        K += 1
    if x[j] == 'U':
        U += 1
    if x[j] == 'P':
        P += 1
    if x[j] == 'C':
        C += 1
        
z = min(K,U,P,C)

print(z)


Measured memory_bytes: 5560
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var n = o.a();
  var a = o.a()-1;
  var b = o.a()-1;
  var c = o.a()-1;
  var d = o.a()-1;
  var s = o.a(1);
  var Y = "Yes", N = "No";
  for(var i = a; i < c;){
    if(s[i+1] === ".")i++;
    else if(s[i+2] === ".")i+=2;
    else return N;
  }
  for(var i = b; i < d;){
    if(s[i+1] === ".")i++;
    else if(s[i+2] === ".")i+=2;
    else return N;
  }
  if(c<d)return Y;
  for(var i = b; i <= d; i++){
    if(s[i-1]+s[i]+s[i+1] === "...")return Y;
  }
  return N;
}

Measured memory_bytes: 10188
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
res = 0
for i in range(n-1):
    if a[i+1] == a[i]:
        a[i+1] = INF
        res += 1
print(res)

Measured memory_bytes: 38384
#include<stdio.h>

#define N 1000
#define M 10000
#define O 0
#define I 1
#define W 2

int n,s,a[N],b[N],T[M+I];


int partition(int a[],int p,int r){
  int i,j,t,x;
  x=a[r];
  i=p-I;
  for(j=p;j<r;j++){
    if(a[j]<=x){
      i++;
      t=a[i];
      a[i]=a[j];
      a[j]=t;
    }
  }
  t=a[i+I];
  a[i+I]=a[r];
  a[r]=t;
  return i+I;
}
void quickSort(int a[],int p,int r){
  int q;
  if(p<r){
    q=partition(a,p,r);
    quickSort(a,p,q-I);
    quickSort(a,q+I,r);
  }
}


int solve(){
  int i,c,S,m,A,v,ans=O;

  int V[N];
  for(i=O;i<n;i++){
    b[i]=a[i];
    V[i]=O;
  }
  quickSort(b,0,n-I);

  for(i=O;i<n;i++){
    T[b[i]]=i;
  }
  for(i=O;i<n;i++){
    if(V[i]){
      continue;
    }
    c=i;
    S=O;
    m=M;
    A=0;
    while(I){
      V[c]=I;
      A++;
      v=a[c];
      if(v<m){
	m=v;
      }
      S+=v;
      c=T[v];
      if(V[c]){
	break;
      }
    }
    if(S+(A-W)*m<m+S+(A+I)*s){
      ans+=S+(A-W)*m;
    }
    else{
      ans+=m+S+(A+I)*s;
    }
  }
  return ans;
}

int main(){
  int i;

  scanf("%d",&n);
  s=M;
  for(i=O;i<n;i++){
    scanf("%d",&a[i]);
    if(a[i]<s){
      s=a[i];
    }
  }
  int ans=solve();
  printf("%d\n",ans);
  return O;
}



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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

//-------------------------------------------------
//--Graph Template
//-------------------------------------------------
template<class E>
struct Graph
{
    vector<vector<E> > adj;
    Graph(int N):adj(N){}
    virtual void add_edge(int v, E e){adj[v].push_back(e);}
    vector<E>& operator[](int v){return adj[v];}
    inline int size(){return adj.size();}
};

struct NormalEdge {
    int to;
    NormalEdge(int to):to(to){}
};

struct UWGraph : public Graph<NormalEdge>
{
    UWGraph(int N):Graph(N){}
    void add_edge(int v, int e){adj[v].push_back({e});}
};

//-------------------------------------------------
//--Dist BFS
//-------------------------------------------------
template<class E>
vector<int> distBFS(Graph<E> &G, int s)
{
    vector<int> dist(G.size(),-1); dist[s]=0;
    queue<int> que; que.push(s);
    while(!que.empty()){
        int v = que.front(); que.pop();
        for(auto e:G[v]){
            if (dist[e.to]!=-1) continue;
            dist[e.to]=dist[v]+1;
            que.push(e.to);
        }
    }
    return dist;
}

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin>>N;
    UWGraph G(N);
    rep(i,N){
        int u,k; cin>>u>>k; u--;
        rep(i,k){
            int v; cin>>v; v--;
            G.add_edge(u,v);
        }
    }
    auto dist = distBFS(G,0);
    rep(i,N){
        cout<<i+1<<" "<<dist[i]<<"\n";
    }
    return 0;
}



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

const int N = 100010;

typedef long long LL;

LL num[N]; int pos[N];

int main() {
    int n, s; scanf("%d%d", &n, &s);
    for (int i = 1; i <= n; i++) scanf("%d%lld", &pos[i], &num[i]);
    int l = 1, r = n, ls = 0; LL res = 0;
    for (int i = 1; i <= n; i++) {
        if (pos[l] > s) { res += pos[r] - s; break; }
        if (pos[r] < s) { res += s - pos[l]; break; }
        int nw;
        if (num[l] >= num[r]) nw = 1, num[l] += num[r];
        else nw = -1, num[r] += num[l];
        if (nw != ls) res += pos[r] - pos[l];
        ls = nw;
        if (nw == -1) l++; else r--;
    }
    printf("%lld\n", res);
    return 0;
}


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

#define FOR(i, a, n) for (int i = a; i < (int)n; i++)
#define REP(i, n) FOR(i, 0, n)

int H, W;
char a[100][100];
int c[26];

int main()
{
  cin >> H >> W;
  REP(h, H) REP(w, W) cin >> a[h][w];
  REP(h, H) REP(w, W) c[a[h][w]-'a']++;

  int nodd = 0;
  int n2   = 0;
  REP(i, 26) {
    if (c[i] % 2 != 0) { nodd++; c[i]--; }
    if (c[i] % 4 != 0 && c[i] % 2 == 0) n2++;
  }

  bool heven = H % 2 == 0;
  bool weven = W % 2 == 0;
  if (heven && weven) {
    if (nodd > 0) { cout << "No" << endl; return 0; }
    cout << (n2 == 0 ? "Yes" : "No") << endl;
  } else if (heven && !weven) {
    if (nodd > 0) { cout << "No" << endl; return 0; }
    cout << (n2 <= H/2 ? "Yes" : "No") << endl;
  } else if (!heven && weven) {
    if (nodd > 0) { cout << "No" << endl; return 0; }
    cout << (n2 <= W/2 ? "Yes" : "No") << endl;
  } else {
    if (nodd > 1) { cout << "No" << endl; return 0; }
    cout << (n2 <= H/2 + W/2 ? "Yes" : "No") << endl;
  }

  return 0;
}

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

int main() {
	int a, b, c, x;
	int count = 0;
	cin >> a >> b >> c >> x;
	for (int i = 0; i <= a; i++) {
		for (int j = 0; j <= b; j++) {
			for (int k = 0; k <= c; k++) {
				if (500 * i + 100 * j + 50 * k == x) {
					count++;
				}
			}
		}
	}

	cout << count;
	return 0;
}

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

#define f(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define int long long
using namespace std;
#define mod 1000000007
signed main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    string s;cin>>s;
    int n=s.length();
    if(s[n-1]=='s'){
    	s+="es";
    }
    else{
    	s+="s";
    }
    cout<<s<<endl;

    
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main(){
  int k, n;
  cin >> k >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];

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

  int diff = a[0] + (k - a[n-1]);
  for(int i = 1; i < n; i++) {
    diff = max((a[i] - a[i-1]), diff);
  }

  cout << k - diff << endl;
  return 0;
}


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

int main() {
  int n,a=0,b=0;
  cin >> n;
  vector<int> s(n);
  rep(i,n) cin >> s.at(i);
  sort(s.begin(),s.end());
  reverse(s.begin(),s.end());
  rep(i,n){
    if (i%2==0) a += s.at(i);
    else b += s.at(i);
  }
  cout << a-b << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[1005],b[1005],d[40005];
int main(){
    ll h,n,mx=0,ans=1e9;
    cin>>h>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i]>>b[i];
        mx=max(mx,a[i]);
    }
    memset(d,0x3f,sizeof(d));
    d[0]=0;
    for(int i=1;i<=n;i++){
        for(int j=a[i];j<=h+mx;j++){
            d[j]=min(d[j],d[j-a[i]]+b[i]);
        }
    }
    for(int i=h;i<=h+mx;i++){
        ans=min(ans,d[i]);
    }
    cout<<ans<<endl;
}                     

Measured memory_bytes: 640
import sys
import re


def lookup(tbl, n):
    for (i,j) in tbl:
        if i == n:
            return j
    else:
        return n

def rlookup(tbl, n):
    for (i,j) in tbl:
        if j == n:
            return i
    else:
        return n


class Affine:
    def __init__(self, a, b):
        tbl = zip(range(27), "abcdefghijklmnopqrstuvwxyz")
        cipher = map(lambda n: lookup(tbl, ((a * n + b) % 26)), range(27))
        self.cipher_table = zip("abcdefghijklmnopqrstuvwxyz", cipher)

    def encrypt(self, str):
        return ''.join(map(lambda c: lookup(self.cipher_table, c), str))

    def decrypt(self, str):
        return ''.join(map(lambda c: rlookup(self.cipher_table, c), str))



r = re.compile("that|this")

sys.stdin.readline()
for line in sys.stdin:
    line = line.rstrip("\r\n")
    for a in [1,3,5,7,9,11,15,17,19,21,23,25]:
        for b in range(26):
            affine = Affine(a, b)
            result = affine.decrypt(line)
            m = r.findall(result)
            if not len(m) == 0:
                 print result

Measured memory_bytes: 4276
#include <iostream>
#include <cmath>

using namespace std;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int,int>;
using vi = std::vector<int>;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    int n,k; cin >> n >> k;
    string s; cin >> s;
    int ans=0;
    vector<int> ps;
    ps.emplace_back(0);
    for(int i=1;i<n;i++){
        if(s[i] != s[i-1]){
            ps.emplace_back(i);
        }
    }
    ps.emplace_back(n);
    int m = ps.size();
    //cout << ps << endl;

    rep(i,ps.size()-1){
        int ei = m-1;
        if(s[ps[i]] == '1'){
            ei = min(ei, i+2*k+1);
        }else{
            ei = min(ei, i+2*k);
        }
        int len = ps[ei] - ps[i];
        //cout << i << " " << ei << " " << len << endl;
        chmax(ans, len);
    }

    cout << ans << endl;
}


Measured memory_bytes: 4008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

int main() {
    string S; cin >> S;
    if (S == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
}

Measured memory_bytes: 3592
MOD=10**9+7
H,W=map(int,input().split())
G=[input() for i in range(H)]
dp=[[0]*W for i in range(H)]
dp[0][0]=1

for i in range(H):
    for j in range(W):
        if(G[i][j]=='#'):
            continue
        if(i+1<H and G[i+1][j]!='#'):
            dp[i+1][j]=(dp[i+1][j]+dp[i][j])%MOD
        if(j+1<W and G[i][j+1]!='#'):
            dp[i][j+1]=(dp[i][j+1]+dp[i][j])%MOD
print(dp[H-1][W-1])

Measured memory_bytes: 43712