akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var S = sc.ReadStr();
        var K = sc.ReadInt();

        var list = new char[S.Length];
        for (int i = 0; i < S.Length; i++)
        {
            if (S[i] == 'a')
            {
                list[i] = 'a';
                continue;
            }
            var d = 26 - (S[i] - 'a');
            if (d <= K)
            {
                K -= d;
                list[i] = 'a';
            }
            else
            {
                list[i] = S[i];
            }
        }
        if (K > 0)
        {
            list[S.Length - 1] = (char)((list[S.Length - 1] - 'a' + K) % 26 + 'a');
        }
        var ans = new string(list);
        Console.WriteLine(ans);
    }
    static Scanner sc = new Scanner();
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }
    public string ReadStr()
    {
        return this.Next();
    }
    public char ReadChar()
    {
        return this.Next()[0];
    }
    public int ReadInt()
    {
        return int.Parse(this.Next());
    }
    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }
    public long ReadLong()
    {
        return long.Parse(this.Next());
    }
    public double ReadDouble()
    {
        return double.Parse(this.Next());
    }
    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }
    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }
    public double[] ReadDoubleArray(int n)
    {
        var array = new double[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadDouble();
        }
        return array;
    }
    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }
    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}


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

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

    int n; cin>>n; bitset<1> a[n+1];int iti=0;bitset<1> key1,key2;
    for (int i = 1; i <= n; i++){
        cin>>a[i];
    }
    key1=a[1];
    for (int i = n; i >=1; i--){
        for (int j = 2*i; j <= n; j+=i)a[i]^=a[j];
        if(a[i]==1)iti++;
    }
    key2=a[1];
    for (int i = 2; i <= n; i++) key2^=a[i];
    if(key1!=key2){
        cout<<-1<<'\n';
    }else{
        cout<<iti<<'\n';
        for (int i = 1; i <= n-1; i++)if(a[i]!=0)cout<<i<<' ';
        if(a[n]!=0)cout<<n;
        if(iti)cout<<endl;
    }
}

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

int main() {
    vector<vector<int>> A(3, vector<int>(3));
    rep(i, 3) {
        rep(j, 3) {
            cin >> A.at(i).at(j);
        }
    }

    int N;
    cin >> N;

    vector<int> B(N);
    rep(i, N) {
        cin >> B.at(i);
    }

    vector<vector<bool>> C(3, vector<bool>(3, false));
    rep(i, 3) {
        rep(j, 3) {
            rep(k, N) {
                if(A.at(i).at(j) == B.at(k)) C.at(i).at(j) = true;
            }
        }
    }

    string ANS = "No";
    rep(i, 3) {
        if(C.at(i).at(0) and C.at(i).at(1) and C.at(i).at(2)) ANS = "Yes";
    }
    rep(i, 3) {
        if(C.at(0).at(i) and C.at(1).at(i) and C.at(2).at(i)) ANS = "Yes";
    }
    if(C.at(0).at(0) and C.at(1).at(1) and C.at(2).at(2)) ANS = "Yes";
    if(C.at(2).at(0) and C.at(1).at(1) and C.at(0).at(2)) ANS = "Yes";

    cout << ANS << endl;;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
static const int64_t INF=10000000000000;
struct edge{int64_t from,to,cost;};
int main(){
int64_t N,M;cin>>N>>M;
  vector<edge>es(M);
  for(int i=0;i<M;i++){
  int64_t a,b,c;cin>>a>>b>>c;
    a--;b--;
    es[i].from=a;
    es[i].to=b;
    es[i].cost=-c;
  }vector<int64_t>d(N,INF);
  d[0]=0;
  for(int i=0;i<N-1;i++){
  for(int j=0;j<M;j++){
  if(d[es[j].from]!=INF && d[es[j].to]>d[es[j].from]+es[j].cost)
    d[es[j].to]=d[es[j].from]+es[j].cost;
   }
   } for(int i=0;i<N;i++){
  for(int j=0;j<M;j++){
  if(d[es[j].from]!=INF && d[es[j].to]>d[es[j].from]+es[j].cost)
    d[es[j].to]=-INF;
   }
   }if(d[N-1]<=-INF)
    cout<<"inf"<<endl;
  else
    cout<<-d[N-1]<<endl;
  
  return 0;
}

Measured memory_bytes: 3664
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
#include <map>
#include <queue>
#include <set>
using namespace std;

#define ll long long
const int MOD = 1000000007;//10^9+7
const string SPACE = " ";

ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//pは素数,aのb乗をpで割った余り

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//pは素数,(nCr)%p

ll gcd(ll a, ll b) {

	if (a > b) {

		ll tmp = a;
		a = b;
		b = tmp;

	}
	ll r;
	r = b%a;
	if (r == 0)return a;
	else return gcd(r, a);

}
//最大公約数

ll lcm(ll a, ll b) {

	return (a / gcd(a, b))*b;

}
//最小公倍数

ll MAX(ll a, ll b) {

	if (a > b)return a;
	else return b;

}
//MAX

int main() {

	int A, B, X;

	cin >> X >> A >> B;
	cout << (X - A) % B << endl;

	return 0;
}

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

using namespace std;

const int N = 1e5+1;

int a[N], b[N], c[N], mx[3][N];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;
		
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i] >> b[i] >> c[i];
	
	for(int i = 1; i <= n; i++) {
		mx[0][i] = a[i] + max(mx[1][i-1], mx[2][i-1]);
		mx[1][i] = b[i] + max(mx[0][i-1], mx[2][i-1]);
		mx[2][i] = c[i] + max(mx[0][i-1], mx[1][i-1]);
	}
	
	cout << max(mx[0][n], max(mx[1][n], mx[2][n]));
}

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

struct Kruskal{

  struct UnionFind{
    Int n;
    vector<Int> r,p;
    UnionFind(){}
    UnionFind(Int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
    Int find(Int x){
      return (x==p[x]?x:p[x]=find(p[x]));
    }
    bool same(Int x,Int y){
      return find(x)==find(y);
    }
    void unite(Int x,Int y){
      x=find(x);y=find(y);
      if(x==y) return;
      if(r[x]<r[y]) swap(x,y);
      r[x]+=r[y];
      p[y]=x;
    }
  };
  
  struct edge{
    Int from,to,cost,used;
    edge(){}
    edge(Int from,Int to,Int cost):
      from(from),to(to),cost(cost),used(0){}
    bool operator<(const edge& e) const{
      return cost<e.cost;
    }
  };

  Int n;
  vector<edge> edges;

  Kruskal(){}
  Kruskal(Int sz):n(sz){}
  
  void add_edge(Int u,Int v,Int c){
    edges.emplace_back(u,v,c);
  }

  void input(Int m,Int offset=0){
    Int a,b,c;
    for(Int i=0;i<m;i++){
      cin>>a>>b>>c;
      add_edge(a+offset,b+offset,c);
    }
  }
  
  Int build(){
    UnionFind uf(n+1);
    Int res=0;
    
    for(auto &e:edges){
      if(e.used){
       	res+=e.cost;
	uf.unite(e.from,e.to);
      }
    }
    
    for(auto &e:edges){
      if(!uf.same(e.from,e.to)){
	res+=e.cost;
	uf.unite(e.from,e.to);
	e.used=1;
      }
    }
    return res;
  }
};

//INSERT ABOVE HERE
signed main(){
  Int n,m,x;
  cin>>n>>m>>x;
  Kruskal ks(n);
  ks.input(m,-1);
  
  sort(ks.edges.begin(),ks.edges.end());
  Int y=ks.build();
  if(y>x){
    cout<<0<<endl;
    return 0;
  }

  Int ok=0,alt=0,ng=0;
  for(Int i=0;i<m;i++){
    for(Int j=0;j<m;j++) ks.edges[j].used=0;
    ks.edges[i].used=1;
    Int z=ks.build();
    //cout<<y<<" "<<z<<endl;
    if(z==y) ok++;
    if(z==x) alt++;
    if(z >x) ng++;
  }
  
  const Int MOD = 1e9+7;
  vector<Int> po(m+1,1);
  for(Int i=0;i<m;i++) po[i+1]=po[i]*2%MOD;

  if(y==x){
    Int ans=(po[ok]+MOD-2)%MOD*po[m-ok]%MOD;
    cout<<ans<<endl;
    return 0;
  }
  
  //cout<<ok<<" "<<alt<<" "<<ng<<endl;
  Int ans=(po[alt+1]+MOD-2)%MOD*po[ng]%MOD;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 512
import sys
sys.setrecursionlimit(10**6)
from collections import defaultdict

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

d = defaultdict(int)

for i in range(N):
    d[A[i]] += 1

#print(d)
a = defaultdict(int)
b = defaultdict(int)
for key, value in d.items():
    a[key] = value * (value - 1) //2
    b[key] = value * (value - 1) //2 - (value - 1) * (value - 2) // 2
#print(a)
#print(b)
total = 0
for key, value in a.items():
    total += value
#print(total)
for i in range(N):
    ans = total - b[A[i]]
    print(ans)

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

typedef long long ll;

int main(){
    int N,M;
    cin >> N >> M;
    char A[N][N];
    char B[M][M];
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            cin >> A[i][j];
        }
    }
    for(int i=0;i<M;i++){
        for(int j=0;j<M;j++){
            cin >> B[i][j];
        }
    }
    bool ok = false;

    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(i+M-1>=N||j+M-1>=N)continue;

            bool match = true;
            for(int y=0;y<M;y++){
                for(int x=0;x<M;x++){
                    if(A[i+y][j+x]!=B[y][x]){
                        match = false;
                        break;
                    }
                }
            }
            if(match) ok =true;
        }
    }

    if(ok){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}


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

int main()
{
    int t;
    ll sum=0;
    cin>>t;
    for(ll i=1;i<=t;i++)
	{
		if(i%3!=0&&i%5!=0)
		sum+=i;
	 } 
	cout<<sum;
    return 0;
}

Measured memory_bytes: 3596
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

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

    ll K, X, Y; cin >> K >> X >> Y;
    if (K % 2 == 0 && (abs(X) + abs(Y)) % 2 == 1) {
        cout << -1 << endl; return 0;
    }

    ll curX = 0, curY = 0;

    ll ans = (abs(X) + abs(Y) +K-1)/K;
    if (ans == 1 && (abs(X)+abs(Y)) != K) ans++;
    while ((ans*K-abs(X)-abs(Y))%2 != 0) ans++;

    ll waste = ans*K; waste -= (abs(X)+abs(Y)); waste /= 2;
    cout << ans << endl;
    bool loX = abs(X) < abs(Y);
    while (waste > 0) {
        if (loX && X >= 0) {
            curX -= min(waste, K);
        } else if (loX) {
            curX += min(waste, K);
        } else if (Y >= 0) {
            curY -= min(waste, K);
        } else {
            curY += min(waste, K);
        }
        ll leftover = K - min(waste, K);
        //cout << leftover << endl;
        if (loX) {
            //adjust Y
            if (curY < Y) {
                curY += leftover;
            } else {
                curY -= leftover;
            }
        } else {
            if (curX < X) {
                curX += leftover;
            } else curX -= leftover;
        }

        waste -= min(waste, K);
        cout << curX << " " << curY << endl;
        loX = abs(X-curX) < abs(Y-curY);
    }

    while (curX != X || curY != Y) {
        ll rem = K;
        if (curX != X) {
            ll todo = min(K, abs(X-curX));
            if (curX < X) {
                curX += todo;
            } else {
                curX -= todo;
            }
            rem -= todo;
        }
        if (curY != Y) {
            ll todo = min(rem, abs(Y-curY));
            if (curY < Y) {
                curY += todo;
            } else curY -= todo;
        }

        cout << curX << " " << curY << endl;
    }



    return 0;
}

// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 2304
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	string s, t; cin >> s >> t;
	int ans = 0;
	for (int i = 0; i < s.size(); ++i)
		ans += s[i] == t[i] ? 1 : 0;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define MOD 1000000007
ll powll(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)
#define swapd(a,b) do{double w=(a);(a)=(b);(b)=w}while(0)
#define in(a) scanf("%lld", &(a))
#define in2(a,b) scanf("%lld %lld",&(a),&(b))
#define in3(a,b,c) scanf("%lld %lld %lld",&(a),&(b),&(c))
#define ind(a) scanf("%lf", &(a))
#define ins(a) scanf("%s", (a))
#define inc(a) scanf("%c", &(a))
#define put(a) printf("%lld\n", (a))
#define putd(a) printf("%.15f\n", (a))
//      puts(a) printf("%s\n", a) 文字はこっち
//your code here!
int main(void){
    ll A, B, ans=0;
    in2(A,B);
    char s[6];
    rep(i, B-A+1){
        ll x=A+i;
        rep(j, 5){
            s[4-j] = '0' + x%10;
            x /= 10;
        }
        if(s[0]==s[4] && s[1]==s[3]) ans++;
    }
    put(ans);
    return 0;
}


Measured memory_bytes: 128
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
        k: usize,
        mut l: [usize;n],
    }
    l.sort();
    l.reverse();
    let mut sum = 0;
    for i in 0..k {
        sum += l[i];
    }
    println!("{}", sum);
}


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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int modPow(ll a, ll n, ll p) {
  if (n == 0) return 1;
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
  ll t = modPow(a, n / 2, p);
  return (t * t) % p;
}

int main() {
	ll X, Y; cin >> X >> Y;
	if((X + Y) % 3 != 0 || (double)Y > 2 * (double)X || (double)Y < (double)X / 2)  {
		cout << 0 << endl;
		return 0;
	}
	else if((X % 2 == 0 && Y == X / 2) || (Y % 2 == 0 && Y == 2 * X)) {
		cout << 1 << endl;
		return 0;
	}
	ll l = max((2 * X - Y) / 3, (ll)0);
	ll s = max((2 * Y - X) / 3, (ll)0);
	
	ll fact = 1;
	for(int i = 2; i <= l + s; i++) fact = fact * i % mod;
	ll invfact1 = 1;
	for(int i = 1; i <= l; i++) invfact1 = invfact1 * modPow(i, mod - 2, mod) % mod;
	ll invfact2 = 1;
	for(int i = 1; i <= s; i++) invfact2 = invfact2 * modPow(i, mod - 2, mod) % mod;
	ll ans = fact * invfact1 % mod;
	ans = ans * invfact2 % mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3616
N = int(input())
A = list(map(int,input().split()))

All = sum(A)

lim = len(A)//2
Exc1 = sum([A[2*i+1] for i in range(lim)])

one = All - Exc1*2
ans = [one]
for i in range(1,N):
    print('{}'.format(ans[-1]),end=' ')
    ans.append(A[i-1]*2 - ans[-1])
print('{}'.format(ans[-1]))


Measured memory_bytes: 20500
H,W=map(int,input().split())


S = [input() for i in range(H)]

ans = S

for i,row in enumerate(S):
    for j,mas in enumerate(row):
        if mas == '#':
            pass
        else:
            count = 0
            for i2 in [-1,0,1]:
                for j2 in [-1,0,1]:
                    if (i+i2<0) | (j+j2<0) | (i+i2>=H) |(j+j2>=W):
                        pass
                    else:
                        if S[i+i2][j+j2]=='#':
                            count +=1
            ans[i] = ans[i][:j] + str(count) +ans[i][j+1:]
for i in ans:
    print(i)

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

#define int long long
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define str string
#define vint vector<int>
#define vchar vector<char>
#define vool vector<bool>
#define pb() pushback
#define elif else if
#define all(x) x.begin(),x.end()

main(){
    int a,b,count=0,count2=0,H,W,ab,A,B;
    double r,pai=3.141592653589;
    int C='A'-'a';
    char op;
    str S,T;
    cin>>a>>b;
    cout<<a-b+1;
}


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

#define step(i, s, n, d) for(int i=s; i<n; i+=d)
#define FOR(i,s,n) step(i,s,n,1)
#define rep(i,n) FOR(i,0,n)
#define gets(x) x; cin >> x;
#define puts(x) x; cout << x << endl;
#define list_input(x, n) x[n]; rep(i,n){ gets(x[i]);}
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = (1LL<<50);

ll V;
struct edge { ll to, cost; }; //辺を持つ
vector<edge> G[100100];
ll dist[100100]; //最短経路を持つ

void dk(int s) {
  priority_queue< P, vector<P>, greater<P> > que;
  fill(dist, dist + 100100, INF);
  dist[s] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    P p = que.top(); que.pop();
    int v = p.second;
    if (dist[v] < p.first) continue;
    rep(i, G[v].size()){
      edge e = G[v][i];
      if (dist[e.to] > dist[v] + e.cost) {
        dist[e.to] = dist[v] + e.cost;
        que.push(P(dist[e.to], e.to));
      }
    }
  }
}

int main(){
  cin >> V;
  ll a, b, c;

  rep(i, V-1){
    cin >> a >> b >> c;
    a --; b --;
    G[a].push_back( {b,c} ); //AからBに行くのにCかかる
    G[b].push_back( {a,c} );
  }

  int Q, K, x, y;
  cin >> Q >> K;
  dk(K-1); // 頂点1が配列番号の0と対応しているため
  rep(i, Q){
    cin >> x >> y;
    cout << dist[x-1] + dist[y-1] << endl;
  }

}


Measured memory_bytes: 11120
#include<bits/stdc++.h>
#define title "title"
#define ll long long
#define ull unsigned ll
#define fix(x) fixed<<setprecision(x)
#define pii pair<ll,ll>
#define vint vector<ll>
#define pb push_back
using namespace std;
void Freopen(){
	freopen(title".in","r",stdin);
	freopen(title".out","w",stdout);
}
ll read(){
	ll g=0,f=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();}
	while('0'<=ch&&ch<='9'){g=g*10+ch-'0';ch=getchar();}
	return g*f;
}
const ll N=1e2+5;
const ll maxn=1e2;
ll n,m,k,mod,C[N][N],P[N][N],f[2][N][N];
void clear(ll opt){
	for(ll i=0;i<=n;i++)for(ll j=0;j<=m;j++)f[opt][i][j]=0;
}
signed main(){
	n=read(),m=read(),k=read(),mod=read();
	for(ll i=0;i<=maxn;i++)C[i][0]=1;
	for(ll i=1;i<=maxn;i++)for(ll j=1;j<=i;j++)C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
	for(ll i=0;i<=maxn;i++)P[i][0]=1;
	for(ll i=1;i<=maxn;i++)for(ll j=1;j<=maxn;j++)P[i][j]=P[i][j-1]*i%mod;
	ll now=1,last=0;f[0][0][0]=1;
	for(ll t=1;t<=k;t++){
		clear(now);for(ll i=0;i<=n;i++)for(ll j=0;j<=m;j++)if(f[last][i][j]){
			ll x=f[last][i][j],y=P[k-t+1][j]*P[t][m-j]%mod;
			for(ll a=0;i+a<=n;a++,x=x*y%mod)f[now][i+a][j]=(f[now][i+a][j]+C[n-i][a]*x%mod)%mod;
		}swap(now,last);
		clear(now);for(ll i=0;i<=n;i++)for(ll j=0;j<=m;j++)if(f[last][i][j]){
			ll x=f[last][i][j],y=P[k-t+1][i]*P[t][n-i]%mod;
			for(ll b=0;j+b<=m;b++,x=x*y%mod)f[now][i][j+b]=(f[now][i][j+b]+C[m-j][b]*x%mod)%mod;
		}swap(now,last);
		clear(now);for(ll i=0;i<=n;i++)for(ll j=0;j<=m;j++)if(f[last][i][j]){
			ll x=f[last][i][j],y=(mod-P[k-t][j])*P[t][m-j]%mod;
			for(ll a=0;i+a<=n;a++,x=x*y%mod)f[now][i+a][j]=(f[now][i+a][j]+C[n-i][a]*x%mod)%mod;
		}swap(now,last);
		clear(now);for(ll i=0;i<=n;i++)for(ll j=0;j<=m;j++)if(f[last][i][j]){
			ll x=f[last][i][j],y=(mod-P[k-t][i])*P[t][n-i]%mod;
			for(ll b=0;j+b<=m;b++,x=x*y%mod)f[now][i][j+b]=(f[now][i][j+b]+C[m-j][b]*x%mod)%mod;
		}swap(now,last);
	}return cout<<f[now][n][m],signed();
}
/*
2 2 2 998244353
2 3 4 998244353
31 41 59 998244353
*/

Measured memory_bytes: 3988
x,k,d = map(int, input().split())
def  abs_calc(x):
    if  x <  0:
        xi =  (-1)* x
    else:
        xi  = x
    return xi


xi = abs_calc(x)
a = xi // d
if a >= k:
    ans = xi - d * k
else:
    k  -= a
    ans = xi - d * a
    if  k %  2 != 0:
        ans =  d - ans
print(ans)


Measured memory_bytes: 9180
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rfor(i, a, b) for(int i = a; i < (int)b; i++)
#define all(ary) (ary).begin(), (ary).end()
#define debug(x) cerr << #x << ": " << x << '\n'
const long long INF = 1LL << 60;
const int MOD = 1000000007; // 1e9 + 7
using namespace std;
using vec = vector<int>;
using ll = long long;
template <class T = int> T in(){ T x; cin >> x; return (x);}
template <class T> inline bool chmin(T &a, T b) { if ( a > b ) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T &a, T b) { if ( a < b ) { a = b; return 1; } return 0; }
const int dy[4] = {-1, 0, 0, 1};
const int dx[4] = {0, -1, 1, 0};

ll N, T;

int main(int argc, char *argv[]){
    cin >> N >> T;
    vector<ll> t(N);
    rep(i, N) cin >> t[i];
    ll res = 0;
    ll start, end;
    start = 0;
    end = start + T;
    // rfor(i, 1, N + 1){
    //     if(start + T <= t[i]){
    //         res += T;
    //     }else{
    //         res += t[i] - start;
    //     }
    //     start = t[i];
    //     end = start + T;
    // }
    res = T;
    rep(i, N - 1){
        res += min(T, t[i + 1] - t[i]);
    }
    cout << res << endl;
    return 0;
}
// 2000000000
// 2000000000

Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>

int main()
{
	int a;
	int b;
	int d;
	int r;
	double f;

	std::cin >> a;
	std::cin >> b;

	d = a / b;
	r = a%b;
	f = (double)a / (double)b;

	std::cout << d << ' ' << r << ' ' <<std::fixed <<std::setprecision(20) << f << "\n";

	return 0;


}


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

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

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll LINF = 1LL<<29;
const int INF = 1e9;
const ll mod = 1e9+7;

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

int main()
{
  int N;
  cin >> N;
  int A[N+2];
  rep(i, 1, N+1)cin >> A[i];
  A[0] = 0;A[N+1] = 0;

  int D = 0;
  rep(i, 0, N+1){
    D += abs(A[i] - A[i+1]);
  }
  rep(i, 1, N+1){
    cout << D - abs(A[i] - A[i-1]) - abs(A[i] - A[i+1]) + abs(A[i-1] - A[i+1]) << endl;
  }
  return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define REP(i, x, y) for (ll i = x; i <= y; i++)
#define BIT(t) (1ll << t)
#define PER(i, y, x) for (ll i = y; i >= x; i--)
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define pll pair<ll, ll>
#define SIZE(v) ll(v.size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
//        ios::sync_with_stdio(false);
//        cin.tie(nullptr);

int main(){
        cout.precision(13);
        ll n;
        cin >> n;
        vll t(n);
        REP(i,0,n-1){
                t[i] = i+1;
        }
        vll x(n+1), y(n+1);
        REP(i,1,n){
                cin >> x[i] >> y[i];
        }
        double ans = 0;
        REP(i,0,n-2){
                ans += sqrt(pow(x[t[i]] - x[t[i+1]], 2) + pow(y[t[i]] - y[t[i+1]], 2));
        }

        while(next_permutation(t.begin(), t.end())){
                REP(i,0,n-2){
                        ans += sqrt(pow(x[t[i]] - x[t[i+1]], 2) + pow(y[t[i]] - y[t[i+1]], 2));
                }
        }
        REP(i,1,n){
                ans /= i;
        }
        cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <vector>
#include <string>
using namespace std;

int main() {
  int n;
  cin >> n;
  int d[n];
  int ans=0;

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

  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      ans+=d[i]*d[j];
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
const int mod=1e9+7;
int dp[1000006][2][2];
signed main()
{
	int n;
	cin>>n;
	dp[0][0][0]=1;
	for (int i=0;i<n;i++)
		for (int j=0;j<2;j++)
			for (int k=0;k<2;k++)
				if (dp[i][j][k]){
					int aa=dp[i][j][k];
					if (j+k==0)
						dp[i+1][0][1]+=aa,dp[i+1][1][0]+=aa,dp[i+1][0][0]+=aa*8%mod;
					if (j+k==1)
						dp[i+1][1][1]+=aa,dp[i+1][j][k]+=aa*9%mod;
					if (j&&k)
						dp[i+1][1][1]+=aa*10%mod;
				}
	cout<<dp[n][1][1]%mod;
	re 0;
}


Measured memory_bytes: 34668
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"n,*a=map(int,open(0).read().split());print(max(sum(a[:i+1]+a[n+i:])for i in range(n)))\n"
"\"";
  system(s);
  return 0;
}            

Measured memory_bytes: 3280
#include <iostream>

int main()
{
  int r, d, x2000;
  std::cin >> r >> d >> x2000;
  int xi = x2000;
  for (int i = 1; i <= 10; i++) {
    xi = r * xi - d;
    std::cout << xi << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [[input().split()] for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes) if b else print(no)
from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right

n,m=n1()
ab=n3(m)

node=defaultdict(list)
for a,b in ab:
    node[a].append(b)
    node[b].append(a)
    
p=deque([1])
d=[0]*(n+1)
while len(p)>0:
    c=p.popleft()
    for i in node[c]:
        if d[i]==0:
            d[i]=c
            p.append(i)
            
print("Yes")
for i in range(2,n+1):
    print(d[i])
    
    

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

int main() {
  int N;
  cin >> N;

  vector<int> A;
  int a;
  long long asum = 0;
  for (int i = 0; i < N; ++i) {
    cin >> a;
    A.push_back(a);
    asum += a;
  }

  vector<int> B;
  int b;
  long long bsum = 0;
  for (int i = 0; i < N; ++i) {
    cin >> b;
    B.push_back(b);
    bsum += b;
  }

  int change_i = -1;

  if (asum >= bsum) {
    // 準備度合計が十分にある
    change_i = 0;

    // 余裕度チェック
    vector<int> yoyu;
    vector<int> fusoku;
    for (int i = 0; i < N; ++i) {
      int d = A[i] - B[i];
      if (d > 0) {
        yoyu.push_back(d);
      } else if (d < 0) {
        // 正であることに注意
        fusoku.push_back(-d);
      }
    }

    // 後ろのほうが大きい
    sort(yoyu.begin(), yoyu.end());
    sort(fusoku.begin(), fusoku.end());

    int y = 0;
    while (!fusoku.empty()) {
      int f = fusoku.back();
      fusoku.pop_back();
      ++change_i;

      while (f > 0) {
        // 大きい余裕から取り出す
        if (y == 0) {
          y = yoyu.back();
          ++change_i;
        }

        if (f >= y) {
          yoyu.pop_back();
          f -= y;
          y = 0;
        } else if (f < y) {
          y -= f;
          f = 0;
        }
      }
    }
  }

  cout << change_i << endl;
  return 0;
}

Measured memory_bytes: 1784
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long int;

void solve()
{
    ll n, a, b;
    cin >> n >> a >> b;
    if(a > b) swap(a, b);
    --a;
    --b;
    
    if((b-a)%2 == 0){
        cout << (b-a)/2 << endl;
    }
    else{
        ll x = (b-a-1)/2 + a + 1;
        a = n-a-1;
        b = n-b-1;
        ll y = (b-a-1)/2 + a + 1;
        cout << min(x, y) << endl;
    }
}

signed main()
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = scanner.nextInt() - 1;
		}
		int sum = 0;
		for (int i = 0; i < n; i++) {
			sum += scanner.nextInt();
		}
		int[] c = new int[n - 1];
		for (int i = 0; i < n - 1; i++) {
			c[i] = scanner.nextInt();
		}

		for (int i = 0; i < n - 1; i++) {
			if (a[i] + 1 == a[i + 1])
				sum += c[a[i]];
		}
		System.out.println(sum);

	}

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define INF 2147483647
#define LLINF 9223372036854775807
using namespace std;
long long ans[500010];
long long cnt[500010];
long long a[500010];
priority_queue<long long,vector<long long>,greater<long long> > q;
priority_queue<long long,vector<long long>,greater<long long> > p;
long long n;
int main()
{
	cin>>n;
	for(int i=0;i<3*n;i++)
		cin>>a[i];
	long long sum=0;
	for(int i=0;i<n;i++)
	{
		sum+=a[i];
		q.push(a[i]);
	}
	ans[n-1]=sum;
	for(int i=n;i<2*n;i++)
	{
		sum+=a[i];
		q.push(a[i]);
		sum-=q.top();
		q.pop();
		ans[i]=sum;
	}
	sum=0;
	for(int i=3*n-1;i>=2*n;i--)
	{
		sum+=a[i];
		p.push(-a[i]);
	}
	cnt[2*n]=sum;
	for(int i=2*n-1;i>=n;i--)
	{
		sum+=a[i];
		p.push(-a[i]);
		sum-=-p.top();
		p.pop();
		cnt[i]=sum;
	}
	long long mx=-LLINF;
	for(int i=n-1;i<2*n;i++)
	{
		mx=max(mx,ans[i]-cnt[i+1]);
	}
	cout<<mx<<"\n";
	return 0;
}

Measured memory_bytes: 10100
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
template<class T> using vv=vector<vector< T > >;

int main() {
  int n, max_w;
  cin >> n >> max_w;
  vector<map<string, int> > items;
  items.pb({{"dummy", 0}});
  for (int i = 0 ; i < n ; i++) {
    int v_tmp, w_tmp;
    cin >> v_tmp >> w_tmp;
    map<string, int> mp;
    mp["value"] = v_tmp;
    mp["weight"] = w_tmp;
    items.pb(mp);
  }

  vvi max_value(n+1, vi(max_w+1, 0));
  for (int item_num = 1 ; item_num <= n ; item_num++) {
    for (int w_left = 1 ; w_left <= max_w ; w_left++) {
      max_value[item_num][w_left] = max_value[item_num-1][w_left];
      if (w_left >= items[item_num]["weight"]) {
        max_value[item_num][w_left] = max(max_value[item_num][w_left], 
          items[item_num]["value"] + max_value[item_num-1][w_left - items[item_num]["weight"]]);
      }
    }
  }

  printf("%d\n", max_value[n][max_w]);

  return 0;
}

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

int main()
{
	long long x, k, d;
	cin >> x >> k >> d;

	// 0 までに必要な移動回数
	if (x < 0) {
		x = -x;
	}
	long long n = x / d;
	long long a = x % d;

	if (k < n) {
		cout << x - d * k << endl;

		system("pause");
		return 0;
	}

	// 残りは0付近で＋ー移動繰り返す
	long long m = k - n;
	if (m % 2 == 0) {
		cout << a << endl;
	}
	else {
		cout << d - a << endl;
	}

	return 0;
}

Measured memory_bytes: 3684
n = int(input())
h = list(map(int, input().split()))
t = 0
result = 0
for i in range(n - 1):
  if h[i + 1] <= h[i]:
    t += 1
  else:
    result = max(t, result)
    t = 0
result = max(t, result)
print(result)

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

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

#define dump(x) cerr << #x << " = " <<(x)<<endl;
#define debug(x) cerr << #x << " = " <<(x) << "(L" << __LINE__ << ")" << __FILE__ << endl;

#define BIT_ON(x,b) ((x)|=(b))
#define BIT_OFF(x,b) ((x)&=~(b))
#define BIT_IS_ON(x,b) (((x)&(b))==(b))


using namespace std;
typedef long long ll;

int main(void){
  ll n,a,b;
  cin >> n >>  a >> b;
  
  if(a > b) {
    cout << 0 << endl;
    return 0;
  }

  if(a == b){
    cout << 1 << endl;
    return 0;
  }

  if(n==1 && a!=b){
    cout << 0 << endl;
    return 0;
  }

  if(n==1 && a!=b){
    cout << 1 << endl;
    return 0;
  }
  
  ll ans;
  ans = a+(n-1)*b - a*(n-1) -b + 1;
  cout  << ans << endl;


  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	
	n := scanInt()
	a := make([]int, n)

	m1,m2 := 0,0
	for i := 0; i < n; i++ {
		a[i] = scanInt()
		if m1 < a[i] {
			m1, m2 = a[i], m1
		} else if m2 < a[i] {
			m2 = a[i]
		}
	}

	for i := 0; i < n; i++ {
		if a[i] == m1 {
			fmt.Println(m2)
		} else {
			fmt.Println(m1)
		}
	}
}


Measured memory_bytes: 6400
a=[]
for i in range(3):
    b=map(int, raw_input().split())
    a.append(b)

lis=[[0,0,0],[0,0,0]]
for i in range(3):
    lis[0][i] = a[i][0] + a[i][1] + a[i][2]
    lis[1][i] = a[0][i] + a[1][i] + a[2][i]

ch=0
for i in range(3):
    if (lis[0][i-1]-lis[0][i])%3!=0:
        ch=1
        break
    if (lis[1][i-1]-lis[1][i])%3!=0:
        ch=1
        break

if ch==0:
    print "Yes"
else:
    print "No"

Measured memory_bytes: 2696
class UnionFind(n: Int) {
    private val parent = IntArray(n, {-1})
    private val rank = IntArray(n, {0})
    private val size = IntArray(n, {1})
    private var numTree = n
    
    fun find(x: Int): Int {
        if (parent[x] == -1) {
            return x
        } else {
            parent[x] = find(parent[x])
            return parent[x]
        }
    }
    
    fun isSame(x: Int, y: Int): Boolean {
        return find(x) == find(y)
    }
    
    fun getSize(): Int {
        return numTree
    }
    
    fun sizeOf(x: Int): Int {
        return size[find(x)]
    }
    
    fun rankOf(x: Int): Int {
        return rank[find(x)]
    }
    
    fun unite(x: Int, y: Int) {
        val parentX = find(x)
        val parentY = find(y)
        
        if (parentX == parentY) {
            return
        }
        
        numTree--
        
        if (rank[parentX] < rank[parentY]) {
            parent[parentX] = parentY
            size[parentY] += size[parentX]
        } else {
            parent[parentY] = parentX
            size[parentX] += size[parentY]
            if (rank[parentX] == rank[parentY]) {
                rank[parentX]++
            }
        }
    }
}

fun main(args: Array<String>) {
    val (N, M) = readInputLine().split(" ").map { it.toInt() }
    
    val ps = readInputLine().split(" ").map { it.toInt() - 1 }
    
    val unionFind = UnionFind(N)
    
    for (i in 1..M) {
        val (x, y) = readInputLine().split(" ").map { it.toInt() - 1 }
        unionFind.unite(x, y)
    }
    
    var ans = 0
    
    for ((i, p) in ps.withIndex()) {
        if (unionFind.isSame(i, p)) {
            ans++
        }
    }

    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 74968
#include <iostream>

using namespace std;

int main(){
    long int N;
    long int A,B;
    cin>>N>>A>>B;
    long int result=0;
    long int count=N/(A+B);
    result=count*A;
    long int tmp=(N%(A+B));
    if(tmp>=A){
        result+=A;
    }else{
        result+=tmp;
    }
    cout<<result;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size() 

ll power(ll x,ll y,ll p) 
{ 
    ll res = 1;      
    x = x % p;  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p;   
    } 
    return res; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
	ll n,i,j,k,x,y,t,m;

	cin >> x >> y;
	ll f=0;
	for(i=0;i<=x;i++)
	{
		j=x-i;

		if(2*i+4*j==y)
			f=1;
	}
	if(f)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}

Measured memory_bytes: 3640
import itertools
A = [ list(map(int, input().split())) for i in range(3)]
a = list(itertools.chain.from_iterable(A))

N = int(input())
b = [ int(input()) for i in range(N)]

for i in b:
    for j in range(len(a)):
        if a[j] == i:
            a[j] = 0
   
flag = False

for i in [0, 1, 2]:
    if a[i] + a[i + 3] + a[i + 6] == 0:
        flag = True
    elif a[i * 3] + a[i * 3 + 1] + a[i * 3 + 2] == 0:
        flag = True
    elif i == 0 and (a[0] + a[4] + a[8] == 0 or a[2] + a[4] + a[6] == 0):
        flag = True

if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
int main() {
  int a,b; cin>>a>>b;
  int n;
  if(b<10) n=a*10+b;
  else if(b<100) n=a*100+b;
  else n=a*1000+b;
  string ans="No";
  for(int i=0;i<n;i++){
    if(n==i*i) ans="Yes";
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=3e3+5;
int a[N][N];long long f[N][N][3];
int main(){
	int r,c,k,x,y,z;scanf("%d%d%d",&r,&c,&k);
	for(int i=0;i<k;i++){
		scanf("%d%d%d",&x,&y,&z);
		a[x][y]=z;
	}
	for(int i=1;i<=r;i++){
		for(int j=1;j<=c;j++){
			for(int k=0;k<3;k++){
				f[i][j][k]=max(f[i-1][j][2],(k?f[i][j-1][k-1]:0))+a[i][j];
				f[i][j][k]=max(f[i][j][k],f[i][j-1][k]);
			}
		}
	}
	printf("%lld",f[r][c][2]);
	return 0;
}

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

int main() {
    int N;  cin>>N;
    string brac;    cin>>brac;
    stack<char> st;
    int back = 0, front = 0;
    for (int i = 0; i < N; ++i) {
        if (brac[i] == '(') {
            st.push('(');
        } else {
            if (st.size() == 0) {
                back++;
            } else
                st.pop();
        }
    }
    
    for (int i = 0; i < back; ++i)
        cout<<"(";
    cout<<brac;
    for (int i = 0; i < st.size(); ++i)
        cout<<")";
    
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		FastScanner fs = new FastScanner();
		int R = fs.nextInt();

		double x = R * 2.0 * Math.PI;

		System.out.println(x);
	}

}


Measured memory_bytes: 25396
#include <bits/stdc++.h>
#define FIN         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii          pair<int,int>
#define F           first
#define S           second
#define pb          push_back
#define all(x)      (x).begin(),(x).end()
#define rall(x)     (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a)   for(int i = a; i >= 0; i--)
#define fori(i,m)   for(auto i = m.begin(); i != m.end(); i++) 
#define w(t)        while(t--)
#define sz(s)       int(s.size())
#define cls(a,car)  memset(a,car,sizeof (a))
#define db(x)       cerr << #x << " is " << x << '\n'
#define FL          freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout);
#define EjecuteTime cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
#define angle(x)    double(x * acos(-1) / 180.0)
using namespace std;
typedef long long   ll;
typedef vector<int> vi;
typedef vector<ii>  vii;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const double E = 1e-9;
//int dx[] = {1, 0}, dy[] = {0, 1};
//int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//int dx[] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[] = {1, 2, 2, 1, -1, -2, -2, -1};
//int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy[] = {0 ,1, 1, 1, 0, -1, -1, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
string a, b;
int dp[3010][3010];
int f(int i, int j){
    if(i == sz(a) or j == sz(b))
        return 0;
    int &ans = dp[i][j];
    if(ans == -1){
        ans = 0;
        if(a[i] == b[j])
            ans = f(i + 1, j + 1) + 1;
        else
            ans = max(f(i + 1, j), f(i, j + 1));

    }return ans;
}

void build(int i, int j){
    if(i == sz(a) or j == sz(b))
        return;
    int ans = f(i, j);
    if(a[i] == b[j] && ans == f(i + 1, j + 1) + 1){
        cout << a[i];
        build(i + 1, j + 1);
        return ;
    }
    else{
        if(ans == f(i + 1, j)){
            build(i + 1, j);
            return;
        }else{
            build(i, j + 1);
            return ;
        }
    }
}
int main(){
    //FL;
    FIN;
    cin >> a >> b;
    for(int i = sz(a); i >= 0; i--){
        for(int j = sz(b); j >= 0; j--){
            int &ans = dp[i][j];
            if(i == sz(a) or j == sz(b)){
                ans = 0;
                continue;
            }
            ans = 0;
            if(a[i] == b[j])
                ans = dp[i + 1][j + 1] + 1;
            else{
                ans = max(dp[i + 1][j], dp[i][j + 1]);
            }
        }
    }
    // build iterativo
    int i = 0, j = 0;
    while(i < sz(a) && j < sz(b)){
        int ans = dp[i][j];
        if(a[i] == b[j] && ans == dp[i + 1][j + 1] + 1){
            cout << a[i];
            i++;j++;
        }else{
            if(ans == dp[i + 1][j])
                i++;
            else
                j++;
        }
    }
    EjecuteTime;
    return 0;
}       

Measured memory_bytes: 39024
a, b = map(int, input().split())
d = b - a
for i in range(1,999):
    Si = i * (i + 1) // 2
    Sii = (i + 1) * (i + 2) // 2
    Sd = Sii - Si
    if d == Sd:
        height = Si
        break
print(height - a)

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

using ll = long long;

constexpr int MAX_N = 1e5 - 1;
int A[MAX_N];

int main() {
  int N;
  cin >> N;
  for (int i{}; i < N; ++i) cin >> A[i];

  int x2{};
  for (int i{}; i < N; ++i) {
    x2 += (i % 2 ? -A[i] : A[i]);
  }
  vector<int> ans(N);
  ans[0] = x2;
  cout << ans[0];
  for (int i{0}; i < N - 1; ++i) {
    ans[i + 1] = (A[i] - ans[i] / 2) * 2;
    cout << " " << ans[i + 1];
  }

  return 0;
}


Measured memory_bytes: 2048
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		System.out.println((b - a == c - b) ? "YES" : "NO");

		sc.close();


	}
}




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

int main() {
  vector<int> v(3);
  cin >> v[0] >> v[1] >> v[2];
  sort(v.begin(), v.end());
  int ans = v[0] + v[1];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
s = gets.chomp

if s.include?('RRR')
  puts 3
elsif s.include?('RR')
  puts 2
elsif s.include?('R')
  puts 1
else
  puts 0
end




Measured memory_bytes: 14640