akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

int main(){
  
  int r=0, b=0;
  int n;
  cin>>n;
  string s;
  cin>>s;
  REP(i,n){
    if(s[i]=='R'){
      r++;
    }else{
      b++;
    }
  }
  
  if(r>b){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  
  return 0;
}


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

using lint=long long;



void solve(){
    string s;
    cin>>s;
    sort(s.begin(), s.end());
    if(s[0]==s[1] && s[2]==s[3] && s[0]!=s[3]){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

signed main(){
    //while(1)
    solve();
}

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

int main() {
  int N, K, S;
   cin >> N >> K;
  
  S = 0;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    if ( x <= K / 2) {
      S += 2 * x;
    }
    else {
      S += 2 * (K - x);
    }
  }
    cout << S << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 1e5; int n;
const lli inf = 1e18;
struct Problem
{
  lli l, r;
  void read() { scanf("%lld %lld", &l, &r); }
};
Problem problems[maxN];

int main()
{
  while (scanf("%d", &n) != EOF)
  {
    lli maxL = -inf, minR = inf;
    for (int i = 0; i < n; i ++)
    {
      problems[i].read();
      maxL = max(maxL, problems[i].l);
      minR = min(minR, problems[i].r);
    }

    lli ans = 0;
    // maxL and minR will have to either be in the same contest or not

    // if they're in the same contest:
    for (int i = 0; i < n; i ++)
      ans = max(ans, max(0LL, minR - maxL + 1) + problems[i].r - problems[i].l + 1);

    // if they're not in the same contest:
    vector<pair<lli, lli>> a;
    for (int i = 0; i < n; i ++)
      a.push_back({max(0LL, problems[i].r - maxL + 1), -max(0LL, minR - problems[i].l + 1)});
    sort(a.begin(), a.end());

    lli curr = -a[0].second;
    for (int i = 1; i < n; i ++)
    {
      ans = max(ans, curr + a[i].first);
      curr = min(curr, -a[i].second);
    }
    printf("%lld\n", ans);
  }

  return 0;
}

Measured memory_bytes: 3956
#include<iostream>

using namespace std ;

int main()
{
	int a ,b ;
	while( cin >> a >> b )
	{
		if( a == b && !a )
			return 0 ;
		if( a > b )
			cout << b << ' ' << a << endl ;
		else
			cout << a << ' ' << b << endl ;
	}
}

Measured memory_bytes: 3052
using DataStructures
const double = Float64
const int = Int64

parseint(x) = parse(int, x)
readint() = map(parseint, split(readline()))

const MOD = 1000000007
 
function main()
  N,M = readint()
  A = Vector{int}(undef,M)
 
  if N==1
    println(1)
    return
  end

  step = Vector{int}(undef,N+1)
  step[0+1] = 1
  step[1+1] = 1
  for i in 3:N+1
    step[i] = (step[i-1] + step[i-2])%MOD
  end

  for i in 1:M
    A[i] = readint()[1]
  end
  
  for i in 2:M
    if A[i]-A[i-1] == 1
      println(0)
      return
    end
  end

  s = 1
  k = 0
  for i in 1:M
    s *= step[A[i]-k]
    s = s % MOD
    k = A[i]+1
    #println(A[i]-k)
  end
  s *= step[N-k+1]
  s = s%MOD

  println(s)


end



main()

Measured memory_bytes: 210168
//#define LOCAL 

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>

#define SIZE 10

using namespace std;

int map[SIZE];

bool dfs(int a, int b, int pos){
	//printf("a: %d b: %d pos: %d\n", a, b, pos);

	if(pos == SIZE)
		return true;

	if(map[pos] > a)
		return dfs(map[pos], b, pos + 1);

	if(map[pos] > b)
		return dfs(a, map[pos], pos + 1);

	return false;
}

int main(void){
#ifdef LOCAL
	freopen("data.in", "r", stdin);
#endif 
	int n;
	
	scanf("%d", &n);
	while(n--){
		for(int i = 0; i < SIZE; i++){
			scanf("%d", &map[i]);
	//		printf("%d ", map[i]);
		}
	//	printf("\n");

		if(dfs(0, 0, 0))
			printf("YES\n");
		else
			printf("NO\n");
	}

	return 0;
}


Measured memory_bytes: 2596
#include <iostream>
#define rep(a,b,c) for(int a=b;a<c;a++)
#define rep_(a,b,c) for(int a=c-1;a>=b;a--)
using namespace std;

int main()
{
	cin.sync_with_stdio(false);
	cout.sync_with_stdio(false);
	int a[100005],b[100005],c[100005],n,t,p=0,q=0;
	cin >>n>>t;
	rep(i,0,n) cin >> a[i],b[i]=((i)?min(a[i],b[i-1]):a[i]);
	c[n-1]=a[n-1];rep_(i,0,n-1) c[i]=max(a[i],c[i+1]);
	rep_(i,0,n)
	{
		t=a[i]-b[i];
		if (p<t) p=t,q=0;
		if (p==t) q++;
	}
	int P=0,Q=0;
	rep(i,0,n)
	{
		t=c[i]-a[i];
		if (P<t) P=t,Q=0;
		if (P==t) Q++;
	}
	cout << min(q,Q) << endl;
}

Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;
int n,d,cnt;
int main()
{
	cin>>n>>d;
	for(int i = 1;i <= n;i++)
	{
		int x,y;
		cin>>x>>y;
		long double dis = sqrt((ll)abs(x) * abs(x) + (ll)abs(y) * abs(y));
		if(dis <= d) cnt++;
	}
	cout<<cnt;
	return 0;
} 

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

string STR;
bool N, S, E, W;


int main() {
	cin >> STR;
	
	for(char c : STR) {
		if(c == 'N')
			N = true;
		if(c == 'E')
			E = true;
		if(c == 'W')
			W = true;
		if(c == 'S')
			S = true;
	}
	
	if((N + S) % 2 || (E + W) % 2) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
	
	
	
	return 0;
}


Measured memory_bytes: 256
using LIB;
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        int[] n = io.r<int>(' ');
        io.w((n[0] / n[1]).ToString() + " " + (n[0] % n[1]).ToString() + " " + ((double)n[0]/(double)(n[1])).ToString("0.000000"));
        io.wflush();
    }
}

namespace LIB
{
    public class io
    {
        private const int WMAX = 1000;
        private static StringBuilder S = new StringBuilder();
        public static T r<T>() { return util.parse<T>(r()); }
        public static T[] r<T>(char s = ' ') { return r().Split(s).Select(util.parse<T>).ToArray(); }
        public static T[] r<T>(int l) { T[] r = new T[l]; for (int i = 0; i < l; i++) { r[i] = r<T>(); } return r; }
        public static T[][] r<T>(int l, char s = ' ') { T[][] r = new T[l][]; for (int i = 0; i < l; i++) { r[i] = r<T>(s); } return r; }
        private static string r() { return Console.ReadLine(); }
        public static void w(object v, bool lf = true) { S.Append(util.parse<string>(v)); if (lf == true) { S.Append('\n'); } if (S.Length >= WMAX) { wflush(); } }
        public static void wflush() { Console.Write(S.ToString()); S.Length = 0; }
    }
    public class util
    {
        public static T parse<T>(object value) { return (T)(Convert.ChangeType(value, typeof(T))); }
    }
    public class memo<Key, Result>
    {
        private Dictionary<Key, Result> R;
        public memo() { R = new Dictionary<Key, Result>(); }
        public Result exec(Key k, Func<Key, Result> f) { Result r; if (R.ContainsKey(k)) { r = R[k]; } else { r = f(k); R.Add(k, r); } return r; }
    }
}

Measured memory_bytes: 10324
#include<iostream>
#include<algorithm>
using namespace std;
using ll=long long;
ll N,A[300][300],ans;
int main(){
    cin>>N;
    for(int i{};i<N;++i)
        for(int j{};j<N;++j)
            cin>>A[i][j];
    for(int i{};i<N;++i)
        for(int j{i+1};j<N;++j){
            int f{};
            for(int k{};k<N;++k){
                if(A[i][j]>A[i][k]+A[k][j]){
                    cout<<-1<<endl;
                    return 0;
                }
                if(i!=k&&j!=k&&A[i][j]==A[i][k]+A[k][j])
                    f=1;
            }
            if(!f)ans+=A[i][j];
        }
    cout<<ans<<endl;
}


Measured memory_bytes: 896
import numpy as np

N = int(input())
A = list(map(int, input().split()))
A = np.array(A)

mod = 10 ** 9 + 7
s = 0

for i in range(60):# Aは2の6乗より小さい
    c = np.count_nonzero(A & 1) # 最下位のbitで0じゃないものの個数
    s += 2 ** i * c * (N - c) # https://qiita.com/ZhangChaoran/items/0d59eb5c95cd9414801d
    A >>= 1 #　1bitずつ右にずらす。これを繰り返し続ける
print(s % mod)

Measured memory_bytes: 49848
#include <bits/stdc++.h>
        using namespace std;
        #define int long long int
        #define pb push_back
        #define mk make_pair
        #define ft first
        #define sc second
        #define ppb pop_back
        #define sz size
        #define forn(i,a,n) for(i=a;i<n;i++)
        #define M 998244353 
        #define inf 2e18

        bool compare(pair<int,int> a,pair<int,int> b){
            if(a.first==b.first)
                return a.second<b.second;
            return a.first<b.first;
        }

        signed main() {
 
     
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        
        int n,m;
        cin>>n>>m;

        vector<int> h(n+1);
        for(int i=1;i<=n;i++)
            cin>>h[i];

        vector<int> val(n+1,0);
        for(int i=0;i<m;i++){
            int a,b;
            cin>>a>>b;
            val[a]=max(val[a],h[b]);
            val[b]=max(val[b],h[a]);
        }
        int ans=0;
        for(int i=1;i<=n;i++){
            if(h[i]>val[i])
                ans++;
        }
        cout<<ans;




        return 0;
    }

Measured memory_bytes: 4784
#include<bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
int n;
ll dp[200005];//dp[i] end with i's best solution
int a[200005],h[200005];
struct BIT{
	ll data[200005];
	void modify(int x,ll y){
		while(x<=n){
			data[x]=max(data[x],y);
			x+=x&-x;
		}
	}
	ll get(int x){
		ll ret=0;
		while(x){
			ret=max(ret,data[x]);
			x&=x-1;
		}
		return ret;
	}
}bit;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&h[i]);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=n;i++){
		dp[i]=bit.get(h[i])+a[i];
		bit.modify(h[i],dp[i]);
	}
	printf("%lld\n",*max_element(dp+1,dp+n+1));
	return 0;
}

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


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

#define int long long
#define ll long long
#define vll vector<int>
#define mset(a) memset(a,0,sizeof(a))
#define pb push_back
#define range(c) c.begin() , c.end()
#define forn(i,n) for(ll i=0; i<(int)n; ++i)
#define for1(i,n) for(ll i=1; i<(int)n; ++i)
#define endl '\n'
#define MOD 1000000007
#define pii pair<int,int>
#define test ll t;cin>>t;while(t--)
using namespace std;

vector<bool> sieve(ll n){
    vector<bool>prime(n+1,true);
    prime[0]=prime[1]=false;
    for(ll i=2; i<=n; ++i){
        if(prime[i]&&(i*i)<=n)
        for(ll j=i*i; j<=n; j+=i)prime[j]=false;
    }
    return prime;
}

ll power(ll a, ll b, ll m = MOD) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

//////////////////////////////////////////////////////////////

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

   

    int n,k;cin>>n>>k;
    vll a(n);
    forn(i,n) cin>>a[i];

    vll dp(n+2+k,INT_MAX);
    dp[0] = 0;

    forn(i,n-1) {
        forn(j,k) {
            int diff = abs(a[j+i+1]-a[i]);
            dp[i+j+1] = min(dp[i+j+1], dp[i]+diff);
        }
    }   
    cout<<dp[n-1]<<endl;

    return 0;
}


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


int main() {
	int i, j, k;
	int m, n;
	int f = 0;
	int g = 0;
	int x[110] = {0};
	int a, b, c, d;


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

	for (i = 0;i < k;i++) {
		scanf("%d", &d);
		for (j = 0;j < d;j++) {
			scanf("%d", &g);
			x[g]++;
		}
	}
	
	for (i = 1;i < n+1;i++) {
		if (x[i] == 0) {
			f++;
		}
	}

	printf("%d", f);

	return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define In_The_Name_Of_Allah_The_Merciful ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define Alhamdulillah return 0;
#define all(v) v.begin(),v.end()
#define debug(n) cerr << "[" << #n << " = " << n << "]" << endl 

void Suhaib_Sawalha (){

    int n , m , d;
    cin >> n >> m >> d;
    int ans = 0;
    for (int i = 1 ; i <= 100 ; ++i){
        ans += (d * i <= m && d * i >= n);
    }
    cout << ans;
}

int main(){
                                In_The_Name_Of_Allah_The_Merciful   /* بسم الله الرحمن الرحيم  */
#ifndef ONLINE_JUDGE
    freopen("SuhaibSawalha1.txt","r",stdin);
#endif
//int _;for(cin>>_;_;--_,cout<<'\n')
        Suhaib_Sawalha();
                                         Alhamdulillah                    /* الحمد لله */
}

Measured memory_bytes: 3644
M, K = map(int, input().split(" "))

if (M, K) == (1, 0):
    print("0 0 1 1")
elif K > (2 ** M) - 1 or (M, K) == (1, 1):
    print(-1)
else:
    elems = list(x for x in range(2 ** M) if x != K)
    print(' '.join(str(x) for x in elems), K, ' '.join(str(x) for x in reversed(elems)), K)


Measured memory_bytes: 86496
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
using namespace std;
struct data_t{
  int k; int pref; int city; int cnum;
};
int main(void)
{
  int n, m;
  data_t c[100000];
  vector<int> pend;
  cin >> m >> n;
  rep(i, n){
    data_t tmp;
    int k, pref, city;
    cin >> pref >> city;
    tmp.k = i;
    tmp.pref = pref;
    tmp.city = city;
    tmp.cnum = 0;
    c[i] = tmp;
  }
  sort(c, c + n,
    [](const data_t &a, const data_t &b){return a.pref < b.pref;});
  pend.push_back(0);
  rep(i, n){
    if(i > 0 && c[i].pref != c[i - 1].pref){
      pend.push_back(i);
    }
  }
  pend.push_back(n);
  // rep(i, n) cout << c[i].pref << " " << c[i].city << endl;
  rep(i, pend.size() - 1){
    sort(c + pend[i], c + pend[i + 1],
      [](const data_t &a, const data_t &b){return a.city < b.city;});
    rep(j, pend[i + 1] - pend[i]){
      c[pend[i] + j].cnum = j + 1;
    }
  }
  sort(c, c + n,
    [](const data_t &a, const data_t &b){return a.k < b.k;});
  rep(i, n){
    printf("%06d%06d\n",c[i].pref,c[i].cnum);
  }
  // rep(i, m + 1) printf("%d ", pend[i]);
  return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	int c4=0,c2=0,codd=0;
	for(int i=0;i<n;i++){
		long long a;
		cin >> a;
		if(a%4==0)
			c4++;
		else if(a%2==0)
			c2++;
		else codd++;
	}
	codd=codd+c2%2;
	codd--;
	if(c4>=codd)
		cout << "Yes" << endl;
	else cout << "No" <<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define pb push_back
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
#define x1 xdddddddddddddddddd
#define y1 ydddddddddddddddddd

int x,y;

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> x >> y;
    cout << x+y/2;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>
#include <functional>
#include <cassert>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (a) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define ASSERT(cond,mes) assert(cond && mes)

using namespace std;
using ll = long long;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
    REP(i, (int)v.size())os << v[i] << endl;
    return os;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

bool isAllVisit(const vector<bool>& visit) {
    for (auto&& v : visit) {
        if (!v)return false;
    }
    return true;
}

std::vector<int> enum_div(int n) {
    std::vector<int> ret;
    for (int i = 1; i*i <= n; ++i) {
        if (n%i == 0) {
            ret.push_back(i);
            if (i != 1 && i*i != n) {
                ret.push_back(n / i);
            }
        }
    }
    return ret;
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);

    int N;
    cin >> N;
    vector<int>A(N);
    cin >> A;

    SORT(A);

    bool isRight = true;
    if (N % 2 == 1) {
        if (A[0] != 0)isRight = false;

        for (int i = 1; i < N; i += 2) {
            if (!(A[i] == A[i + 1] && A[i + 1] == i + 1))isRight = false;
        }
    }
    else {
        for (int i = 0; i < N; i += 2) {
            if (!(A[i] == A[i + 1] && A[i + 1] == i + 1))isRight = false;
        }
    }

    if (!isRight) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1;
    int num = N % 2 == 0 ? N / 2 : (N - 1) / 2;
    REP(i, num) {
        ans *= 2;
        ans %= MOD;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
int            main
(){             int
a,b           , c;
scanf("%d %d %d"   ,&a,&        b,&c)     ;if    ((
a==              b&&   b!=   c)||    (c   ==b  &&a
!=c             )||     (a   ==c     &&b  !=c)){
puts             ("Y"  "e"    "s"   );}   else{
puts              ("No");      }return    0;}

Measured memory_bytes: 128
n, a, b = map(int, input().split())

def kurikaeshi(x, n, mod):
    if n == 1:
        return x%mod
    elif n %2 == 0:
        return kurikaeshi(x, n//2, mod)**2%mod
    elif n %2 == 1:
        return kurikaeshi(x, n//2, mod)**2*x%mod
    
    
def combination(n, a, mod):
    bunbo = 1
    bunshi = 1
    for i in range(a):
        bunshi *= n-i
        bunshi = bunshi%mod
        bunbo *= a-i
        bunbo = bunbo%mod
        
    return bunshi*pow(bunbo, mod-2, mod)%mod
        
        
mod = 1000000007
answer = pow(2, n, mod)
answer -= 1
answer -= combination(n, a, mod)
answer -= combination(n, b, mod)
print(answer%mod)

Measured memory_bytes: 3064
class FenwickTree:
    def __init__(self, n):
        self.n = n
        self.bit = [0]*(n+1)
    
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= i & -i
        return s
    
    def add(self, i, x):
        while i <= self.n:
            self.bit[i] += x
            i += i & -i
    
    def get_sum(self, i, j):
        return self.sum(j) - self.sum(i)
    


def main():
    n, q = map(int, input().split())
    a = list(map(int, input().split()))
    
    bit = FenwickTree(n)
    for i, x in enumerate(a):
        bit.add(i+1, x)
    
    for i in range(q):
        query = list(map(int, input().split()))
        if query[0] == 0:
            bit.add(query[1]+1, query[2])
        else:
            print(bit.get_sum(query[1], query[2]))
    
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 65056
package main

import (
	"fmt"
)

// 貰うDP(動的計画法)

func main() {

	var n int
	fmt.Scan(&n)

	h := make([]int, n)
	for i := 0; i < n; i++{
		fmt.Scan(&h[i])
	}

	dp := make([]int, n+10)
	dp[1] = abs(h[1] - h[0])

	for i := 2; i < n; i++ {
		d1 := dp[i-1] + abs(h[i]-h[i-1])
		d2 := dp[i-2] + abs(h[i]-h[i-2])

		if d1 < d2 {
			dp[i] = d1
		} else {
			dp[i]= d2
		}
	}
	fmt.Println(dp[n-1])

}

func abs(n int) int {
	y := n >> 63
	return (n ^ y) - y
}


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

#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
using vs = vector<string>;
constexpr int inf = 1<<30;
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

string replace(string s, const string &a, const string &b){
  string::size_type pos = 0;
  while(1){
    pos = s.find(a,pos);
    if(pos == string::npos) break;
    s.replace(pos,a.size(),b);
    pos += b.size();
  }
  return s;
}

int bfs(const vs &as, const vs &bs, string c, const string &d, int depth){
  int n = as.size();
  int minv = inf;
  int csz = c.size(), dsz = d.size();
  rep(i,n){
    string after = replace(c, as[i], bs[i]);
    if(after.size() == csz) continue;
    if(after.size() < dsz) chmin(minv, bfs(as, bs, after, d, depth+1));
    else if(after == d) chmin(minv, depth);
  }
  return minv;
}

int main(){
  int n;
  while(cin >> n, n){
    vs as(n), bs(n);
    rep(i,n) cin >> as[i] >> bs[i];
    string c, d; cin >> c >> d;
    int ans = bfs(as,bs,c,d,1);
    if(ans == inf) cout << -1 << endl;
    else cout << ans << endl;
  }
}


Measured memory_bytes: 3044
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,a) for(int i=0;i<(a);i++)
#define MOD 1000000007

int p[10]={0,0,0,0,0,0,1,1,1,2};
int q[10]={1,1,1,2,2,3,2,2,3,3};
int r[10]={2,3,4,3,4,4,3,4,4,4};

int main(){
  int N;
  cin>>N;
  vector<set<string>> v(5);
  for(int i=0;i<N;i++){
    string s;
    cin>>s;
    char c=s[0];
    if(c=='M') v[0].insert(s);
    if(c=='A') v[1].insert(s);
    if(c=='R') v[2].insert(s);
    if(c=='C') v[3].insert(s);
    if(c=='H') v[4].insert(s);
  }
  ll num[5];
  for(int i=0;i<5;i++) num[i]=v[i].size();
  ll ans=0;
  for(int i=0;i<10;i++){
    ans+=num[p[i]]*num[q[i]]*num[r[i]];
  }
  cout<<ans<<endl;
  return 0;
}


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

const int DIM = 1e5 + 5;

long long arr[DIM];

inline long long solve( int n ) {
    long long sum( arr[1] ), ans( 0 );
    
    for( int i = 2; i <= n; i ++ ) {
        if( sum < 0 && sum + arr[i] <= 0 )
            ans += 1 - sum - arr[i], sum = 1;
        else
        if( sum > 0 && sum + arr[i] >= 0 )
            ans += 1 + sum + arr[i], sum = -1;
        else
            sum += arr[i];
    }
    
    return ans;
}

int main( void ) {
    
    int n;
    cin >> n;
    
    long long ans( 1e18 );
    for( int i = 1; i <= n; i ++ )
        cin >> arr[i];
    
    if( arr[1] != 0 ) {
        long long cst = abs( arr[1] ) + 1;
        ans = min( ans, solve( n ) + 0 );
        
        arr[1] = arr[1] * -1 / abs( arr[1] );
        ans = min( ans, solve( n ) + cst );
    }
    else {
        arr[1] = -1;
        ans = min( ans, solve( n ) + 1 );
        
        arr[1] = +1;
        ans = min( ans, solve( n ) + 1 );
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
a,b,c=map(int,input().split())
import math
d=math.sin(math.radians(c))
print(a*b*d/2)
e=math.cos(math.radians(c))
x=math.sqrt(a**2+b**2-2*a*b*e)
print(a+b+x)
print(2*(a*b*d/2)/a)


Measured memory_bytes: 5708
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string.h>
#define _USE_MATH_DEFINES
#define LL long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
using namespace std;

int max(int *ary) {
	int max = 0;
	for (int i = 0; i < sizeof(ary) / sizeof(ary[0]); i++)
		if (max < ary[i]) max = ary[i];
	return max;
}

int nmax(int *ary) {
	int max = 0, num;
	for (int i = 0; i < sizeof(ary) / sizeof(ary[0]); i++)
		if (max < ary[i]) {
			max = ary[i];
			num = i;
		}
	return max, num;
}

int main() {
	int n, a[100000], now = 1;
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	for (int i = 1; i <= n; i++) {
		if (a[now - 1] == 2) {
			cout << i << endl;
			return 0;
		}
		else now = a[now - 1];
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int mot(int a,int x){
    int i=1;
    while(1){
        if((double)i*(100+x)/100>=a){
            if((double)i*(100+x)/100<a+1)return i;
            else return 0;
        }
        i++;
    }
}

void solve(int x,int y,int s){
    int X=x+100,Y=y+100;
    int ans=0;
    for(int i=1;i<=s/2;i++){
        int ax=i,bx=s-i;
        //cout<<ax<<"!"<<bx<<endl;
        ax=mot(ax,x);
        bx=mot(bx,x);
        //cout<<ax<<"?"<<bx<<endl;
        ax=ax*Y/100;
        bx=bx*Y/100;
        ans=max(ax+bx,ans);
        //cout<<ax<<" "<<bx<< " "<<ax+bx<<endl;
    }
    cout<<ans<<endl;
}


int main(void){
    int a,b,c;
    while(cin>>a>>b>>c,a){
        solve(a,b,c);
    }
    
}

Measured memory_bytes: 3080
import sys

while True:
    n = int(sys.stdin.readline())
    if n == 0:
        break
    
    score = []
    for i in xrange(n):
        x = int(sys.stdin.readline())
        
        score.append(x)
    score.sort()
    result = score[1:-1]
    print sum(result) / len(result)

Measured memory_bytes: 4224
#include<iostream>
#include<vector>
#include<string>

using namespace std;

char returnc(char c){
  if('a'<=c && c<='z'){
    if(c=='z')return 'a';
    return ++c;
  }
  return c;
}
int main(void){
  string s;
  while(getline(cin,s)){

  vector<string> ss;
  string str;
  s+= " ";
  for(int i = 0 ; i < s.size() ; i ++){
    if(s[i] == ' '){
      ss.push_back(str);
      str="";
    }else{
      str+=s[i];
    }
  }
  bool ok=true;
  string out[] = {"this","that","the"};
  while(ok){
    for(int i = 0 ; i < ss.size(); i ++){
      //cout<<ss[i]<<endl;
      for(int j = 0 ; j < ss[i].size() ; j ++){
	ss[i][j] = returnc(ss[i][j]);
      }
      for(int j = 0 ; j < 3 ; j ++){
	if(ss[i] == out[j])ok=false;
      }
    }
  }
  for(int i = 0 ; i < ss.size()-1 ; i ++){
    cout<<ss[i]<<" ";
  }
  cout<<ss[ss.size() - 1]<<endl;
  }
}

Measured memory_bytes: 1184
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int k = sc.nextInt();
        if (k % 2 == 0) {
            out.println(-1);
        } else if (k == 7) {
            out.println(1);
        } else {
            long pow = 1;
            for (int i = 1; i <= k; i++) {
                if ((pow * 7) % k == 0) {
                    out.println(i);
                    out.close();
                    return;
                }
                pow = (pow + pow(10, i, k)) % k;
            }
            out.println(-1);
        }
        out.close();
    }

    static int pow(long b, int e, int mod) {
        long ans = 1;
        while (e > 0) {
            if (e % 2 == 1)
                ans = ans * b % mod;
            e >>= 1;
            b = b * b % mod;
        }
        return (int) ans;
    }

    static int inv(int x, int mod) {
        return pow(x, mod - 2, mod);
    }


    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

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

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}

Measured memory_bytes: 33100
using System;
using System.Collections.Generic;

namespace AtCorderPractice
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var _ = LnInts();
            var N = _[0];
            var M = _[1];
            var cities = new int[N];
            for (int i = 0; i < M; i++)
            {
                var roadBetween = LnInts();
                cities[roadBetween[0]-1]++;
                cities[roadBetween[1]-1]++;
            }
            foreach (var v in cities) Console.WriteLine(v);
        }

        public static string[] LnStrs()
        {
            var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            return vs;
        }
        public static string LnStr()
        {
            var vs = Console.ReadLine().Trim();
            return vs;
        }
        public static int[] LnInts()
        {
            var vs = Console.ReadLine().Trim().Split(new[] {' '},StringSplitOptions.RemoveEmptyEntries);
            var ins = new int[vs.Length];
            for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]);
            return ins;
        }
        public static int LnInt()
        {
            var vs = Console.ReadLine().Trim();
            return int.Parse(vs);
        }
    }
}

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

int main(){
    int a,b,k;
    cin>>a>>b>>k;

    vector<int> x;

    for(int i = 100 ; i >0 ;i--){
        if(a%i == 0 && b%i == 0){
            x.push_back(i);
        }
    }

    cout<<x[k-1]<<endl;

    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define MAX 100000
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

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


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

int main() {
  
  int N;
  cin >> N;
  
  vector<int> A(N);
  for(int i=0; i<N; i++){
    cin >> A.at(i);
  }
  
  sort(A.begin(), A.end());
  
  int ans = 0;
  
  ans = A.at(N-1) - A.at(0);
  
  cout << ans << endl;
  
}


Measured memory_bytes: 3620
import java.util.Scanner;

public class Main{
  static int n;
  static long s;
  static long[] t;

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    n = sc.nextInt();
    s = sc.nextInt();
    t = new long[n];
    for(int i = 0; i < n; i++){
      t[i] = sc.nextInt();
    }

    long sum = 0;
    long time = t[0];
    for(int i = 0; i < n; i++){
      if(t[i] >= time){
        sum += s;
      }
      else{
        sum += (t[i] + s) - time;
      }
      time = t[i] + s;
    }

    System.out.println(sum);
  }
}


Measured memory_bytes: 87316
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <typename T> bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    int H, W;
    cin >> H >> W;
    const int dx[4] = {1, 0, -1, 0};
    const int dy[4] = {0, 1, 0, -1};

    vector<vector<char>> m(H, vector<char>(W));
    rep(i, H) rep(j, W) cin >> m.at(i).at(j);

    vector<vector<int>> dist(H, vector<int>(W, -1));

    queue<pair<int, int>> que;
    int max = -1;
    rep(i, H) {
        rep(j, W) {
            if(m.at(i).at(j) == '#') continue;
            dist.assign(H, vector<int>(W, -1));
            dist.at(i).at(j) = 0;
            que.push(make_pair(i, j));

            while(!que.empty()) {
                pair<int, int> current_pos = que.front();
                int y = current_pos.first;
                int x = current_pos.second;
                que.pop();

                rep(di, 4) {
                    int nx = x + dx[di];
                    int ny = y + dy[di];
                    if(nx < 0 || nx >= W || ny < 0 || ny >= H) continue;
                    if(m.at(ny).at(nx) == '#') continue;

                    if(dist.at(ny).at(nx) == -1) {
                        que.push(make_pair(ny, nx));
                        dist.at(ny).at(nx) = dist.at(y).at(x) + 1;
                        chmax(max, dist.at(y).at(x) + 1);
                    }
                }
            }
        }
    }
    cout << max << endl;
}

Measured memory_bytes: 3592
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  string str;
  cin >> str;
  int q,i;
  cin >> q;
  string s1,s2;
  int a,b;
  for(i=0;i<q;i++){
    //cout << str << endl;
    cin >> s1 >> a >> b;
    if(s1=="print"){
      cout << str.substr(a,b-a+1) << endl;
    }else if(s1=="reverse"){
      string s3=str.substr(a,b-a+1);
      reverse(s3.begin(),s3.end());
      str=str.substr(0,a)+s3+str.substr(b+1,str.size()-a-1);
    }else{
      cin >> s2;
      str=str.substr(0,a)+s2+str.substr(b+1,str.size()-a-1);
    }
  }
}



Measured memory_bytes: 3196
s = gets.chomp
for i in 1...s.length
    k = s.slice(0...(s.length-i))
    if k.length % 2 == 0
        if k.slice(0, k.length/2) == k.slice(k.length/2, k.length/2)
            print(s.length - i)
            exit()
        end
    end
end

Measured memory_bytes: 1788
N = int(input())
t0, x0, y0 = 0, 0, 0
for _ in range(N):
    t, x, y = map(int, input().split())
    dt = t - t0
    dx = x - x0
    dy = y - y0
    if dt < dx + dy:
        print("No")
        exit()
    if (dx + dy - dt) % 2 != 0:
        print("No")
        exit()
    t0, x0, y0 = t, x, y
print("Yes")


Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <utility>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <vector>
#include <limits.h>
#include <math.h>
#define ll long long

using namespace std;
ll k, n;
int main(void)
{
        while (scanf("%lld", &k) == 1)
        {
                n = 50;
                printf("%lld\n", n);
                ll a = k / n, b = k%n;
                int cot = 0;
                for (ll i = 1; i <= b; i++)
                {
                        cot++;
                        cout << 49 + a + 50 - (b - 1) << (cot == n ? '\n' : ' ');
                }
                for (ll i = 1; i <= (n - b); i++)
                {
                        cot++;
                        cout << 49 + a - b << (cot == n ? '\n' : ' ');
                }
        }
        return false;

        return false;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N; cin >> N;
    int a = sqrt(2 * N);
    int b = a + 1;
    set<int> res;

    int cnt = 0;
    for (int i = 1; i <= b; i++) {
        cnt +=i;
        res.emplace(i);
    }
    if (cnt - N >= b) {
        cnt -= b;
        res.erase(b);
    }
    if (cnt - N > 0) {
        int n = cnt - N;
        res.erase(n);
    }
    for (auto x : res) {
        cout << x << endl;
    }
}


Measured memory_bytes: 3748
#include <iostream>

#define SIZE 200010

int main() {
    int k, n, m=-1;
    int a[SIZE];
    std::cin >> k >> n;
    for (int i=0; i<n; ++i) std::cin >> a[i];
    m = a[0] + k - a[n-1];
    for (int i=1; i<n; ++i) m = std::max(m, a[i] - a[i-1]);

    std::cout << k - m << std::endl;

    return 0;
}

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

int main()
{
    char ch[3];
    cin>>ch;

    if(ch[0]=='S')
        {
            if(ch[1]=='U')cout<<"7"<<endl;
            else cout<<"1"<<endl;
        }
    else if(ch[0]=='T')
        {
            if(ch[1]=='U')cout<<"5"<<endl;
            else cout<<"3"<<endl;
        }
    else if(ch[0]=='M')cout<<"6"<<endl;
    else if(ch[0]=='W')cout<<"4"<<endl;
    else cout<<"2"<<endl;

    return 0;
}


Measured memory_bytes: 3640
// ABC160
// a.cs

using System;

class A
{
    public static void Main()
    {
        string str = Console.ReadLine();

        if (str[2] == str[3] && str[4] == str[5])
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 13140
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define prints(x, y) cout<<(x)<<" "<<(y)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define r_rep(i, n) for(int i = n; i >= 0; i--)
#define ll long long int
#define pb push_back

const long long INF = 1LL << 60;

int main() {
  string s;
  cin >> s;
  int start, end;
  rep(i, s.size()){
    if(s[i] == 'A'){
      start = i;
      break;
    }
  }

  r_rep(i, s.size()){
    if(s[i] == 'Z'){
      end = i;
      break;
    }
  }
  print(end - start + 1);

}


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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    cout << n*n*n << endl;
    return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = (a); i < (b); i++)
using ll = long long;
using ull = unsigned long long;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ull> vul;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<ll>> vvl;
typedef vector<vector<string>> vvs;
typedef vector<vector<ull>> vvul;
typedef vector<bool> vb;
const ll md = 998244353;

ll add(ll a, ll b, ll mod = md) {
    return (a%mod + b%mod + mod)%mod;
}

ll mul(ll a, ll b, ll mod = md) {
    return ((a%mod) * (b%mod))%mod;
}

ll C(vl &fact, vl &invfact, ll n, ll r, ll mod = md) {
    if(r == 0) return 1;
    return mul(fact[n], mul(invfact[r], invfact[n-r], mod), mod);
}

ll power(ll x, ll n, ll mod = md) {
    ll res = 1;
    x %= mod;
    while (n) {
        if (n & 1)  res = (res*x)%mod;
        n = (n >> 1);
        x = (x*x)%mod;
    }
    res %= mod;
    return res;
}

void cachefact(vector<ll>& fac, vector<ll> &ifac, ll bound, ll mod = md) {
	fac[0] = 1;
	ifac[0] = power(1, mod-2)%mod;
	for(ll i = 1; i <= bound; i++) {
		fac[i] = (fac[i-1] % mod * i % mod)%mod;
		ifac[i] = power(fac[i], mod-2)%mod;
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, k;
	cin >> n >> k;
	vector<ll> a(n);
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll sum = 0;
	sort(a.begin(), a.end());
	for(int i = 0; i < k; i++) {
		sum += a[i];
	}
	cout << sum << "\n";
	return 0;
}

Measured memory_bytes: 3648
S=input()
N=len(S)

K1=[0 for i in range(N)]
K2=[0 for i in range(N)]

for i in range(N):
    if i==0:
        K1[i]=1
        K2[i]=0
    elif i==1:
        K1[i]=2 if S[0]!=S[1] else 0
        K2[i]=1
    elif i==2:
        K1[i]=max(K1[1]+1 if S[1]!=S[2] else 0,2)
        K2[i]=2
    else:
        K1[i]=max(K1[i-1]+1 if S[i-1]!=S[i] else 0,K2[i-1]+1)
        K2[i]=max(K1[i-2]+1,K2[i-2]+1 if S[i-3:i-1]!=S[i-1:i+1] else 0)

print(max(K1[N-1],K2[N-1]))

Measured memory_bytes: 19356
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  if(A+B>C+D){
    cout << "Left" << endl;
  }
  if(A+B==C+D){
    cout << "Balanced" << endl;
  }
  if(A+B<C+D){
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
 int A, B, C;
  cin >> A >> B >> C;
  if (A == 7 && B == 5 && C == 5)
    cout << "YES" << endl;
  else if (B == 7 && A == 5 && C == 5)
    cout << "YES" << endl;
  else if (C == 7 && A == 5 && B == 5)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
return 0;
}


Measured memory_bytes: 3556
#include <iostream>
using namespace std;
int n;
int main()
{
	cin >> n;
	int i,a[1000],b[1000],c[1000],x[1000],y[1000],z[1000],res[1000];
	for (i = 0; i < n; i++) {
		cin >> a[i] >> b[i] >> c[i];
		x[i] = a[i];
		if (x[i] < b[i]) {
			y[i] = x[i];
			x[i] = b[i];
		}
		else {
			y[i] = b[i];
		}
		if (x[i] < c[i]) {
			z[i] = y[i];
			y[i] = x[i];
			x[i] = c[i];
		}
		else if (y[i] < c[i]) {
			z[i] = y[i];
			y[i] = c[i];
		}
		else {
			z[i] = c[i];
		}
	}
	for (i = 0; i < n; i++) {
		res[i] = x[i] * x[i] - z[i] * z[i] - y[i] * y[i];
		if (res[i] == 0) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1172
from math import factorial


def main(a, b):
    ans = 0

    if a >= 2:
        ans += calc(a)
    if b >= 2:
        ans += calc(b)

    print(ans)


def calc(a):
    return factorial(a) // factorial(2) // factorial(a - 2)


if __name__ == "__main__":
    a, b = map(int, input().split())

    main(a, b)


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

int main() {
    int n, d[60];
    cin >> n;
    for (int i=0;i<n;i++) cin >> d[i];
    int ans = 0;
    for (int i=0;i<n;i++) {
        for (int j=i+1;j<n;j++) {
            ans += d[i] * d[j];
        }
    }
    
    cout << ans << endl;
}

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

typedef long long ll;
#define PI 3.1415926535897932384626433
#define mod 1000000007

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

int lcm(int a, int b) { return a * b / gcd(a, b); }

int main(){
    ll x, y;
    cin >> x >> y;
    if(x % y == 0){
        cout << -1 << endl;
        return 0;
    }
    cout << x << endl;
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <climits>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int n, m;

int main() {
    //cout << fixed << setprecision(15);
    LL r, D, x;
    cin >> r >> D >> x;

    for(int i=0; i<10; ++i){
        x = r*x-D;
        cout << x << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
#define pb push_back
using namespace std;

string s, t;
int c, pre = -1;
vector<int> f[128];

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> s >> t;
    for (int i = 0; i < s.size(); ++i)
        f[s[i]].pb(i);
    for (int i = 0; i < t.size(); ++i) {
        if (f[t[i]].empty()) return cout << "-1\n", 0;
        auto h = upper_bound(f[t[i]].begin(), f[t[i]].end(), pre);
        if (h == f[t[i]].end()) {
            h = f[t[i]].begin();
            ++c;
        }
        pre = *h;
    }
    cout << 1ll * c * s.size() + pre + 1 << '\n';
}

Measured memory_bytes: 1228
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int a[] = new int[n];

		int count[] = new int[1_00001];
		long sum = 0;
		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt();
			count[a[i]] ++;
			sum += a[i];
		}

		int q = sc.nextInt();

		for(int i = 0; i < q; i++){
			int b = sc.nextInt();
			int c = sc.nextInt();

			sum += (long)(c - b)*count[b];
			count[c] += count[b];
			count[b] = 0;

			System.out.println(sum);
		}

//		long sum = 0;
//		for(int i = 0; i < 1_00001; i++){
//			sum += (long)count[i]*i;
//		}
//
//		System.out.println(sum);
	}
}


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

bool contains(const set<int> &s, int x){
    return *s.find(x) != *s.end();
}
int main(){
    int n,d;
    cin >> n >> d;
    vector<vector<int>> x(n,vector<int>(d));
    for(auto &&v : x){
        for (auto &&e : v)
        {
            cin >> e;  
        }
    }
    int ans =0;
    set<int> hoge = {1,4,9,16,25,36,49,64,81,100,121,144,169,196,225,256,289,324,361,400,441,484,529,576,625,676,729,784,841,900,961,1024,1089,1156,1225,1296,1369,1444,1521,1600,1681,1764,1849,1936,2025,2116,2209,2304,2401,2500,2601,2704,2809,2916,3025,3136,3249,3364,3481,3600,3721,3844,3969,4096,4225,4356,4489,4624,4761,4900,5041,5184,5329,5476,5625,5776,5929,6084,6241,6400,6561,6724,6889,7056,7225,7396,7569,7744,7921,8100,8281,8464,8649,8836,9025,9216,9409,9604,9801,10000,10201,10404,10609,10816,11025,11236,11449,11664,11881,12100,12321,12544,12769,12996,13225,13456,13689,13924,14161,14400,14641,14884,15129,15376,15625,15876,16129,16384,16641,16900,17161,17424,17689};
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < i; j++)
        {
          	int dis2=0;
            for (size_t k = 0; k < d; k++)
            {
              	
                dis2 += (x.at(i).at(k) - x.at(j).at(k)) * (x.at(i).at(k) - x.at(j).at(k));
            }
            
            if(contains(hoge,dis2)){
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256