akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for (int i = n - 1; i >= 0; i--)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

#define INF bit(60)
#define pb push_back
#define mod 1000000007

template <class T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
  if (b < a)
  {
    a = b;
    return 1;
  }
  return 0;
}

using namespace std;
using uif = uint_fast64_t;
using ll = long long int;
using tTree = __gnu_pbds::tree<ll, __gnu_pbds::null_type, less<ll>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

int qp(int a, ll b)
{
  int ans = 1;
  do
  {
    if (b & 1)
      ans = 1ll * ans * a % mod;
    a = 1ll * a * a % mod;
  } while (b >>= 1);
  return ans;
}
int qp(int a, ll b, int mo)
{
  int ans = 1;
  do
  {
    if (b & 1)
      ans = 1ll * ans * a % mo;
    a = 1ll * a * a % mo;
  } while (b >>= 1);
  return ans;
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

#define FACSIZE 2002

ll invfac[FACSIZE];
ll fac[FACSIZE];

ll mod_pow(ll, ll);
ll mod_add(ll, ll);
ll mod_mul(ll, ll);
ll mod_div(ll, ll);
void make_fact(ll);
void make_invfact(ll);

int main(void)
{
	ll a1,a2,a3;
  cin>>a1>>a2>>a3;
  if(a1+a2+a3>=22){
  cout << "bust" << endl;
  }
  else{
  	cout << "win" << endl;
  }
  return 0;
}

ll mod_pow(ll x, ll r)
{
  if (r == 0)
    return 1;
  else if (r == 1)
    return x % mod;
  else if (r % 2 == 0)
  {
    ll t = mod_pow(x, r / 2) % mod;
    return t * t % mod;
  }
  else
  {
    ll t = mod_pow(x, r / 2) % mod;
    ll k = t * t % mod;
    return k * x % mod;
  }
}
ll mod_add(ll a, ll b)
{
  return (a + b) % mod;
}

ll mod_mul(ll a, ll b)
{
  return (a * b) % mod;
}

ll mod_div(ll a, ll b)
{
  return mod_mul(a, mod_pow(b, mod - 2));
}

void make_fact(ll n)
{
  fac[0] = 1;
  rep(i, n)
  {
    fac[i + 1] = mod_mul(fac[i], i + 1);
  }
}

void make_invfact(ll n)
{
  invfac[n] = mod_pow(fac[n], mod - 2);
  for (int i = n - 1; i >= 0; i--)
  {
    invfac[i] = mod_mul(invfac[i + 1], i + 1);
  }
}

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

int main() {
  int n;
  cin >> n;
  
  for(int i=0; i<n; i++){
    string s;
    cin >> s;
    if (s == "Y"){
      cout << "Four" << endl;
      return 0;
    }
  }
  cout << "Three" << endl;
}





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

using namespace std;

#define MAX_H 100
#define MAX_W 100

int main(){
  int H,W;
  char ch;
  int arr[MAX_H][MAX_W];
  cin >> H >> W;
  for(int i = 0 ; i < H ; i++){
    for(int j = 0 ; j < W ; j++){
      cin >> ch;
      arr[i][j] = (ch == '.' ? -1 : 0);
    }
  } 
  for(int i = 0 ; i < H ; i++){
    for(int j = 1 ; j < W ; j++){
      if(arr[i][j-1] == -1){ continue; }
      if(arr[i][j] == 0){ continue; }
      arr[i][j] = max(arr[i][j],arr[i][j-1]+1);
    }
  }
  for(int i = 0 ; i < H ; i++){
    for(int j = 0 ; j < W ; j++){
      if(j > 0){ cout << " "; }
      cout << arr[i][j];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1196
from bisect import bisect_left

N = int(input())
L = sorted([int(i) for i in input().split()])

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        ans += bisect_left(L, L[i]+L[j]) - (j + 1)

print(ans)

Measured memory_bytes: 3188
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0
for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            s = i * 500 + j * 100 + k * 50
            if s == x:
                ans += 1

print(ans)


Measured memory_bytes: 3060
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.numeric;
import std.stdio;
import std.string;

void main()
{
    string s = readln().chomp;
    long w = readln().chomp.to!long;
    for (int i = 0; i < s.length; i += w)
    {
        write(s[i]);
    }
    writeln();
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		double r = double.Parse(Console.ReadLine());
		double a = r * r * 3.141592653589;
		double b = r * 2 * 3.141592653589;
		Console.WriteLine(a.ToString("F8") + " " + b.ToString("F8"));
	}
}


Measured memory_bytes: 9220
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

vector<string> s;
int n, m, ans;

bool isin(int i, int j){
    return i >= 0 && j >= 0 && i < n && j < m;
}

void poyo(){
    int pa = ans;
    REP(i,n) REP(j,m){
        if (s[i][j] != '.') continue;
        int si[4], sj[4];
        char c[] = "....";
        int di[] = {1,0,-1,0}, dj[] = {0,1,0,-1};
        REP(k,4){
            int ii = i, jj = j;
            while (isin(ii,jj)){
                if (s[ii][jj] != '.'){
                    c[k] = s[ii][jj];
                    si[k] = ii;
                    sj[k] = jj;
                    break;
                }
                ii += di[k];
                jj += dj[k];
            }
        }
        FOR(k,1,3) REP(l,k){
            if (c[k] != '.' && c[k] == c[l]){
                ans += 2;
                s[si[k]][sj[k]] = '.';
                s[si[l]][sj[l]] = '.';
            }
        }
    }
    if (ans != pa) poyo();
}

int main() {
    cin >> n >> m;
    s.resize(n);
    REP(i,n) cin >> s[i];

    poyo();

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3288
using System;

namespace AtCoderConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            // 標準入力から1行取得
            string input = Console.ReadLine();
            int n = int.Parse(input);

            string output = "ABC";

            if (n >= 1000)
            {
                output = "ABD";
            }

            Console.WriteLine(output);
        }
    }
}


Measured memory_bytes: 11092
import math
n = int(input())
rat = [list(map(int, input().split(' '))) for _ in range(n)]
a = 1
b = 1
for i in range(n):
    x = max(-(-a//rat[i][0]), -(-b//rat[i][1]))
    a = x*rat[i][0]
    b = x*rat[i][1]
print(a+b)

Measured memory_bytes: 3188
#include <iostream>
#include <string.h>

using namespace std;

int a, b, n;

int solve()
{
	char able[n+1];
	memset(able, 0, sizeof(char)*(n+1));

	able[0] = 1;
	for(int i=0; i<=n; i++)
	{
		if(able[i]==1)
		{
			if(i+a <= n) able[i+a] = 1;
			if(i+b <= n) able[i+b] = 1;
		}
	}

	int ret = 0;
	for(int i=1; i<=n; i++)
	{
		if(able[i]==0) ret++;
	}

	return ret;
}

int main()
{
	while( 1 )
	{
		cin >> n >> a >> b;
		if(n==0 && b==0 && b==0) break;

		int ans = solve();
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 0
def main():
    n, m = map(int, input().split())
    ans = 10 ** 10
    m1, m2 = m // 2, m - m // 2
    for i in range(1, n):
        S = i * m, m1 * (n - i), m2 * (n - i)
        ans = min(ans, max(S) - min(S))
    n1, n2 = n // 2, n - n // 2
    for i in range(1, m):
        S = i * n, n1 * (m - i), n2 * (m - i)
        ans = min(ans, max(S) - min(S))
    if n % 3 == 0 or m % 3 == 0: ans = 0
    if n > 2: ans = min(ans, m)
    if m > 2: ans = min(ans, n)
    assert(ans != 10 ** 10)
    print(ans)
main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include<functional>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector<int > v(N);
  vector<int > sumv(N);
  int sum = 0;
  REP(i, N) {
    cin >> v[i];
    sum += v[i]; 
  }
  // cout << "sum =" << sum <<  endl;
  int sum1 = 0;
  int sum2 = 0;
  REP(i, N){
    sum1 += v[i];
    // cout << "sum1, sum2 = " <<sum1 <<"," <<sum2<<  endl;
    if(2*sum1  - sum >= 0){
      cout << min(abs(sum - 2*sum1), abs(sum - 2*sum2)) << endl;
      break;
    }
    sum2 = sum1;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll = long long;
using  INT = long long;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define ALL(x) x.begin(),x.end()

#define INF (int)1e9 //10^9:∞
#define LLINF (long long)1e12
#define MOD (int)1e9+7 //10^9+7:合同式の法
#define PI 3.141592653589

#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define Graph vector<vector<int>>
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VPII vector<pair<int,int>>

#define DDD fixed<<setprecision(10)

using namespace std;
/*........................................DEFINE FUNCTIONS.........................................*/


/*....................................DEFINE GLOBAL VARIABLES .....................................*/



/*.........................................kemkemG0................................................*/
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);


	string S;
	cin>>S;
	int ans=0;
	int cnt0,cnt1;
	cnt0=cnt1=0;
	if(S.size()==1)ans=0;
	else{
		REP(i,S.size()){
			if(S[i]=='0')cnt0++;
			else cnt1++;
		}
		ans=2*min(cnt0,cnt1);
	}

	cout<<ans<<endl;















	return 0;
}













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

int main(){

    double x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;

    double ans = sqrt((x1 - x2) * (x1 - x2) +(y1 - y2) * (y1 - y2));

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

    return 0;
}


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

int main(){

  double a,b;

  while(scanf("%lf",&a) != EOF){
    
    scanf("%lf",&b);

    if(a < 35.5 && b < 71) printf("AAA\n");
    else if(a < 37.5 && b < 77) printf("AA\n");
    else if(a < 40 && b < 83) printf("A\n");
    else if(a < 43 && b <  89) printf("B\n");
    else if(a < 50 && b <  105) printf("C\n");
    else if(a < 55 && b <  116) printf("D\n");
    else if(a < 70 && b <  148) printf("E\n");
    else printf("NA\n");

  }

  return (0);
}

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

int a, b;

void solve() {
  if (a % 2 == 1 && b % 2 == 1) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return;
}
int main() {
  cin >> a >> b;

  solve();

  return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    B = [int(x) for x in input().split()]
    A = [0] * N
    A[0] = B[0]
    A[N-1] = B[-1]
    for i in range(1, N-1):
        if B[i - 1] <= B[i]:
            A[i] = B[i - 1]
        else:
            A[i] = B[i]
    print(sum(A))


if __name__ == "__main__":
    main()


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

using ll=long long;
using vll=vector<ll>;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vpii=vector<pii>;


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

    int n;
    cin >> n;
    cout << (n-2)*180 << endl;
}


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

using namespace std;

int main() {
    int N, a, preA = -1, nextA = -1, cnt = 0;

    scanf("%d", &N);

    for(int i = 0; i < N; i++) {
        scanf("%d", &a);
        if(a == preA) {
            cnt++;
            scanf("%d", &preA);
            i++;
        }
        else {
            preA  = a;
        }
    }

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

    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

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

using namespace std;

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

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int main() {
	int N;
	string S;
	cin >> N;
	cin >> S;
	int left[2], right[2];

	// 初期値
	REP(i, 2) left[i] = 0, right[i] = 0;
	REP(i, S.size()) {
		if (S[i] == 'W') right[0]++;
		else right[1]++;
	}

	// 最初の一人目がリーダーの場合
	if (S[0] == 'W') right[0]--;
	else right[1]--;
	int ans = right[1] + left[0];

	// リーダーを全探索
	REPS(i, 1, S.size()) {

		char c_current = S[i];
		if (c_current == 'W') right[0]--;
		else right[1]--;
		
		char c_back = S[i - 1];
		if (c_back == 'W') left[0]++;
		else left[1]++;

		int people_num = right[1] + left[0];
		//cout << left[0] << left[1] << right[0] << right[1] << endl;
		ans = min(ans, people_num);
	}
	cout << ans;
	system("pause");
	return 0;
}

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

int main(){
	string s;
	int n, k;
	cin >> n;
	cin >> s;
	cin >> k;
	for(int i = 0; i < n; i++){
		if(s[i] != s[k-1]) s[i] = '*';
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
//typedef long long int;
typedef long long ll;
//typedef pair<int, int> P;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;

int main()
{
    int n;
    cin >> n;
    
    if(n == 22) cout << "Christmas Eve Eve Eve" << endl;
    else if(n == 23) cout << "Christmas Eve Eve" << endl;
    else if(n == 24) cout << "Christmas Eve" << endl;
    else cout << "Christmas" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main(void)
{
    int n;
    while (cin >> n)
    {
        int p[n + 1];
        for (int i = 0; i < n + 1; i++)
        {
            p[i] = 1;
        }
        p[0] = 0;
        p[1] = 0;
        for (int i = 2; i <= sqrt(n); i++)
        {
            for (int j = 2; i * j <= n; j++)
            {
                p[i * j] = 0;
            }
        }
        int c = 0;
        for (int i = 0; i <= n; i++)
        {
            if (p[i] == 1)
            {
                c++;
            }
        }
        cout << c << endl;
    }
}



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

namespace _1_7_c
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] a = Console.ReadLine().Split(' ');
            int r = int.Parse(a[0]);
            int c = int.Parse(a[1]);
            int s = r + 1; //各列最後の行
            int d = c + 1; //各行最後の列

            int[,] array = new int[s,d];

            for (int i = 0; i < r; i++)//4回
            {
                string[] t = Console.ReadLine().Split(' ');//1行読む
                for (int k = 0; k < c; k++)//1行読んだ配列を列ごとに処理
                {
                    array[i, k] = int.Parse(t[k]);
                }
            }
            //1行を合計するメソッド
            for (int j = 0; j < r; j++)//4行分ループ
            {
                for (int l = 0; l < c; l++)//5列分ループ
                {
                    array[j, c] += array[j, l];
                }
            }
            //1列を合計するメソッド
            for (int n = 0; n < d; n++)//6列分ループ
            {
                for (int m = 0; m < r; m++)//4行分ループ
                {
                    array[r, n] += array[m, n];
                }
            }
            //出力メソッド
            for (int o = 0; o < s; o++)//5列分ループ
            {
                for (int p = 0; p < d; p++)//6行分ループ
                {
                    Console.Write(array[o,p]);//1要素
                    

                    if (p != d - 1)
                    {
                        Console.Write(' ');//空白
                    }
                }
                Console.Write('\n');//改行
            }
            Console.ReadKey();
        }
    }
}



Measured memory_bytes: 17820
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string,int>;
const double PI = acos(-1);
int main() {
  string sa,sb,sc;
  cin >> sa >> sb >> sc;
  char turn  = 'a';
  while(true){
    if(turn == 'a'){
      if(sa == ""){
        cout << "A" << endl;
        return 0;
      }
      turn = sa.front();
      sa.erase(sa.begin());
      
    } 
    else if(turn == 'b'){
      if(sb == ""){
        cout << "B" << endl;
        return 0;
      }
      turn = sb.front();
      sb.erase(sb.begin());
      
    }
    else{
      if(sc == ""){
        cout << "C" << endl;
        return 0;
      }
      turn = sc.front();
      sc.erase(sc.begin());
      
    }
  }
  
}



Measured memory_bytes: 3584
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;


int main(){
  ios::sync_with_stdio(false);
  string S;
  cin >> S;

  bool same = false;
  if(S[0] == S[S.size()-1]) same = true;

  if(same){ //奇数長なら負ける
    if(S.size() % 2 == 0) cout << "First" << endl;
    else cout << "Second" << endl;
  }else{ //偶数長なら負ける
    if(S.size() % 2 != 0) cout << "First" << endl;
    else cout << "Second" << endl;
  }
    
  return 0;
}



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

using namespace std;

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

  for( int i = n; i >= 1; i-- ) {
    if( a % i == 0 && b % i == 0 ) {
      --k;
      if( k == 0 ) {
        cout << i << endl;
        break;
      }
    }
  }
  return 0;
}

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}

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

int main(){
    bool flag=false;
    ll ans=-1*INF,sum=0;

    int n;
    int joi[5][2]={};
    int shop[110][5][2]={};
    int p[110][11]={};


    cin >>n;
    rep(i,n){
        rep(j,5){
            cin>>shop[i][j][0]>>shop[i][j][1];
        }
    }
    rep(i,n){
        rep(j,11){
            cin>>p[i][j];
        }
    }


    rep1(j,1,(1<<10)){
        
        int jnow=j;

        rep(d,5){
            joi[d][0]=jnow%2; jnow/=2;
            joi[d][1]=jnow%2; jnow/=2;
        }

        int pnow=0;
        rep(s,n){
            int cnow=0;
            rep(d,5){
                if(shop[s][d][0] == joi[d][0] && joi[d][0]==1)cnow++;
                if(shop[s][d][1] == joi[d][1] && joi[d][1]==1)cnow++;
            }

            pnow += p[s][cnow];
        }
        chmax(ans,pnow);
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    cout<<ans<<endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#define DEBUG 0

/**
 * File    : D3.cpp
 * Author  : Kazune Takahashi
 * Created : 2/16/2019, 11:46:09 PM
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(10101010));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef long long ll;

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

// const int C = 1e6+10;

const int H[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

int N, M;
int A[10];
int DP[100010];

int main()
{
  cin >> N >> M;
  for (auto i = 0; i < M; i++)
  {
    cin >> A[i];
  }
  sort(A, A + M);
  reverse(A, A + M);
  fill(DP + 1, DP + 100010, -1);
  DP[0] = 0;
  for (auto i = 0; i < N; i++)
  {
    if (DP[i] == -1)
    {
      continue;
    }
    else
    {
      for (auto j = 0; j < M; j++)
      {
        DP[i + H[A[j]]] = max(DP[i + H[A[j]]], DP[i] + 1);
      }
    }
  }
  assert(DP[N] > 0);
  int ind = 0;
  while (N > 0)
  {
    assert(ind < M);
    if (N - H[A[ind]] >= 0 && DP[N] - 1 == DP[N - H[A[ind]]])
    {
      cout << A[ind];
      N -= H[A[ind]];
    }
    else
    {
      ind++;
    }
  }
  cout << endl;
}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-
"""
Created on Fri Aug  9 21:30:56 2019

@author: Yamazaki Kenichi
"""

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

highest = 0

ans = 'Yes'
for i in range(N):
    if H[i] < highest - 1:
        ans = 'No'
    if H[i] > highest:
        highest = H[i]

print(ans)

Measured memory_bytes: 15020
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
add = 0
a1 = a[:-1]
for i, m in enumerate(a1):
    if m+1 == a[i+1]:
        add += c[m-1]
print(sum(b)+add)

Measured memory_bytes: 3064
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
import itertools
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

N = I()

A = LI()

cnt = 0
for i in range(N):
    if (i+1) % 2 != 1:
        continue
    
    if A[i] % 2 == 1:
        cnt += 1

print(cnt)


Measured memory_bytes: 27088
//PKMKB
#include <bits/stdc++.h>
#define ll long long int
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define scanarr(a,b,c) for( i=b;i<c;i++)cin>>a[i]
#define showarr(a,b,c) for( i=b;i<c;i++)cout<<a[i]<<' '
#define ln cout<<'\n'
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 1000000007
#define MAX 100005
using namespace std;
////////////////////////////////////////////////////////////////CODE STARTS HERE////////////////////////////////////////////////////////////////

void solve(){
	
	int L, R , d, c = 0;

	cin >> L >> R >> d;

	for(int i = L; i <= R; i++)
		if(i % d == 0)
			c++;
	
	cout << c << endl;
}
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	#endif
	

		solve();
}

Measured memory_bytes: 3628
#pragma region noncode
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SORT(v) sort(all(v))
#define TROS(v) sort(all(v), std::greater<Type>());
#pragma endregion

int main() {
    // template
    string s;cin>>s;
    int res = 700;
    rep(i,3){
        if(s.at(i)=='o') res+=100;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 3628
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String az = "abcdefghijklmnopqrstuvwxyz";
    
    for(int i =0; i < az.length() ;i++){
      String f = az.substring(i,i+1);
      if(s.contains(f) == false){
        System.out.println(f);
        System.exit(0);
      }
    }
    System.out.println("None");
  }
}

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


int main() {
  int a; cin >> a;
  string s; cin >> s;
  if(a >= 3200)cout << s << endl;
  else cout << "red" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    for(int i=0; i<N-1; i++){
        int j = N-1-i;
        long long ub = -C * i + D * j;
        long long lb = -D * i + C * j;
        if(lb <= B-A && B-A <= ub){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <functional>

using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	int n;
	vector<int> l;
	cin >> n;
	l.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> l[i];
	}
	int sum = 0;
	int max = *max_element(l.begin(), l.end());
	for (int i = 0; i < n; i++) {
		sum += l[i];
	}
	sum = sum - max;

	if (sum <= max) {
		cout << "No";
	}
	else {
		cout << "Yes";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FSP(x) fixed << setprecision(x)
using namespace std;
using ll = long long;
constexpr ll INF = LLONG_MAX;
constexpr long double PI = acosl(-1);
void Yes() {cout << "Yes\n";}
void No() {cout << "No\n";}
void YES() {cout << "YES\n";}
void NO() {cout << "NO\n";}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//constexpr ll P = 1e9 + 7;
	//constexpr ll P = 998244353;

	ll n;
	cin >> n;
	vector<ll> p(n);
	for (ll i = 0; i < n; i++) cin >> p[i];

	vector<ll> idx(n + 1);
	for (ll i = 0; i < n; i++) idx[p[i]] = i;

	set<ll> st;
	ll ans = 0;
	for (ll i = n - 1; i > 0; i--) {
		st.insert(idx[i + 1]);
		ll subans1, subans2;
		auto r = st.lower_bound(idx[i]);
		if (r != st.end()) {
			auto rr = r; rr++;
			if (rr != st.end()) subans2 = (*rr) - (*r);
			else subans2 = n - (*r);
			if (r != st.begin()) {
				auto l = r; l--;
				subans1 = idx[i] - (*l);
			} else subans1 = idx[i] + 1;
			ans += i * subans1 * subans2;
		}
		if (r != st.begin()) {
			auto l = r; l--;
			if (l != st.begin()) {
				auto ll = l; ll--;
				subans1 = (*l) - (*ll);
			} else subans1 = (*l) + 1;
			if (r != st.end()) subans2 = (*r) - idx[i];
			else subans2 = n - idx[i];
			ans += i * subans1 * subans2;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 9412
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class D
{
	public static void Main()
	{
		int N = GetInt();
		long Z = GetLong();
		long W = GetLong();
		long[] a = new long[N];
		for(int i = 0; i < N; i++)
			a[i] = GetLong();

		if(N == 1)
			Console.WriteLine(Math.Abs(a[N-1] - W));
		else
			Console.WriteLine(Math.Max(Math.Abs(a[N-1] - W), Math.Abs(a[N-1] - a[N-2])));
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}





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

int read()
{
	int ans=0;
	char ch=getchar();
	for(;(ch<'0' || ch>'9') && ch!='-';ch=getchar());
	bool flag=0;
	if(ch=='-')flag=1,ch=getchar();
	for(;ch>='0' && ch<='9';ch=getchar())ans=ans*10+ch-'0';
	if(flag)ans=-ans;
	return ans;
}

long long rell()
{
	long long ans=0;
	char ch=getchar();
	for(;(ch<'0' || ch>'9') && ch!='-';ch=getchar());
	bool flag=0;
	if(ch=='-')flag=1,ch=getchar();
	for(;ch>='0' && ch<='9';ch=getchar())ans=ans*10ll+(long long)(ch-'0');
	if(flag)ans=-ans;
	return ans;
}

void writ(int n)
{
	char ch[25];
	int m=0;
	if(n<0)putchar('-'),n=-n;
	if(n==0)
	{
		putchar('0');
		return;
	}
	for(;n;n/=10)ch[m++]=n%10ll+'0';
	for(;m;)putchar(ch[--m]);
}

void wrll(long long n)
{
	char ch[25];
	int m=0;
	if(n<0)putchar('-'),n=-n;
	if(n==0)
	{
		putchar('0');
		return;
	}
	for(;n;n/=10ll)ch[m++]=n%10ll+'0';
	for(;m;)putchar(ch[--m]);
}
const int N=1<<20;
long long an[N];

struct node
{
	int x,y,z;

	bool friend operator < (node a,node b)
	{
		return a.x-a.y>b.x-b.y;
	}
}a[N];

int main()
{
	int x,y,z;
	scanf("%d%d%d",&x,&y,&z);
	int n=x+y+z;
	for(int i=0;i<n;i++)
	{
		scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].z);
	}
	sort(a,a+n);
	/*for(int i=0;i<n;i++)
	{
		printf("%d %d %d\n",a[i].x,a[i].y,a[i].z);
	}*/
	static priority_queue<int> xq;
	long long ans=0;
	for(int i=0;i<x+z;i++)
	{
		xq.push(a[i].z-a[i].x);
		ans+=a[i].x;
		if(i>=x)
		{
			ans+=xq.top();
			xq.pop();
		}
		an[i]=ans;
		//printf("i=%d ans=%I64d\n",i,ans);
	}
	static priority_queue<int> yq;
	ans=0;
	long long out=0;
	for(int i=n-1;i>=x;i--)
	{
		yq.push(a[i].z-a[i].y);
		ans+=a[i].y;
		if(i<x+z)
		{
			ans+=yq.top();
			yq.pop();
		}
		out=max(out,an[i-1]+ans);
		//printf("i=%d ans=%I64d\n",i,ans);
	}
	wrll(out);
	puts("");
	return 0;
}


Measured memory_bytes: 4112
function sl(n){
	if(n%2===0){
		return 2;
	}
	for(var i=3;i*i<=n;i+=2){
		if(n%i===0){
			return i;
		}
	}
	return n;
}
var a=[2,3];
for(var i=1,l=50024;i*6+1<l;i++){
	var o=i*6-1,p=i*6+1;
	sl(o)===o&&a.push(o);
	sl(p)===p&&a.push(p);
}
var l=a.length;
process.stdin.on("data",function(c){
	(c+"").trim().split("\n").some(function(n){
		n=+n;
		for(var i=0;i<l;i++){
			if(n<a[i]){
				console.log((a[i-1]===n?a[i-2]:a[i-1]),a[i]);
				break;
			}
		}
	});
}).resume();

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

const ll mod = 998244353;
ll dp[3030][3030];

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    dp[a][b] = 1;
    for (ll x = a; x <= c; x++) {
        for (ll y = b; y <= d; y++) {
            dp[x][y] += dp[x - 1][y] * y % mod;
            dp[x][y] %= mod;
            dp[x][y] += dp[x][y - 1] * x % mod;
            dp[x][y] %= mod;
            dp[x][y] -= dp[x - 1][y - 1] * (x - 1) * (y - 1) % mod;
            dp[x][y] += mod;
            dp[x][y] %= mod;
        }
    }
    // rep(i, c) {
    //     rep(j, d) {
    //         cout << dp[i + 1][j + 1] << " ";
    //     }
    //     cout << endl;
    // }

    cout << dp[c][d] << endl;
}

Measured memory_bytes: 74544
package main
 
import (
    "bufio"
    "fmt"
    "os"
    "strconv"
)

func main(){
    for {
        H := nextInt()
        W := nextInt()
        if H == 0 && W == 0 {
            break
        }
        line := ""
        for i := 0; i < W; i++ {
            line += "#"
        }
        for i := 0; i < H; i++ {
            fmt.Println(line);
        }
        fmt.Println("");
    }    
}
 
/* templates */
 
func Max(a []int) int {
    r := a[0]
    for i := 0; i < len(a); i++ {
        if r < a[i] {
            r = a[i]
        }
    }
    return r
}
 
func Min(a []int) int {
    r := a[0]
    for i := 0; i < len(a); i++ {
        if r > a[i] {
            r = a[i]
        }
    }
    return r
}
 
func Sum(a []int) (r int) {
    for i := range a {
        r += a[i]
    }
    return r
}
 
func Abs(a float64) float64 {
    if a < 0 {
        return -a
    }
    return a
}
 
type Pair struct {
    a, b int
}
 
type Pairs []Pair
 
func (p Pairs) Len() int {
    return len(p)
}
 
func (p Pairs) Swap(i, j int) {
    p[i], p[j] = p[j], p[i]
}
 
func (p Pairs) Less(i, j int) bool {
    return p[i].b < p[j].b
}
 
var nextReader func() string
 
func init() {
    nextReader = NewScanner()
}
 
func NewScanner() func() string {
    r := bufio.NewScanner(os.Stdin)
    r.Buffer(make([]byte, 1024), int(1e+11))
    r.Split(bufio.ScanWords)
    return func() string {
        r.Scan()
        return r.Text()
    }
}
 
func nextString() string {
    return nextReader()
}
 
func nextInt64() int64 {
    v, _ := strconv.ParseInt(nextReader(), 10, 64)
    return v
}
 
func nextInt() int {
    v, _ := strconv.Atoi(nextReader())
    return v
}
 
func nextInts(n int) []int {
    r := make([]int, n)
    for i := 0; i < n; i++ {
        r[i] = nextInt()
    }
    return r
}
 
func nextFloat64() float64 {
    f, _ := strconv.ParseFloat(nextReader(), 64)
    return f
}


Measured memory_bytes: 1116
//#include<iostream>
//#include<algorithm>
//#include<string>
//#include <cmath>
//#include <vector>
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define REP(x,n) for(int x=0;x<n;x++)

// vector 操作  vector<int> data(10,5) 5が10個　data(10) 要素数10
// v.size(), v.empty(), v.insert(itr,値), v.erase(itr) (first,last),
// sort(itr), find(all(x),値),reverse(itr),accumulate(itr,0) 積算,
//v.swap
// stringも同じ itrがただの数字になる
// s.substr(n,m)n番目以降m文字取り出す　erase(n,m)も  s.find
#define vei vector<int> 
#define velli vector<long long int> 
#define pb(x) push_back(x) // 末尾にxを加える
#define pb2 pop_back() // 末尾削除
#define all(x) (x).begin(),(x).end() //イテレーター
#define be(x) (x).begin()
//auto  auto begin = v.begin()とか

// map 操作  map<string,int> mp キー=string 値=int型  pair< , >型
// 代入:mp["abc"]=123  mp.erase(キー)
// itr = mp.begin()のとき　itr->first = key, itr->second = val
// mp.find(key) itrを返す
typedef pair<int,int> P;  //q(p.first,p.second)で定義できる？

// lcm( , ) gcd( , ) 最大公約数　最小公倍数
//if(cin.eof()) break; 入力数が決まってないとき
//ifstream  whilwee(ifs>>data)

// 浮動小数点
// cout << fixed; 以下と組fみ合わせで小数点以下n桁
// cout << setprecision(n) << 値; n桁表記
// defaultfloat

struct Card{char suit; 
            int value;
            };

void BubbleSort(vector<Card>& a,int n){
    int i = 0; // 先頭インデックス
    // int cou = 0;
    int flag = 1;
    for(i=0;flag;i++){
        while(flag){
            flag = 0;
            for(int j=n-1;j>=i+1;j--){
                if(a[j-1].value > a[j].value){
                    Card t = a[j];
                    a[j]=a[j-1];
                    a[j-1]=t;
                    // cou++;
                    flag = 1;
                }
            }
        }
    }
    // return cou;
}

void SelectionSort(vector<Card>& a,int n){
    
    // int count=0;
    for(int i=0;i<n;i++){
        int minj = i;
        for(int j=i;j<n;j++){
            if(a[minj].value > a[j].value){
                minj = j;
            }
        }
        swap(a[minj],a[i]);
        // if(minj!=i){
        //     // count++;
        // }
    }
    // return count;
}

bool isStable(vector<Card>& c1,vector<Card>c2, int n){
    for(int i=0;i<n;i++){
        if(c1[i].suit != c2[i].suit){
            return false;
        } 
    }
    return true;
}

int main (){
    int n;
    cin >> n;
    vector<Card> c1(n);
    vector<Card> c2(n);

    REP(i,n){
        cin >> c1[i].suit >> c1[i].value;
    }
    c2 = c1;

    BubbleSort(c1,n);
    SelectionSort(c2,n);

    REP(i,n-1){
        cout << c1[i].suit << c1[i].value << " ";
    }
    cout << c1[n-1].suit << c1[n-1].value << endl;
    cout << "Stable" << endl;

     REP(i,n-1){
        cout << c2[i].suit << c2[i].value << " ";
    }
    cout << c2[n-1].suit << c2[n-1].value << endl;
    if(isStable(c1,c2,n)){
        cout << "Stable" << endl;
    }else{
        cout << "Not stable" << endl;
    }
}


Measured memory_bytes: 3152
#include <iostream>
#include <vector>
#include <numeric>
#include <functional>

//using namespace std;
using namespace std;

int main()
{
  int c[3][3] = { 0 };

  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++)
      cin >> c[i][j];
   
  bool endFlag = false;

  for (int a0 = 0; a0 < 101; a0++)
  {
    for (int a1 = 0; a1 < 101; a1++)
    {
      for (int a2 = 0; a2 < 101; a2++)
      {
        //3 * 3 のグリッドに対する処理
        int a[3] = { a0, a1, a2 };
        int b[3] = { 0 };

        //全iに対してのb[j]を決める
        int bmCount = 0;

        auto Match3Elems = [&](int j) -> bool
        {
          if (c[0][j] - a[0] == c[1][j] - a[1] && c[1][j] - a[1] == c[2][j] - a[2])
            return true;
          else
            return false;
        };

        for (int j = 0; j < 3; j++)
          if (Match3Elems(j)) bmCount++; //3つのb[j]がそれぞれ一致しているか

        if (bmCount == 3)
        {
          b[0] = c[0][0] - a[0];
          b[1] = c[0][1] - a[0];
          b[2] = c[0][2] - a[0];

          int cmCount = 0;
          for (int i = 0; i < 3; i++)
            for (int j = 0; j < 3; j++)
              if (c[i][j] == a[i] + b[j]) cmCount++;

          if (cmCount == 9)
          {
            endFlag = true;
            break;
          }
        }

      }
    }
  }

  if (endFlag) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
A = []
for i in range(5):
  A.append(int(input()))
B = list(map(lambda x : (int((x - 1) // 10) + 1) * 10, A))
C = list(map(lambda x : int((x - 1) % 10), A))
ans = sum(B) - 9 + min(C)
print(ans)

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;

set<int>G[111111],H[111111];

int par[111111];
int find(int x){
    return x==par[x]?x:par[x]=find(par[x]);
}

signed main(){
    scanf("%lld",&N);
    rep(i,N-1){
        int a,b;
        scanf("%lld%lld",&a,&b);
        a--;b--;
        G[a].insert(b);
        G[b].insert(a);
    }

    queue<pint>que;

    rep(i,N-1){
        int c,d;
        scanf("%lld%lld",&c,&d);
        c--;d--;
        H[c].insert(d);
        H[d].insert(c);

        if(G[c].find(d)!=G[c].end())que.push({c,d});
    }

    rep(i,N)par[i]=i;

    rep(i,N-1){
        if(que.size()==0){
            cout<<"NO"<<endl;
            return 0;
        }

        int u,v;
        tie(u,v)=que.front();
        que.pop();

        u=find(u);
        v=find(v);

        if(G[u].size()+H[u].size()>G[v].size()+H[v].size())swap(u,v);


        for(auto a:G[u]){
            if(H[v].find(a)!=H[v].end()){
                que.push({v,a});
            }
        }
        for(auto a:H[u]){
            if(G[v].find(a)!=G[v].end()){
                que.push({v,a});
            }
        }

        G[u].erase(v);G[v].erase(u);
        H[u].erase(v);H[v].erase(u);

        for(auto a:G[u]){
            G[a].erase(u);
            G[a].insert(v);
            G[v].insert(a);
        }
        for(auto a:H[u]){
            H[a].erase(u);
            H[a].insert(v);
            H[v].insert(a);
        }

        par[u]=v;
    }
    cout<<"YES"<<endl;
    return 0;
}


Measured memory_bytes: 30848
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <bitset>
#include <queue>

#define pb push_back
#define ins insert
#define pob pop_back
#define er erase
#define emp empty
#define f first
#define s second
#define ff f.f
#define fs f.s
#define sf s.f
#define ss s.s
#define var auto
#define M int main()
#define For(itr,max) for(int itr = 0;itr <= max;itr++)

using namespace std;
template<typename  T>
using s = set<T>;
template<typename T>
using  v = vector<T>;
template<typename T1, typename  T2>
using p = pair < T1, T2>;
typedef p<int, int> pii;
typedef v<int> vi;
typedef v<pii> vpii;
typedef s<int> si;
typedef s<pii> spii;
typedef long long ll;


//const int Max = 1e8 + 10;
const int Mx = 1e5;
ll n, k;
ll H[Mx];
ll dp[Mx];
int main()
{
	cin >> n;
    k = 2;
	for (int i = 0; i < n; i++)
	{
		cin >> H[i];
	}

	dp[n - 1] = 0;
	for (int i = n - 1; i--;)
	{
		dp[i] = 1e18;
		for (int j = 1; j <= k; j++)
		{
			if (i + j == n)
				break;
			dp[i] = min(dp[i], dp[i + j] + abs(H[i] - H[i + j]));
		}
	}

	cout << dp[0];
}

Measured memory_bytes: 1792
import sys
INF = 10 ** 9
MOD = 10 ** 9 + 7
from collections import deque
sys.setrecursionlimit(100000000)
input = sys.stdin.readline

def main():
    n,z,w = map(int,input().split())
    a = list(map(int,input().split()))
    if n == 1:
        ans = abs(w - a[0])
    else:
        ans = max(abs(w - a[-1]),abs(a[-1] - a[-2]))
    print(ans)

if __name__=='__main__':
    main()

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

int main(){
  int n;
  cin >> n;
  int *a = new int[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=0;i<n;i++){
    if(a[i]%2 == 1)continue;
    if(a[i]%3 != 0 && a[i]%5 != 0){
      cout << "DENIED" << endl;
      return 0;
    }
  }
  cout << "APPROVED" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define INF 1e18

long long min(long long a,long long b){
  if(a < b){
    return a;
  }
  return b;
}

int main(void){
  int N;
  long long x;
  scanf("%d%lld", &N, &x);

  long long a[N];
  for (int i = 0; i < N; i++) {
    scanf("%lld", &a[i]);
  }

  long long ans = INF;
  long long b[N][N+1];
  for (int i = 0; i < N; i++) {
    b[i][0] = a[i];
  }

  for (int k = 0; k < N; k++) {
    long long sum = 0;
    for (int i = 0; i < N; i++) {
      b[i][k+1] = min(b[i][k], a[i-k >= 0?i-k:N+(i-k)]);
      sum += b[i][k+1];
    }
    ans = min(ans, sum+k*x);
  }

  printf("%lld\n", ans);
  
  return 0;
}

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

int main(void)
{
    int H,W;
    while(true){
        cin>>H>>W;
        if(H==0 && W==0){
            break;
        }
        for(int j=0;j<W;j++){
            cout<<'#';
        }
        cout<<endl;
        for(int i=1;i<H-1;i++){
            cout<<'#';
            for(int j=1;j<W-1;j++){
                cout<<'.';
        }
        cout<<'#'<<endl;
        }
        for(int j=0;j<W;j++){
            cout<<'#';
        }
        cout<<endl<<endl;
    }
}


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

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> x(n);
  vector<int> r(n-k+1);
  
  for(int &e: x)cin >> e;
  
  for(int i=0; i<n-k+1; i++){
    int a = x.at(i);
    int b = x.at(i+k-1);
    if(a<0 && b<0) r.at(i) = -a;
    if(a<0 && b>0 && -a>b) r.at(i) = -a+2*b;
    if(a<0 && b>0 && -a<=b) r.at(i) = -2*a+b;
    if(a>0 && b>0) r.at(i) = b;
  }
  
  cout << *min_element(r.begin(), r.end()) << endl;
}

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

const int MAX = 1e5+10;
int n, m;
bool visit[MAX];
vector<int>adj[MAX];
int npai[MAX];
int memo[MAX];

int pd(int i) {
    //cout<<"testando com "<<i<<endl;
    //visit[i] = true;
    int ans = 0;
    if(memo[i] != -1) return memo[i];
    if(adj[i].size() == 0) return 1;
    for(auto x : adj[i]) {
        if(visit[x]) continue;
        ans = max(ans, 1 + pd(x));
    }
    return memo[i] = ans;
}

int main() {
    memset(memo, -1, sizeof memo);
    cin>>n>>m;

    int saida = 0;

    for(int i = 0; i < m; i++) {
        int a, b;
        cin>>a>>b;
        adj[a].push_back(b);
        npai[b]++;
    }

    for(int i = 1; i <= n; ++i) {
        if(npai[i] == 0) {
            //cout<<"testando com "<<i<<endl;
            saida = max(saida, pd(i));
        }
    }
    if(saida > 0) cout<<saida-1<<"\n";
    else cout<<saida<<"\n";
}


Measured memory_bytes: 11136
#include<iostream>
#include<vector>

using namespace std;

class union_find{
    private:
        vector<int> parent; //parent[i]=頂点iの親
        vector<int> rank; //rank[i]=(iが根であるとき)iが属する木の長さ
        int cnt;
    public:
        union_find(int vertex_num /*頂点数*/)
        {
            parent.resize(vertex_num);
            rank.resize(vertex_num);
            cnt = vertex_num;
            /*
            　最初はすべての頂点が根なので、
            　すべての頂点に対し自分自身を親に設定する
            */
            for(int i=0;i<vertex_num;i++){
                parent[i] = i;
                //最初はすべて木の深さは0
                rank[i]=0;
            }
        }

        int get_root(int n /*根を知りたい頂点の番号*/)
        {
            if(parent[n]==n) return n;
            else return get_root(parent[n]);
        }

        bool is_same(int a,int b /*連結を判定したい2頂点*/)
        {
            return get_root(a)==get_root(b);
        }

        void unite(int a,int b /*連結したい2頂点*/)
        {
            int root_a=get_root(a),root_b=get_root(b);
            if(root_a==root_b) return;
            if(rank[root_a]<rank[root_b]){
                parent[root_a] = root_b;
            }else if(rank[root_a]>rank[root_b]){
                parent[root_b] = root_a;
            }else{ //等しいとき
                parent[root_a] = get_root(root_b);
                ++rank[root_b];
            }
            cnt--;
        }

        bool connected(){
            return cnt==1;
        }
};

int main(){
    int n,m; cin>>n>>m;
    vector<pair<int,int>> ab(m);
    for(int i=0;i<m;i++){
        int a,b; cin>>a>>b;
        a--; b--;
        ab[i]=make_pair(a,b);
    }
    int ans=0;
    for(int i=0;i<m;i++){
        union_find uf(n);
        for(int j=0;j<m;j++){
            if(i==j) continue;
            uf.unite( ab[j].first, ab[j].second );
        }
        if(!uf.connected()) ++ans;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256