akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>

using namespace std;

int memo[21];
int m;

void mlen(int d[10][10],int ns, int s,int c, int mem[],int dep){
	bool last = true;
	mem[dep] = s;
	for(int i = 0; i < ns; i++){
		if(d[s][i] != 0){
			int _d = d[s][i];
			d[s][i] = d[i][s] = 0;
			mlen(d,ns,i,c+_d,mem,dep+1);
			d[s][i] = d[i][s] = _d;
			last = false;
		}
	}
	if(last && m < c){
		for(int i = 0; i < 21; i++){
			if(i <= dep) memo[i] = mem[i];
			else memo[i] = -1;
		}
		m = c;
	}
}

int main(){
	int ns,nl;
	cin >> ns>> nl;
	while(ns){
		int d[10][10];
		memset(d,0,sizeof d);
		for(int i = 0; i < 21; i++) memo[i] = -1;
		for(int i = 0; i < nl; i++){
			int a,b,c;
			cin >> a >> b >> c;
			a--;
			b--;
			d[a][b] = d[b][a] = c;
		}
		m = 0;
		int mem[10] = {0};
		for(int i = 0; i < ns; i++){
			mlen(d,ns,i,0,mem,0);
		}
		cout << m << endl;
		for(int i = 0; i < 21; i++){
			if(i < 20 && memo[i+1] > -1) cout << memo[i]+1 << " ";
			else if(memo[i] > -1) cout << memo[i]+1;
		}
		cout << endl;
		cin >> ns >> nl;
	}
}

Measured memory_bytes: 0
import java.io.PrintWriter;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int sx = sc.nextInt();
		int sy = sc.nextInt();
		int tx = sc.nextInt();
		int ty = sc.nextInt();
		int w = tx - sx;
		int h = ty - sy;
		int[] c = {h,w,h,w,1,h+1,w+1,1,1,h+1,w+1,1};
		String[] s = {"U","R","D","L","L","U","R","D","R","D","L","U"};
		for(int i=0;i<12;i++) {
			for(int j=0;j<c[i];j++) {
				out.print(s[i]);
			}
		}
		out.flush();
	}

}

Measured memory_bytes: 21332
#include <iostream>

using namespace std;

int C[2][200];

int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < 2*n; i++)
    C[0][i] = i+1;
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    if (!k)
      for (int j = 0; j < n; j++) {
        C[(i+1)%2][2*j] = C[i%2][j];
        C[(i+1)%2][2*j+1] = C[i%2][n+j];
      }
    else {
      for (int j = 0; j < k; j++)
        C[(i+1)%2][2*n-k+j] = C[i%2][j];
      for (int j = k; j < 2*n; j++)
        C[(i+1)%2][j-k] = C[i%2][j];
    }
  }
  for (int i = 0; i < 2*n; i++)
    cout << C[m%2][i] << endl;
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIL pair<int,LL>
#define PLI pair<LL,int>
#define PIII pair<int,PII>
#define PLL pair<LL,LL>
#define PLII pair<LL,PII>
#define VI vector<int>
#define VVI vector<VI>
#define VL vector<LL>
#define VVL vector<VL>
#define VPII vector<PII>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define all(x) x.begin(),x.end()
#define watch(x) cout<<(#x)<<" = "<<(x)<<'\n'
#define mset(a,v) memset(a,v,sizeof(a))
#define setp(x) cout<<fixed<<setprecision(x)
#define EPS 0.00000000001
#define PI acos(-1)
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

const int MOD = 1e9 + 7;
const LL MX = 3010;
const LL INF = 1e9;

LL v[MX][MX], mem[MX][MX][4];
int n,m;

void dp(int i, int j, int f)
{
    if(i != n-1 && mem[i+1][j][0] == -1) dp(i+1,j,0);
    int f1 = min(3,f+1);
    if(j != m-1 && mem[i][j+1][f1] == -1) dp(i,j+1,f1);
    if(j != m-1 && mem[i][j+1][f] == -1) dp(i,j+1,f);

    LL ans1 = 0;
    if(f != 3) ans1 = v[i][j];
    LL ans = ans1;

    if(i != n-1) ans = ans1 + mem[i+1][j][0];

    if(j != m-1)
    {
        ans = max(ans,ans1 + mem[i][j+1][f1]);
        ans = max(ans,mem[i][j+1][f]);
    }

    mem[i][j][f] = ans;
}

int main()
{
    //ofstream out("output.txt");
    //ifstream in("input.txt");
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int k;
    cin>>n>>m>>k;
    int x,y;
    LL a;

    mset(v,0);
    loop(i,0,k)
    {
        cin>>x>>y>>a;
        v[x-1][y-1] = a;
    }

    mset(mem,-1);
    dp(0,0,0);
    cout<<mem[0][0][0]<<'\n';

    /*
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int a[n];
        loop(i,0,n)
        {
            cin>>a[i];
        }
    }
    */

    /*
    int n;
    cin>>n;
    int a[n];
    loop(i,0,n)
    {
        cin>>a[i];
    }
    */

    /*
    cout<<ans<<'\n';

    if(f) cout<<"YES\n";
    else cout<<"NO\n";

    if(f) cout<<"Yes\n";
    else cout<<"No\n";
    */

    return 0;
}


Measured memory_bytes: 358052
def main():
    N, A, B = map(int, input().split())
    S = input()
    for c in S:
        if c == "a":
            if A + B > 0:
                print("Yes")
                A -= 1
                continue
        elif c == "b":
            if A + B > 0 and B > 0:
                print("Yes")
                B -= 1
                continue
        print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 51800
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string n; cin >> n;
    // 0: ぴったり 1: 多め
    vvll dp(2, vll(n.size() + 2, HIGHINF));
    dp[0][0] = 0;
    for (int i = 0; i < n.size(); i++) {
        dp[0][i + 1] = min(dp[0][i], dp[1][i]) + n[i] - '0';
        dp[1][i + 1] = min(dp[0][i] + 1 + 10 - (n[i] - '0'), dp[1][i] + 10 - (n[i] - '0' + 1));
    }

    cout << min(dp[0][n.size()], dp[1][n.size()]) << '\n';
    return 0;
}


Measured memory_bytes: 24860
#include <iostream>
#include <cstdio>
#include <climits>
#define MAX 4000000
#define INF INT_MAX
using namespace std;

int D[MAX]; // segment tree elements num: 2n-1
int n = 1;

void initRMQ(int n_){
    while(n < n_) n *= 2; // 配列のサイズは 2のべき乗個(要素数=~A)
    for(int i = 0; i < 2*n-1; i++){ // initialization, segment tree elements num = 2n-1
        D[i] = INF;
    }
}
// 指定範囲:[a,b), k:index of segment tree, 
int query(int a, int b, int k, int l, int r){
    if(r <= a || b <= l) return INF;
    if(a <= l && r <= b) return D[k];

    // otherwise
    int vleft, vright;
    vleft = query(a,b,2*k+1,l,(l+r)/2);
    vright = query(a,b,2*k+2,(l+r)/2,r);
    return min(vleft,vright); 
}

int findMin(int a, int b){ //区間[a,b]で最小値を返す
    return query(a,b+1,0,0,n);
}

void update(int k, int a){ // a_kを更新
    k += n-1;
    D[k] = a;
    while(k > 0){
        k = (k-1)/2;
        D[k] = min(D[2*k+1],D[2*k+2]);
    }
}

int main(){
    int i;
    int n_, l, a;
    cin >> n_ >> l; // n_: elements num
    initRMQ(n_);

    for(int i = 0; i < n_; i++){
        cin >> a;
        update(i,a);
    }
   
    for(i = 0; i < n_-l; i++){
        cout << findMin(i,i+l-1) << " ";
    }
    cout << findMin(i,i+l) << endl;
    return 0;
}


Measured memory_bytes: 11288
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _165A
{
    class Program
    {
        static void Main(string[] args)
        {
            long K = long.Parse(Console.ReadLine());
            long[] AB = Console.ReadLine().Split(' ').Select(tmp => long.Parse(tmp)).ToArray();

            for (var i = AB[0]; i < AB[1]+1; i++)
            {
                if (i % K == 0)
                {
                    Console.WriteLine("OK");
                    return;
                }
            }
            Console.WriteLine("NG");

        }
    }   
}


Measured memory_bytes: 28164
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n;
    vector<long long> a;
    long long const mod = 1000000007;
    long long ans = 0;
    cin >> n;
    a.assign(n, 0);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(long long k=0;k<60;k++){
        long long b = 0;
        for(int i=0;i<n;i++){
            if(((a[i]>>k)&1)==1) b++;
        }
        ans += (1LL<<k) % mod * b % mod * (n-b) % mod;
        ans %= mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    int k = 0;
    rep(i,n) {
        cin >> a[i];
        k ^= a[i];
    }
    rep(i,n) {
        cout << (k^a[i]) << endl;;
    }
}


Measured memory_bytes: 4048
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
    int n, m,k,a,b;
    int maxcnt = 0,tmpcnt=0;
    cin >> n >> m >> k;
    vector<ll>booka, bookb;
    vector<ll>bookasum(n+1,0), bookbsum(m+1,0);
    rep(i, n) {
        cin >> a;
        booka.push_back(a);
        bookasum[i + 1] = a + bookasum[i];
    }

    rep(i, m) {
        cin >> b;
        bookb.push_back(b);
        bookbsum[i + 1] = b + bookbsum[i];
    }
    for (int i = 0;i <= n;i++) {
        if (bookasum[i] > k)break;
        auto itr = upper_bound(all(bookbsum), k - bookasum[i]);
        tmpcnt = itr - bookbsum.begin();
        if (bookbsum.begin() != itr)tmpcnt--;
        //maxcnt = max(maxcnt, int(i + itr - bookbsum.begin()));
        maxcnt = max(maxcnt, int(i + tmpcnt));
    }

    cout << maxcnt << endl;
    return 0;

}


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

signed main()
{
    int a, b, c, k, cnt;
    cin >> a >> b >> c >> k;
    cnt = 0;
    
    while(a >= b){
        b *= 2;
        cnt++;
    }
    while(b >= c){
        c *= 2;
        cnt++;
    }
    
    if(cnt > k){
        cout << "No\n";
    } else {
        cout << "Yes\n";
    }
    return (0);
}

Measured memory_bytes: 3628
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
typedef long long int lli;
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<pll> vop;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define REP(i,a,b) for( long long i=a;i<b;i++)
#define REPR(i,a,b) for(long long i=a;i>=b;i--)
#define adb(a) for(auto ii:a) cout << ii << " "; cout << endl
#define adp(a) for(auto ii:a) cout << ii.F << " " << ii.S << endl;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define endl "\n"
#define mem(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define PI 3.14159265358979323846
const ll MAXN = 100007;
const ll p = 1000000007;
#define N 100003
#define INF INTMAX_MAX

struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1> {}(p.first);
        auto hash2 = hash<T2> {}(p.second);
        return hash1 ^ hash2;
    }
};

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

ll power(ll a, ll b, ll m) { ll ans = 1; a = a % m; while (b) { if (b & 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans; }

ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); }

ll modInverse(ll a, ll m) { ll g = __gcd(a, m); return power(a, m - 2, m); }

bool cmp(const pll &a, const pll &b)
{
    if (a.F != b.F) {
        return a.F > b.F;
    }
    else
        return a.S < b.S;
}

// bool check(ll i, ll j)
// {
//     if (i >= 0 && i < n && j >= 0 && j < m && a[i][j] != '#')
//         return true;
//     return false;
// }


int main()
{


    fastIO;
    int test = 1, num = 1;
    //cin >> test;
    while (test--)
    {
        ll n;
        cin >> n;
        ll a[n];
        ll sum = 0;
        REP(i, 0, n)
        {
            cin >> a[i];
            sum += a[i];
            sum %= mod;
        }
        sum = ((sum - a[0]) % mod + mod) % mod;
        ll ans = 0;
        REP(i, 0, n)
        {
            ll x = (a[i] % mod * sum % mod) % mod;
            ans = (ans + x) % mod;
            sum = ((sum - a[i + 1]) % mod + mod) % mod;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 5176
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>

int main(){
    std::string s;
    std::cin>>s;
    char t='0';
    for(size_t i = 0; i < s.size(); i++){
        if(s[i]==t){
            std::cout<<i<<" "<<i+1<<std::endl;
            return 0;
        }
        t=s[i];
    }
    for(size_t i = 0; i+2 < s.size(); i++){
        if(s[i]==s[i+2]){
            std::cout<<i+1<<" "<<i+3<<std::endl;
            return 0;
        }    
    }
    std::cout<<"-1 -1"<<std::endl;
    return 0;
}

Measured memory_bytes: 512
s = input()
i1 = int(s[0:2])
i2 = int(s[2:4])
if i1 >= 1 and i1 <= 12 and i2 >= 1 and i2 <= 12:
  print('AMBIGUOUS')
elif i1 >= 1 and i1 <= 12:
  print('MMYY')
elif i2 >= 1 and i2 <= 12:
  print('YYMM')
else:
  print('NA')


Measured memory_bytes: 2940
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <stdio.h>
#include <cmath>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);

/*int dxy[5] = {0, 1, 0, -1, 0};
  assign
*/
bool eq(long double a, long double b)
{
    return ( -EPS < a-b && a-b < EPS );
}

 
signed main()
{
    Int(n);

    while (n) {
        vi in(n);
        rep(i, n) {
            cin >> in[i];
        }
        long double min = 1001000.0;
        int anss = 0, ansa = 0, ansc = 0;
        rep(s, 16) {
            rep(a, 16) {
                rep(c, 16) {
                    vi ex(256, 0);
                    int r = s;
                    rep(i, n) {
                        r = (a * r + c) % 256;
                        ex[(r + in[i]) % 256]++;
                    }
                    long double ret = 0.0;
                    rep(i, 256) {
                        long double d = (long double)ex[i] / (long double)n;
                        if (eq(d, 0.0)) {
                            continue;
                        } else {
                            ret -= d * log(d);
                        }
                    }
                    if (ret < min - EPS) {
                        min = ret;
                        anss = s;
                        ansa = a;
                        ansc = c;
                    }
                }
            }
        }
        cout << anss << " " << ansa << " " << ansc << endl;
        cin >> n;
    }

    return 0;
}

Measured memory_bytes: 3264
#include<bits/stdc++.h>
#define ll unsigned long long
#define pp pair<int,int>
#define ppn pair<pp,int>
#define F first
#define S second
#define N 1000005
#define mod 1000000007


using namespace std;



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


    int n;
    cin>>n;
    cout<<(n>=30?"Yes":"No")<<endl;
}


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

#define int long long 

int mat[22][22];

int dp[(1<<22)];

const int mod=1e9+7;

int n;

void add_self(int& a, int b) {
    a += b;
    if(a >= mod) {
        a -= mod;
    }
}

int f(int mask){
	if(mask==((1<<n)-1)){
		return 1;
	}
	int &res=dp[mask];
	if(res!=-1){
		return res;
	}
	res=0;
	
	int cnt=__builtin_popcount(mask);
	for(int i=0;i<n;i++){
		if(mat[cnt][i] and !(mask&(1<<i))){
			add_self(res,f(mask^(1<<i)));
		}
	}

	return res;
}

signed main(){

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

	memset(dp,-1,sizeof dp);

	cout<<f(0)<<endl;

}

Measured memory_bytes: 33024
#include<stdio.h>
int main()
{
	int tc;
	scanf("%d",&tc);
	int A,B;
	scanf("%d %d",&A,&B);
	int flag = 1;
	for(int i = A;i<=B;i++)
	{
		if(i % tc == 0)
		{
			flag = 0;
			break;
		}
	}
	(flag) ? printf("NG\n") : printf("OK\n");
}

Measured memory_bytes: 2064
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a, b, c, K, sum;
    cin >> a >> b  >> c >> K;

    sum = 0;
    int i = 0;
    for (;i < a && i < K; i++) {
        sum++;
    }

    int iii = 0;
    for (;iii < c && i + b + iii < K; iii++) {
        sum += -1;
    }

    cout << sum << endl;

    return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        var inputs = ReadInts();
        Console.WriteLine(inputs[0] * inputs[1] / 2);
    }

    public static string Read() { return Console.ReadLine(); }
    public static int ReadInt() { return int.Parse(Read()); }
    public static long ReadLong() { return long.Parse(Read()); }
    public static double ReadDouble() { return double.Parse(Read()); }

    public static string[] Reads() { return Console.ReadLine().Split(' '); }
    public static int[] ReadInts() { return Reads().Select(_ => int.Parse(_)).ToArray(); }
    public static long[] ReadLongs() { return Reads().Select(_ => long.Parse(_)).ToArray(); }
    public static double[] ReadDoubles() { return Reads().Select(_ => double.Parse(_)).ToArray(); }
}



Measured memory_bytes: 13268
import sys
sys.setrecursionlimit(20000000)
n=int(input())
h=list(map(int,input().split()))
memory={}
def cost(place):
    if place in memory:
        return memory[place]
    if place==n-1:
        return 0
    if place==n-2:
        return abs(h[n-2]-h[n-1])
    if place<=n-3:
        a=abs(h[place]-h[place+2])+cost(place+2)
        b=abs(h[place]-h[place+1])+cost(place+1)
        x=min(a,b)
        memory[place]=x
        return x
print(cost(0))


Measured memory_bytes: 61748
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <numeric>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1e9+7
#define pb push_back
#define MP make_pair
typedef long long int ll;
typedef std::pair<int,int> P;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;
int main() {
    int n; cin>>n;
    int f[100][14],p[100][15];
    rep(i,0,n)rep(j,0,10)cin>>f[i][j];
    rep(i,0,n)rep(j,0,11)cin>>p[i][j];
    int ans=-INF;
    rep(b,1,1<<10){
        int cc=0;
        rep(i,0,n){
            int c=0;
            rep(j,0,10){
                if((b>>j&1)&&f[i][j])c++;
            }
            cc+=p[i][c];
        }
        if(ans<cc)ans=cc;
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())  # 項数N, Aの和M

if N == 1:
    print(M)
    exit()

# Mの約数を列挙する
divs = []
ans = 1


for i in range(1, int(M**(1/2))+2):
    if M % i == 0:
        divs.append(i)
        divs.append(M//i)

# print(divs)
# 約数が全て手に入った
for d in divs:
    if M >= N * d:
        ans = max(ans, d)

print(ans)


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

int main(){
  int N,a,b,c,d;
  cin >> N;
  a = N/1000;
  b = (N-a*1000)/100;
  c = (N-a*1000-b*100)/10;
  d = (N-a*1000-b*100-c*10);
  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;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

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

const int MOD = 1e9+7;
const int INF = 1e9;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,K;
    cin>>N>>K;
    vector<ll> h(N);
    rep(i,N)cin>>h[i];
    int ans = 0;
    rep(i,N){
        if(h[i]>=K)ans++;
    }    
    cout<<ans<<endl;

}

Measured memory_bytes: 1024
int K, nyan = 7;
main(){
	scanf("%d", &K);
	if(K%2==0 || K%5==0){
		puts("-1");
		return 0;
	}
	for(int i=1; i<=K; i++){
		if(nyan%K==0){
			printf("%d\n", i);
			return 0;
		}
		nyan = (10*nyan+7) % K;
	}
	puts("-1");
	return 0;
}

Measured memory_bytes: 1724
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;

int main(){
    int n, t, a;
    cin >> n >> t >> a;
    
    vector<int> h(n);

    for (int i = 0; i < h.size(); i++){
        cin >> h[i];
    }

    double min_sub = 1000000;
    int ans = 0;

    for (int i = 0; i < h.size(); i++){
        double sub = fabs(a - (t - h[i] * 0.006));
        if (sub < min_sub){
            min_sub = sub;
            ans = i + 1;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;
const int MAX_N = 2e6;
int main(){
  //階乗、逆元、階乗の逆元 

 ll fact[MAX_N], inv[MAX_N], fact_inv[MAX_N];
  fact[1] = inv[1] = fact_inv[1] = 1;
  fact[0] = inv[0] = fact_inv[0] = 1;
  for (int i = 2; i < MAX_N; i++) {
      fact[i] = fact[i - 1] * i % MOD;
      inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
      fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
  }
  ll p25[MAX_N], p26[MAX_N];
  p25[0] = p26[0] = 1;
  for(int i = 1; i < MAX_N; i++){
    p25[i] = (p25[i-1] * 25)%MOD;
    p26[i] = (p26[i-1] * 26)%MOD;
  }
  ll k;
  cin >> k;
  string s;
  cin >> s;
  ll n = s.size();
  ll ans = 0;
  for(ll i = 0; i <= k; i++){
    ll res = (fact[n+i-1] * fact_inv[n-1])%MOD;
    res = (res * fact_inv[i])%MOD;
    res = (res * p26[k-i])%MOD;
    res = (res * p25[i])%MOD;
    ans = (ans + res)%MOD;
  }
  cout << ans <<endl;
}

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

class Solver {
  public:
    bool solve() {
        int H, W; cin >> H >> W;
        vector<string> G(H); cin >> G;
        ll ans = 0;
        vector<vector<int>> visited(H, vector<int>(W));
        rep(h, H) rep(w, W) {
            if(not visited[h][w]) {
                visited[h][w] = true;
                // cerr << endl;
                int dots = 0;
                int sharp = 0;
                queue<pii> que;
                que.emplace(h, w);
                while(que.size()) {
                    pii p = que.front(); que.pop();
                    int y = p.first;
                    int x = p.second;
                    // cerr << y << "," << x << endl;
                    (G[y][x] == '.' ? dots : sharp)++;
                    rep(i, 4) {
                        int ny = y + dy[i];
                        int nx = x + dx[i];
                        if(0 <= ny and ny < H and 0 <= nx and nx < W) {
                            if(G[y][x] != G[ny][nx]) {
                                if(not visited[ny][nx]) {
                                    visited[ny][nx] = true;
                                    que.emplace(ny, nx);
                                }
                            }
                        }
                    }
                }
                // cerr << " > " << dots << "," << sharp << endl;
                ans += (ll)dots * sharp;
            }
        }
        cout << ans << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
int main() 
{
	int n;
	map<int,int> ss;
	cin>>n;
	int f[n+5];
	for(int i=1;i<=n;i++)
		cin>>f[i];
	for (int i=1;i<=n;i++) 
	{
		int x=i+f[i];
		ss[x]++;
	}
	long long ans=0;
	for (int i=1;i<=n;i++)
		ans+=ss[i-f[i]];
	cout<<ans<<endl;
}

Measured memory_bytes: 21420
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N,T=get_i
t=get_i
last=0
time=0
ans=0
t.each do|ti|
  if time.zero?
      last=ti
      time=ti+T
  elsif time>=ti
      time=ti+T
  else
      ans+=time-last
      time=ti+T
      last=ti
  end 
end
ans+=time-last
puts ans

Measured memory_bytes: 17932
a, b, c, k = map(int, input().split())

ans = 0

if 0 <= (k - a):
    ans += a
    k = k - a
    if 0 <= (k - b):
        k = k - b
        if 1 <= k:
            ans -= k
    else:
        k = k - b
        if 1 <= k:
            ans -= k
else:
    ans += k

print(ans)

Measured memory_bytes: 61676
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define ld long double
#define vi vector<vector<ll> >
using namespace std;
const int MOD=1000000007;
const int MOD2=998244353;
const ll MAX=9187201950435737471;
const int N=100005;
const int INF=1e9;
const long double PI=acos(-1);

map<ll,int>mp;

ll po(ll x,int y){
    ll res=1;
    for(int i=0;i<y;i++){
        res*=x;
        res%=MOD;
    }
    return res;
}

void f(int x){
    map<ll,int>s;
    for(int i=2;i*i<=x;i++){
        int tmp=0;
        while(x%i==0){
            tmp++;
            x/=i;
        }
        if(tmp){
            s[i]=tmp;
        }
    }
    if(x>=2){
        s[x]++;
    }
    for(auto i : s){
        mp[i.fi]=max(i.se,mp[i.fi]);
    }
}

void solve(int T){
    int l,r,d;
    cin>>l>>r>>d;
    int ans=0;
    for(int i=l;i<=r;i++){
        if(i%d==0)ans++;
    }
    cout<<ans<<"\n";
}

int main() {
    //fastio

    int T=1;
    //cin>>T;
    for(int i=1;i<=T;i++){
        solve(i);
        //if(i<T)cout<<"\n";
    }
    return 0;
}

/*
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define ld long double
#define vi vector<vector<ll> >
using namespace std;
const int MOD=1000000007;
const int MOD2=998244353;
const ll MAX=9187201950435737471;
const int N=100005;
const int INF=1e9;
const long double PI=acos(-1);

map<ll,int>mp;

ll po(ll x,int y){
    ll res=1;
    for(int i=0;i<y;i++){
        res*=x;
        res%=MOD;
    }
    return res;
}

void f(int x){
    map<ll,int>s;
    for(int i=2;i*i<=x;i++){
        int tmp=0;
        while(x%i==0){
            tmp++;
            x/=i;
        }
        if(tmp){
            s[i]=tmp;
        }
    }
    if(x>=2){
        s[x]++;
    }
    for(auto i : s){
        mp[i.fi]=max(i.se,mp[i.fi]);
    }
}

void solve(int T){
    int n;
    cin>>n;
    vector<int>a(n);
    cin>>a[0];
    ll x=a[0];
    for(int i=1;i<n;i++){
        cin>>a[i];
        f(a[i]);
    }
    ll ans=1;
    for(auto i:mp){
        ans=((ans%MOD) * (po(i.fi,i.se)%MOD))%MOD;
    }
    ll final_ans=0;
    for(int i=0;i<n;i++){
        final_ans+=(ans/a[i]);
        final_ans%=MOD;
    }
    cout<<final_ans<<"\n";
}

int main() {
    //fastio

    int T=1;
    //cin>>T;
    for(int i=1;i<=T;i++){
        solve(i);
        //if(i<T)cout<<"\n";
    }
    return 0;
}
*/


Measured memory_bytes: 3628
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> n >> s;
  if (n % 2 == 1)
    Cout("No");
  else {
    string co = "";
    rep(i, n / 2) co += s[i];
    rrep(i, n / 2, n) {
      if (s[i] == co[i - n / 2]) continue;
      Cout("No");
      return 0;
    }
    Cout("Yes");
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF (1<<28)
#define lp(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n,m,e,s,t,r;
  cin>>n>>m>>e>>s>>t>>r;
  vector<vector<int>> g(n);
  lp(i,m){
    int a,b;
    cin>>a>>b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<vector<int>> ch(e);
  int ex[10];
  lp(i,e){
    int a,b,c;
    cin>>b>>a>>c;
    ex[i]=c;
    ch[i]={a,b};
  }
  int dp[110][100][110];
  dp[0][0][0]=0;
  lp(i,110){
    lp(j,100){
      lp(k,110){
	dp[i][j][k]=INF;
      }
    }
  }
  queue<vector<int>> q;
  q.push({s,0,0,0});
  int ans=INF;
  while(!q.empty()){
    int now=q.front()[0];
    int cnt=q.front()[1];
    int bit=q.front()[2];
    int tr=q.front()[3];
    q.pop();
    if(tr>r) continue;
    if(dp[now][bit][tr]<cnt) continue;
    if(cnt>ans) continue;
    if(now==t){
      ans=min(cnt,ans);
      continue;
    }
    int trs=0;
    lp(i,e){
      if(now==ex[i]&&!(bit&(1<<i))){
	bit|=(1<<i);
	trs=1;
      }
    }
    //cout<<now<<" "<<bit<<endl;
    lp(i,g[now].size()){
      int next=g[now][i];
      if(dp[next][bit][tr]>cnt+1){
	dp[next][bit][tr]=cnt+1;
	q.push({next,cnt+1,bit,tr+1});
      }
    }
    lp(i,e){
      if(bit&(1<<i)){
	if(ch[i][0]==now){
	  int next=ch[i][1];
	  if(dp[next][bit][tr]>cnt+1){
	    dp[next][bit][tr]=cnt+1;
	    q.push({next,cnt+1,bit,tr+1});
	  }
	}
	if(ch[i][1]==now){
	  int next=ch[i][0];
	  if(dp[next][bit][tr]>cnt+1){
	    dp[next][bit][tr]=cnt+1;
	    q.push({next,cnt+1,bit,tr+1});
	  }
	}
      }
      if(trs==1){
	int next=s;
	if(dp[next][bit][tr]>cnt+1){
	  dp[next][bit][tr]=cnt+1;
	  q.push({next,cnt+1,bit,0});
	}
      }
    }
    
  }
  if(ans==INF) cout<<-1<<endl;
  else cout<<ans<<endl;
  
  return 0;
}



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

typedef long long ll;
ll k, a, b, s;
int main()
{
	cin >> k >> a >> b;
	b -= a;
	s = 1;
	if (1 < b && k >= a + 1) {
		k -= a + 1;
		s += a - 1 + b;
		if (2 < b) {
			s += k / 2 * b;
			k %= 2;
		}
	}
	s += k;
    cout << s << endl;
    return 0;
}

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

int main(){
    string s;
    cin >> s;
    int f, l;
    int ans=0;
    bool flag = false;
    rep(i,s.size()){
        if(s[i]=='A'&&!flag){
            f=i;
            flag = true;
        }
        else if(s[i]=='Z')l=i;
    }
    cout<<l-f+1<<endl;
}

Measured memory_bytes: 640
#include <set>
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <limits>
#include <map>
#include <numeric>

#define ll long long
using namespace std;
static ll imin = std::numeric_limits<ll>::min();
static ll imax = std::numeric_limits<ll>::max();
#define rep(i, n) for(int i = 0; i<n; ++i)
#define rep1(i, n) for(int i = 1; i<n; ++i)
#define rev_rep(i, n) for(int i = n - 1; i >= 0; --i)
#define range(a, i, b) for(int i = a; i <b; ++i)
#define dump(x) cout << #x << ":" << x << "\n";
#define all(v) v.begin(), v.end()
#define readll(N) ll N; cin >> N
#define readlv(N, vec) vector<ll> vec(N); rep(i, N){cin >> vec[i];}

template<class T1, class T2>
std::ostream& operator << (std::ostream& os, std::map<T1, T2>& mp);
template<class T1, class T2>
std::ostream& operator << (std::ostream& os, std::pair<T1, T2>& pair);
template<class T>
std::ostream& operator << (std::ostream& os, std::vector<T>& vec);
template<class T1, class T2>
std::ostream& operator << (std::ostream& os, std::pair<T1, T2>& pair){
  os << '(' << pair.first << ',' << pair.second << ')';
  return os;
}

template<class T>
std::ostream& operator << (std::ostream& os, std::vector<T>& vec){
  std::size_t n = vec.size();
  if(n == 0){
    return os;
  }
  os << " ";
  for(int i = 0; i<n - 1; ++i){
    os << vec[i] << " ";
  }
  os << vec[n - 1];
  os << std::endl;
  return os;
}

template<class T1, class T2>
std::ostream& operator << (std::ostream& os, std::map<T1, T2>& mp){
  std::size_t n = mp.size();
  if(n == 0){
    return os;
  }
  os << " ";
  for(auto && x:mp){
    os << x << " ";
  }
  os << std::endl;
  return os;
}

template<class T>
std::ostream& operator << (std::ostream& os, std::set<T>& mp){
  std::size_t n = mp.size();
  if(n == 0){
    return os;
  }
  os << " ";
  for(auto && x:mp){
    os << x << " ";
  }
  os << std::endl;
  return os;
}

#ifndef BOOST_TEST_MAIN
int main(int const argc, char const** argv){
  readll(N);
  readll(Y);
  rep(i, N + 1){
    range(0, j, N + 1){
      ll k = N - i - j;
      if(k<0){
        continue;
      }
      // dump(i);
      // dump(j);
      // dump(k);
      if(i * 10000 + j * 5000 + k * 1000 == Y){
        cout << i << " " << j << " " << k;
        return 0;
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1;
  return 0;
}
#endif


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <random>
#include <cstdint>
#include <bitset>
#include <iomanip>
#include <utility>
#include<map>
#include<functional>
#include<climits>
using namespace std;
using ll = long long;
const int mod = 1000000007;

int main() {
	double a, b;
	cin >> a >> b;
	cout <<setprecision(5)<< a / b << endl;
}

Measured memory_bytes: 256
def method_name(n, ps)
  cnt = 0
  ps.each_with_index do |v, i|
    cnt += 1 if v != i+1
    return "NO" if cnt > 2
  end
  return "NO" if cnt == 1
  return "YES"
end

n = gets.chomp.to_i
ps = gets.chomp.split(" ").map(&:to_i)
puts method_name(n, ps)

Measured memory_bytes: 3836
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio, std.bitmanip;
 
 
void main() {
    immutable int INF = 2^^30;
    alias Tuple!(int, "st", int, "company") Node;
    
    int N, M, p, q, c;
 
    scanf("%d %d", &N, &M);
    Node[][Node] adj;
    auto cs = new int[][](N);
    foreach (i; 0..M) {
        scanf("%d %d %d", &p, &q, &c);
        adj[Node(p-1, c)] ~= Node(q-1, c);
        adj[Node(q-1, c)] ~= Node(p-1, c);
    }

    foreach (n; adj.keys) {
        adj[n] ~= Node(n.st, 0);
        adj[Node(n.st, 0)] ~= n;
    }

    alias Tuple!(int, "to", int, "company", int, "cost") Route;
    auto queue = new BinaryHeap!(Array!Route, "a.cost > b.cost");

    int[Node] dist;
    foreach (n; adj.keys) {
        dist[n] = n.st == 0 ? 1 : INF;
        if (n.st == 0)
            queue.insert(Route(n.st, n.company, 1));
    }
 
    while(!queue.empty) {
        auto cur = queue.front;
        queue.removeFront;

        if (cur.cost > dist[Node(cur.to, cur.company)]) continue;
 
        foreach (next; adj[Node(cur.to, cur.company)]) {
            int fee = (next.company == 0) ? 1 : 0;
            if (cur.cost + fee >= dist[next]) continue;
            dist[next] = cur.cost + fee;
            queue.insert(Route(next.st, next.company, dist[next]));
        }
    }
 
    int ans = INF;
    foreach (n; adj.keys)
        if (n.st == N-1)
            ans = min(ans, dist[n]);
    writeln(ans == INF ? -1 : ans);
}


Measured memory_bytes: 150636
#include <vector>
#include <iostream>
#include <climits>
#include <functional>
using namespace std;

template <typename T>
struct SegmentTree{
private:
  using F = function<T(T,T)>;
  int n;
  F f;
  T ti;
  vector<T> dat;
public:
  SegmentTree(){};
  SegmentTree(F f,T ti) : f(f),ti(ti) {}
  void build(int n_){
    n = n_;
    dat.assign(2*n,ti);
  }
  void build(const vector<T> &v){
    int n_ = v.size();
    build(n_);
    for(int i = 0; i < n; ++i) dat[n+i]=v[i];
    for(int i = n-1; i >= 0; --i)
      dat[i]=f(dat[2*i+0],dat[2*i+1]);
  }
  void set_val(int k,T x){
    dat[k+=n] = x;
    while(k > 0){
      k = k/2;
      dat[k]=f(dat[2*k+0],dat[2*k+1]);
    }
  }
  T query(int a,int b){
    if(a == b) return ti;
    T vl = ti, vr = ti;
    for(int l = a+n, r = b+n; l < r; l >>= 1, r >>= 1){
      if(l&1) vl = f(vl,dat[l++]);
      if(r&1) vr = f(dat[--r],vr);
    }
    return f(vl,vr);
  }
};

// RMQ
// int main(){
//   int n, q;
//   cin >> n >> q;
//   SegmentTree<int> rmq([](int a, int b){return min(a,b);}, INT_MAX);
//   rmq.init(n);
//   while(q--){
//     int c, x, y;
//     cin >> c >> x >> y;
//     if(c){
//       cout << rmq.query(x,y+1) << endl;
//     }else{
//       rmq.set_val(x,y);
//     }
//   }
// }


// RSQ
int main(){
  int n, q;
  cin >> n >> q;
  using T = long long;
  SegmentTree<T> rsq([](T a, T b){return a+b;},0LL);
  rsq.build(n);
  while(q--){
    int c, x, y;
    cin >> c >> x >> y;
    if(c){
      --x,--y;
      cout << rsq.query(x,y+1) << endl;
    }else{
      --x;
      long long t = rsq.query(x,x+1);
      rsq.set_val(x,t+y);
    }
  }
}



Measured memory_bytes: 4364
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
 int n,m;
 cin>>n>>m;
 const int INF=1e9+7;
 vector<vector<char>> a(n,vector<char>(m));
 vector<vector<int>> d(n,vector<int>(m,INF));
 queue<pair<int,int>> q;
 for(int i=0;i<n;i++){
  for(int j=0;j<m;j++){
   cin>>a[i][j];
   if(a[i][j]=='#') {q.push({i,j});d[i][j]=0;}
  }
 }
 while(q.size()){
  pair<int,int> v=q.front();
  q.pop();
  int i=v.first;
  int j=v.second;
  if(i+1<n&&d[i+1][j]>d[i][j]+1){
   d[i+1][j]=d[i][j]+1;
   q.push({i+1,j});
  } 
  if(i-1>=0&&d[i-1][j]>d[i][j]+1){
   d[i-1][j]=d[i][j]+1;
   q.push({i-1,j});
  }
  if(j-1>=0&&d[i][j-1]>d[i][j]+1){
   d[i][j-1]=d[i][j]+1;
   q.push({i,j-1});
  }
  if(j+1<m&&d[i][j+1]>d[i][j]+1){
   d[i][j+1]=d[i][j]+1;
   q.push({i,j+1});
  }
 }
 int ans=0;
 for(int i=0;i<n;i++){
  for(int j=0;j<m;j++){
   ans=max(ans,d[i][j]);
  }
 }
 cout<<ans<<endl;
 return 0;
}

Measured memory_bytes: 13456
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
//#define S set<int>
#define itn int
bool dbg = false;

int N, K;
int H[202020];

void solve() {
    sort(H, H + N);
    int ans = 0;
    FOR(i, 0, N - K)
    ans += H[i];
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N >> K;
    FOR(N)
    cin >> H[i];
    solve();
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

typedef struct point{ // 点を表す構造体
    int x_elem;
    int y_elem;
}point;

point shift_point(point vtx1, point vtx2){ // vtx1を中心にvtx2を90度回転させた座標を返す関数
    /* 複素数平面上で考える。
     * 複素数 z1 を中心に複素数 z2 を90°回転させた複素数 z は
     *   z = (z2 - z1)i + z1  と表される。
     *
     * z1 = x1 + iy1, z2 = x2 + iy2 とすると
     * z = {x2 + iy2 - (x1 + iy1)}i + x1 + iy1
     *   = {x2 - x1 + i(y2 - y1)}i + x1 + iy1
     *   = -(y2 - y1) + i(x2 - x1) + x1 + iy1
     *   = x1 + y1 - y2 + i(- x1 + x2 + y1)
     */
    point vtx;
    vtx.x_elem = vtx1.x_elem + vtx1.y_elem - vtx2.y_elem;
    vtx.y_elem = - vtx1.x_elem + vtx2.x_elem + vtx1.y_elem;
    return vtx;
}

int main(void){
    point vtx1, vtx2, vtx3, vtx4;
    scanf("%d%d%d%d", &vtx1.x_elem, &vtx1.y_elem, &vtx2.x_elem, &vtx2.y_elem);
    
    // vtx1, vtx2, vtx3, vtx4 は反時計回りに並んでいる
    vtx4 = shift_point(vtx1, vtx2); // vtx4はvtx1を中心にvtx2を90°回転させた座標にある。
    vtx3 = shift_point(vtx4, vtx1); // vtx3はvtx4を中心にvtx1を90°回転させた座標にある。
  
    printf("%d %d %d %d\n", vtx3.x_elem, vtx3.y_elem, vtx4.x_elem, vtx4.y_elem);
    return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<string> vs;
const ll mod = 1e9+7;
const ll inf = 1e17;
const int INF = 1e9;
const double PI = acos(-1);
#define fo(i, a, b) for (int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(s) s.begin(), s.end()
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
int main()
{
  string s;
  cin >> s;

  bool ac = true;
  if(s[0] != 'A') {
    ac = false;
  } else {
    int c = 0;
    fo(i, 2, s.size()-1) {
      if(s[i] == 'C') {
        s.erase(i, 1);
        c++;
      }
    }
    if(c != 1) ac = false;
    int a = 0;
    fo(i, 1, s.size()) {
      if(isupper(s[i])) a++;
    }
    if(a != 0) ac = false;
  }
  if(ac) cout << "AC" << endl;
  else cout << "WA" << endl;

  return 0;
}


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

#ifdef DEBUG
#define FAST ;
#else
#define FAST ios::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#endif
#define _ <<' '<<
#define Fr(i, s, e) for(auto i = s; i < e; ++i)
#define Ft first
#define Sd second
using ll = long long;
using pii = pair<int, int>;
constexpr ll MAX = 1e6+5;
constexpr ll INF = 2134567890;
constexpr ll MOD = 998244353;

ll fpow(ll b, ll a, ll MOD = MOD) {
    b %= MOD;
    ll r = 1;
    for(; a; b=b*b%MOD, a>>=1)
        a&1 && (r = r*b%MOD);
    return r;
}

signed main() {
    FAST;

    int N;
    cin >> N;
    vector<int> X(N), L(N);
    Fr(i, 0, N) cin >> X[i] >> L[i];
    vector<pii> line(N);
    Fr(i, 0, N) line[i] = { X[i]-L[i], X[i]+L[i] };
    sort(line.begin(), line.end(), [](const pii &a, const pii &b) {
            if (a.Sd != b.Sd) return a.Sd < b.Sd;
            return a.Ft < b.Ft;
        });
    //Fr(i, 0, N) cout << line[i].Ft _ line[i].Sd << endl;
    int cnt = 1, last = 0;
    Fr(i, 1, N) if (line[last].Sd <= line[i].Ft) {
        cnt++;
        last = i;
    }
    cout << cnt << endl;

}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 500005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 1e9 + 7;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, q;
    while (cin >> n >> q) {
        vector<ll>v(n);
        vector<ll>pre{0};
        vector<ll>suf{0};
        for (auto &i : v) {
            cin >> i;
        }
        for (int i = 0 ; i < v.size(); i++) {
            if (i % 2 != n % 2) {
                pre.pb(pre.back() + v[i]);
            }
        }
        for (int i = v.size() - 1 ; i >= 0 ; i--) {
            suf.pb(suf.back() + v[i]);
        }
        while(q--) {
            ll x;
            cin >> x;
            int r = (n + 1) / 2 + 1;
            int l = 1;
            while (r - l > 1) {
                int mid = (r + l) >> 1;
                ll val = v[n - mid];
                if (val < x) {
                    r = mid;
                }
                ll lb = x * 2 - val;
                int cnt = lower_bound(v.begin(),v.end(),val) - lower_bound(v.begin(),v.end(),lb);
                if (cnt >= mid - 1) {
                    l = mid;
                }
                else {
                    r = mid;
                }
            }
            int rem = (n + 1) / 2 - l;
            cout << pre[rem] + suf[l] << '\n';
        }
    }
}

Measured memory_bytes: 3828
n=int(input())
fact=[1]*13
for i in range(2,13):
	fact[i]=i*fact[i-1]
p=list(map(int,input().split()))
q=list(map(int,input().split()))
a=0
b=0
for i in range(n):
	a=a+((p[i]-1)*(fact[n-i-1]))
	b=b+((q[i]-1)*(fact[n-i-1]))
	for j in range(i+1,n):
		if(p[j]>p[i]):
			p[j]=p[j]-1
		if(q[j]>q[i]):
			q[j]=q[j]-1
print(abs(a-b))

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
//#include<math.h>
//#include<string.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
int main() {
	int n, i,max,num,d,dd,t;
	for (; fscanf(stdin, "%d", &n), n != 0;fprintf(stdout,"%d %d\n",num,max)) {
		num=max=-1;
		fscanf(stdin, "%d%d%d", &t, &d, &dd);
		max = d + dd,num=t;
		for (i = 1; i < n; i++) {
			fscanf(stdin, "%d%d%d", &t, &d, &dd);
			if (d + dd > max)max = d + dd, num = t;
		}
	}
	return 0;
}

Measured memory_bytes: 604