akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std;

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

Node *root, *NIL;

Node * find(Node *u,int k){
    while(u != NIL && k != u->key){
        if(k < u->key) u = u->left;
        else u = u->right;
    }
    return u;
}

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

z = (Node *)malloc(sizeof(Node));
z->key = k;
z->left = NIL;
z->right = NIL;

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

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

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

int main(){
    int n,i,x;
    string com;
    scanf("%d",&n);
    for(i = 0;i < n;i++){
        cin >> com;
        if(com[0] == 'f'){
            scanf("%d",&x);
            Node *t = find(root,x);
            if(t != NIL) printf("yes\n");
            else printf("no\n");
        }else if(com == "insert"){
            scanf("%d",&x);
            insert(x);
        }else if (com == "print"){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 21948
n = int(input())
arr = list(map(int, input().strip().split()))

dp = [float('inf') for i in range(n)]
dp[0] = 0

for i in range(n-1):
    dp[i+1] = min(dp[i+1], dp[i] + abs(arr[i]-arr[i+1]))
    if i < n-2:
        dp[i+2] = min(dp[i+2], dp[i] + abs(arr[i]-arr[i+2]))

print(dp[-1])


Measured memory_bytes: 20412
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double ld;

#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rd3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define rl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define inf 10000000000000
#define mod 1000000007
#define maxn 100009
#define maxr 100009
int main(){
	//sstd::ios::sync_with_stdio(false); cin.tie(NULL);
	ll n;
	rl(n);
	string str;
	cin>>str;
	ll ct=0;
	fr(i,0,n-2)
	{
		if(str[i]=='A'&&str[i+1]=='B'&&str[i+2]=='C')
		{
			ct++;
		}
	}
	wl(ct);
	NL;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

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

  string s, t;
  cin >> s >> t;
  int a, b;
  cin >> a >> b;
  string u;
  cin >> u;

  if (s == u) a--;
  else b--;

  cout << a << " " << b;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n; cin >> n;
    int ans = 0;
    FOR(i,1,n+1) {
        FOR(j,1,n+1) {
            if (i*j < n) ans++;
            else break; 
        }
    }
    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 3648
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;


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

    long long r = 0, g = 0, b = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] == 'R') r++;
        if (S[i] == 'G') g++;
        if (S[i] == 'B') b++;
    }

    long long cnt = 0;
    for (int i = 0; i < N-2; i++) {
        for (int j = i+1; j < N-1; j++) {
            if (S[i] != S[j]) {
                int k = j + (j-i);
                if (k < N) {
                    if (S[i] != S[k] && S[j] != S[k]) {
                        cnt++;
                    }
                }
            }
        }
    }

    long long ans = r * g * b - cnt;

    cout << ans << endl;
}


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

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#define MOD 1000000007
#define INF (1ll<<60)
typedef long long ll;
using namespace std;

char a[100][100];
bool line_1[100]; //falseうめされてる
bool line_2[100];

int main(){
    int h, w;
    cin >> h >> w;
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            cin >> a[i][j];
        }
    }

    for (int i = 0; i < 100; i++){
        line_1[i] = false;
        line_2[i] = false;
    }

    for (int i = 0; i < h; i++){
        int j;
        for (j = 0; j < w; j++){
            if (a[i][j] == '#') break;
        }
        if (a[i][j] == '#') continue;
        line_1[i] = true;
    }

    for (int j = 0; j < w; j++){
        int i;
        for (i = 0; i < h; i++){
            if (a[i][j] == '#') break;
        }
        if (a[i][j] == '#') continue;
        line_2[j] = true;
    }

    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            if (line_1[i] || line_2[j]) continue;
            cout << a[i][j];
        }
        if (!line_1[i])cout << endl;
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <iomanip>


using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long N, std::vector<long long> x, std::vector<long long> y){
  vector<ll> v;
  for(int i=0; i<N; i++) {
    v.push_back(i);
  }
  double ans = 0;
  do{
    for(int i=0; i+1<N; i++) {
      ans+=sqrt((x[v[i]]-x[v[i+1]])*(x[v[i]]-x[v[i+1]])+(y[v[i]]-y[v[i+1]])*(y[v[i]]-y[v[i+1]]));
    }
  }while(next_permutation(v.begin(), v.end()));
  double xx = 1;
  for(int i=1; i<=N; i++) {
    xx*=i;
  }
  std::cout <<setprecision(10)<< ans/xx << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  std::vector<long long> x(N);
  std::vector<long long> y(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&x[i]);
    scanf("%lld",&y[i]);
  }
  solve(N, std::move(x), std::move(y));
  return 0;
}



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

int main(int argc, const char * argv[]) {
    int N;
    int H[100] = {0};
    int result = 1;
    
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> H[i];
    }
    
    for (int i = 1; i < N; i++) {
        int check = 0;
        for (int j = 0; j < i; j++) {
            if (H[j] > H[i]) {
                check = 1;
            }
        }
        if (check == 0 && H[i] >= H[i - 1]) {
            result++;
        }
    }
    
    cout << result << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long int ll;
typedef long double ld;
int main(){
  ll n,t[110],v[110],ts[110]={};
  ld a[50000]={},ans=0;
  cin>>n;
  ts[0]=0;
  for(int i=0;i<n;i++){cin>>t[i];ts[i+1]=ts[i]+t[i];}
  for(int i=0;i<n;i++) cin>>v[i];
  for(ll i=0;i<=2*ts[n];i++){
    a[i]=  min((ld)i/2,(ld)ts[n]-(ld)i/2);
    for(int j=0;j<n;j++){
      if(i < 2*ts[j]) a[i]=  min(a[i],(ld)v[j]+(ld)ts[j]-(ld)i/2);
      else if( i > 2*ts[j+1]) a[i]= min(a[i],(ld) v[j]+(ld)i/2-(ld)ts[j+1]);
      else a[i]=min(a[i],(ld) v[j]);
    }
  }
  for(int i=0;i<2*ts[n];i++){
    ans+=(a[i]+a[i+1])/4;
  }
  printf("%f",(double)ans);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
  int H, W, h, w;
  cin >> H >> W >> h >> w;

  cout << H * W - (h * W + w * H - h * w) << endl;

  return 0;
}


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

vector<int> cand[50];
int peddle;
int n,p;
int count;
int who;

int main()
{
        while(cin >> n >> p){
                if(n==0 && p==0) break;
                count = 0;
                peddle = p;
                while(true){
                        who = count % n;
                        if(peddle>0){
                                cand[who].push_back(1);
                                peddle--;                                                                                                                                                       }else if(peddle==0){
                                peddle += cand[who].size();
                                cand[who].clear();
                        }

                        if(cand[who].size()==p){
                                cout << who << endl;
                                break;
                        }

                        count++;                                                                                                                                                        }
                for(int i=0;i<n;i++) cand[i].clear();
        }                                                                                                                                                               
        return 0;
}

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

while H != 0 and W != 0:
    for i in range(H):
        if i == 0 or i%2 == 0:
            ans = []
            for k in range(W):
                if k == 0 or k%2 == 0:
                    ans.append("#")
                else:
                    ans.append(".")
            for n in range(W):
                print(ans[n],end="")
            print("")
        else:
            ans = []
            for k in range(W):
                if k == 0 or k%2 == 0:
                    ans.append(".")
                else:
                    ans.append("#")
            for n in range(W):
                print(ans[n],end="")
            print("")
    print("")
    H,W = map(int,input().split())
        



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

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  vector<int> M(N + 1);
  for(int i = 1; i < N + 1; i++) {
    for(int j = i + 1; j < N + 1; j++) {
      int tmp = min(j - i, abs(i - X) + abs(j - Y) + 1);
      M[tmp]++;
    } 
  } 
  for(int i = 1; i < N; i++) {
    cout << M[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i,k,n) for(int i = k; i < (int)(n); i++)
using namespace std;
int main(){
        int A,B,C,D;
        cin >>A>>B>>C>>D;
        int ans = min(B,D) - max(A,C);
        if(ans<0) ans = 0;
        cout << ans << endl;

        return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main
{
  public static void main(String args[])
  {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int arr[]=new int[n];
    for(int i=0;i<n;i++)
      arr[i]=sc.nextInt();
    int min=Integer.MAX_VALUE/2;
    for(int i=-100;i<=100;i++)
    {
      int sum=0;
      for(int j=0;j<n;j++)
      {
        sum+=(arr[j]-i)*(arr[j]-i);
      }
      min=Math.min(sum,min);
    }
    System.out.println(min);
  }
}

Measured memory_bytes: 23252
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int n = sc.nextInt();
		int sum = 0;
		for (int i = 0; i < n; i++) {
			sum = sum + sc.nextInt();
		}
		printBool(sum >= h);
		sc.close();
	}

	public static void print(Object obj) {
		System.out.println(obj);
	}

	public static void printBool(boolean bool) {
		print(bool ? "Yes" : "No");
	}

}


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

using namespace std;

int main(){
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<int>> A(h);
    for (auto &s: A){
        string T;
        cin >> T;
        for (const auto &t: T)
            s.push_back(t - '0');
    }
    int ans = 1e8;
    for (int bits = 0; bits < (1 << (h - 1)); bits++){
        int res = __builtin_popcount(bits);
        vector<int> S(res + 1);
        for (int j = 0; j < w; j++){
            int cur = 0;
            bool flag = false;
            for (int i = 0; i < h; i++){
                S[cur] += A[i][j];
                flag |= S[cur] > k;
                if ((bits >> i) & 1)
                    cur++;
            }

            if (flag){
                res++;
                cur = 0;
                flag = false;
                for (auto &s: S)
                    s = 0;
                for (int i = 0; i < h; i++){
                    S[cur] += A[i][j];
                    flag |= S[cur] > k;
                    if ((bits >> i) & 1)
                        cur++;
                }
                if (flag)
                    res = 1e8;
            }
        }
        ans = min(ans, res);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
"use strict";

function main(arg) {
    const input = arg.split("\n")
    const [X,Y] = input[0].split(" ").map(x=>Number(x))
    //console.log(X)
    //console.log(Y)
    
    let craneNum = 2 * X - Y/2
    let turtleNum = X - craneNum
    //console.log(`craneNum = ${craneNum}`)
    //console.log(`turtleNum = ${turtleNum}`)
    
    if(!Number.isInteger(craneNum) || craneNum < 0 || !Number.isInteger(turtleNum) || turtleNum < 0) {
        console.log("No")
    } else {
        console.log("Yes")
    }
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29620
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <fstream>
using namespace std;
double pie=3.14159265358979;
long long mod=998244353;
//
int main(){
	long long a;
	string b;
	cin>>a>>b;
	long long ans=a*(b[0]-'0');
	long long bns=a*(b[2]-'0')*10+a*(b[3]-'0');
	cout<<bns/100+ans<<endl;
	return 0;
}

Measured memory_bytes: 3152
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

int main() {
  int a, b, k;
  scan(a, b, k);
  int mi = min(a, b);
  int cnt = 0;
  for (int i = mi; i > 0; --i) {
    if (a % i == 0 && b % i == 0) {
      cnt += 1;
      if (cnt == k) {
        print(i);
        return 0;
      }
    }
  }
  assert(false);

  return 0;
}


Measured memory_bytes: 888
S = input()
black = 0
white = 0
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == '0':
            white += 1
        else:
            black += 1
    if i % 2 == 1:
        if S[i] == '1':
            white += 1
        else:
            black += 1
print(min(black, white))

Measured memory_bytes: 3188
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

int count(string& s, int i) {
  unordered_set<char> a, b;
  rep(k, i) { a.insert(s[k]); }
  REP(k, i, s.size()) { b.insert(s[k]); }
  int ret = 0;
  for (auto& x : a) {
    if (b.find(x) != b.end()) ret++;
  }
  return ret;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  string s;
  cin >> n;
  cin >> s;
  int ans = 0;
  REP(i, 1, n - 1) { ans = max(ans, count(s, i)); }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
l=[input().split() for _ in range(n)]
w=[[0]*(k+1) for _ in range(k+1)]
b=[[0]*(k+1) for _ in range(k+1)]
for i in range(n):
    if ((int(l[i][0])//k+int(l[i][1])//k)%2==0)^(l[i][2]=='W'):
        b[int(l[i][0])%k][int(l[i][1])%k]+=1
    else:
        w[int(l[i][0])%k][int(l[i][1])%k]+=1

for i in range(1,k+1):
    b[0][i]+=b[0][i-1]
    b[i][0]+=b[i-1][0]
    w[0][i]+=w[0][i-1]
    w[i][0]+=w[i-1][0]
for i in range(1,k+1):
    for j in range(1,k+1):
        b[i][j]+=b[i-1][j]+b[i][j-1]-b[i-1][j-1]
        w[i][j]+=w[i-1][j]+w[i][j-1]-w[i-1][j-1]

ans=0
for i in range(k+1):
    for j in range(k+1):
        ans=max(ans,b[k][k]-b[i][k]-b[k][j]+2*b[i][j]+w[i][k]+w[k][j]-2*w[i][j])
        ans=max(ans,w[k][k]-w[i][k]-w[k][j]+2*w[i][j]+b[i][k]+b[k][j]-2*b[i][j])
print(ans)


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

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
constexpr ll INF = 10000000000;
const ll MOD = 1000000007;

using namespace std;

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	long long g = gcd(a, b);
	return a / g * b;
}

int main() {
	ll a, b, c; cin >> a >> b >> c;
	if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {
		cout << 0 << endl;
		return 0;
	}

	vector<ll>ans(3);
	ans[0] = a * b;
	ans[1] = a * c;
	ans[2] = b * c;
	sort(ans.begin(), ans.end());
	cout << ans[0] << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
//#include<math.h>

using namespace std;
#define int long long
/*                      */    //#undef int
#define INF 1000000009
#define INFL 1000000000000000018ll
#define mod 1000000007ll
#define pb push_back
#define fi first
#define se second
#define mk make_pair
typedef pair<pair<int, int> , pair<int, int> > PA;
typedef priority_queue<int> PQ;
typedef priority_queue<PA, vector<PA>, greater<PA> >PQG;

int H, W, D;
int a[334][334];
int Q;
pair<int, pair<int, int> >sum[334 * 334];

signed main()
{
    cin >> H >> W >> D;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> a[i][j];
            sum[a[i][j]] = mk(0, mk(i, j));
        }
    }
    for(int i = 1 + D; i <= H * W; i++){
        sum[i].first = sum[i - D].first + abs(sum[i].se.fi - sum[i - D].se.fi) + abs(sum[i].se.se - sum[i - D].se.se);
    }
    cin >> Q;
    for(int i = 0; i < Q; i++){
        int l, r;
        cin >> l >> r;
        cout << sum[r].first - sum[l].first << endl;
    }

    return 0;
}
/*


*/


Measured memory_bytes: 3968
#include <stdio.h>
#include <math.h>
#include <limits.h>
#include <stdlib.h>

int cnt;

int bubbleSort(double* A, int N)
{
	int flag=1,i;
	double tmp;
	while(flag){
		flag = 0;
		
		for(i=N-1;i>0;i--){
			if(A[i]<A[i-1]){
				tmp = A[i];
				A[i]=A[i-1];
				A[i-1]=tmp;
				flag=1;
				cnt++;
			}
		}
	}
	return 0;
}

int 
main(){
	long long N;
	double vi[100];
	double srt[100];
	scanf("%lld",&N);
	long long i,j;
	for(i=0;i<N;i++){
		scanf("%lf",&vi[i]);
	}
	
	bubbleSort(vi, N);
	double rtn;
	for(i=0;i<N-1;i++){
		vi[i+1] = (vi[i]+vi[i+1])/2.;
	}
	
	printf("%lf\n",vi[N-1]);
 return 0;
}

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

class Main {
  public static void main(String[] args) throws Exception{
    try (Scanner sc = new Scanner(System.in)){
      Integer[] list = new Integer[3];
      list[0] = sc.nextInt();
      list[1] = sc.nextInt();
      list[2] = sc.nextInt();
      Arrays.sort(list, Collections.reverseOrder());
      int cost = 0;
      int pre = list[0];
      for (int i = 1; i < list.length; i++) {
        cost += pre - list[i];
        pre = list[i];
      }
      System.out.println(cost);
    }
  }
}


Measured memory_bytes: 22996
/*
 *  I wish I could travel by the road that crosses baby's mind,
 *  and out beyond all bounds;
 *  Where messengers run errands for no cause
 *  between the kingdoms of kings of no history;
 *  Where Reason makes kites of her laws and flies them,
 *  and Truth sets Fact free from its fetters.
 *                                           Rabindranath Tagore
 */

#include <bits/stdc++.h>
using namespace std;

#ifndef ORZ_EVERYBODY_BUT_ME
#define ORZ_EVERYBODY_BUT_ME
#endif

#ifndef SOCIALISM
#define SOCIALISM
#endif

typedef pair<int, int> ii;
const int HASH1 = 1e9 + 7,
          HASH2 = 1e9 + 9;
#define fi first
#define se second

char str[15][15];
int lines[15], h, w;
bool matched[15];
ii dvec[15], uvec[15];

inline void match() {
    for (int i = 0, j, k, _ = w >> 1; i < _; ++i)
        for (j = 0; j < w; ++j)
            if (!matched[j])
                for (k = 0; k < w; ++k)
                    if (k != j && uvec[k] == dvec[j] && !matched[k]) {
                        matched[j] = matched[k] = true;
                        break;
                    }
    for (int i = 0; i <= w; ++i)
        if (i == w) {
            puts("YES");
            exit(0);
        } else if (!matched[i]) {
            break;
        }
    for (int i = 0; i < w; ++i) matched[i] = false;
}

void check() {
    for (int i = 0, j; i < w; ++i) {
        dvec[i] = {0, 0};
        for (j = 0; j < h; ++j) {
            (dvec[i].fi *= HASH1) += str[lines[j]][i];
            (dvec[i].se *= HASH2) += str[lines[j]][i];
        }
        uvec[i] = {0, 0};
        for (j = h - 1; j >= 0; --j) {
            (uvec[i].fi *= HASH1) += str[lines[j]][i];
            (uvec[i].se *= HASH2) += str[lines[j]][i];
        }
    }
    if (w & 1) {
        for (int i = 0; i < w; ++i)
            if (dvec[i] == uvec[i]) {
                matched[i] = true;
                match();
                matched[i] = false;
            }
    } else {
        match();
    }
}

bool setted[15];

void getLines(int msk, int cur, int smallest) {
    if (cur == (h >> 1)) return check();
    while (setted[smallest] || (msk >> smallest & 1))
        ++smallest;
    lines[cur] = smallest;
    for (int i = smallest + 1; i < h; ++i)
        if (!setted[i] && (msk >> i & 1)) {
            lines[h - 1 - cur] = i;
            setted[i] = setted[smallest] = true;
            getLines(msk, cur + 1, smallest + 1);
            setted[i] = setted[smallest] = false;
        }
}

void dfs(int cur, int cnt, int msk) {
    if (cnt == (h >> 1)) return getLines(msk, 0, 0);
    if (cur == h) return ;
    if (setted[cur]) return dfs(cur + 1, cnt, msk);
    dfs(cur + 1, cnt + 1, msk | 1 << cur);
    dfs(cur + 1, cnt, msk);
}

int main() {
    scanf("%d%d", &h, &w);
    for (int i = 0; i < h; ++i) scanf("%s", str[i]);
    if (h & 1) {
        for (int i = 0; i < h; ++i) {
            setted[i] = true;
            lines[h >> 1] = i;
            dfs(0, 0, 0);
            setted[i] = false;
        }
    } else {
        dfs(0, 0, 0);
    }
    puts("NO");
    return 0;
}


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

namespace AtTest.AGC_Challenge
{
    class _001_A
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int[] ls = ReadInts();
            Array.Sort(ls);
            int res = 0;
            for(int i = 0; i < n; i++)
            {
                res += ls[i * 2];
            }
            Console.WriteLine(res);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11220
#include <iostream>
using namespace std;
long long x11,x12,x13,x21,x22,x23,x31,x32,x33;
/*             *\
   x11 x12 x13
   x21 x22 x23
   x31 x32 x33
\*             */ 
int main()
{
	cin>>x11>>x12>>x22;
	long long S=x22*3;
	x13=S-x11-x12;
	cout<<x11<<" "<<x12<<" "<<x13<<endl;
	x32=S-x12-x22;
	x31=S-x13-x22;
	x33=S-x11-x22;
	x21=S-x11-x31;
	x23=S-x21-x22;
	cout<<x21<<" "<<x22<<" "<<x23<<endl;
	cout<<x31<<" "<<x32<<" "<<x33<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>

using namespace std;

typedef long long ll;

ll a[100005], kum[100005];
map <ll, ll> br;

int main ()
{
ll n, m;
cin >> n >> m;
for(int i = 1 ; i <= n ; ++i){
	cin >> a[i];
}
br[0] = 1;
ll sol = 0;
for(int i = 1 ; i <= n ; ++i){
	kum[i] = (kum[i - 1] + a[i]) % m;
	sol += br[kum[i]];
	br[kum[i]]++;
}
cout << sol;

return 0;
}

Measured memory_bytes: 5760
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
mod=998244353
from collections import defaultdict
DX=defaultdict(int)
DY=defaultdict(int)
XY,X,Y=[],[],[]
for _ in range(n):
  x,y=map(int,input().split())
  X.append(x)
  Y.append(y)
  XY.append((x,y))
X.sort()
Y.sort()
XY.sort(key=lambda x:x[0])
for i,x in enumerate(X):
  DX[x]=i+1
for i,y in enumerate(Y):
  DY[y]=i+1
XY2=[]
for x,y in XY:
  XY2.append((DX[x],DY[y]))
A=[[0]*4 for _ in range(n)]

n_max=2*10**5
nn=n_max.bit_length()+1
BIT=[0]*(2**nn)
BIT.insert(0,0)
def bitsum(BIT,i):
  s=0
  while i>0:
    s+=BIT[i]
    i-=i&(-i)
  return s
def bitadd(BIT,i,x):
  while i<=2**nn:
    BIT[i]+=x
    i+=i&(-i)
  return BIT

for i in range(n):
  x,y=XY2[i]
  ct=bitsum(BIT,y)
  A[i][2]+=ct
  A[i][1]+=i-ct
  bitadd(BIT,y,1)

BIT=[0]*(2**nn)
BIT.insert(0,0)
for i in range(n)[::-1]:
  x,y=XY2[i]
  ct=bitsum(BIT,y)
  A[i][3]+=ct
  A[i][0]+=(n-1-i)-ct
  bitadd(BIT,y,1)

P=[0]*n
P[0]=1
for i in range(1,n):
  P[i]=(P[i-1]*2)%mod
def f(x):
  return P[x]

ans=0
for a,b,c,d in A:
  ans+=2*f(a+b+c+d)-f(a+b)-f(b+c)-f(c+d)-f(d+a)+f(a)+f(b)+f(c)+f(d)-1
  ans%=mod
print(ans)


Measured memory_bytes: 124904
#include <iostream>

using namespace std;

typedef long long ll;

main(){
  while(1){
    ll L;
    cin >> L;
    if(L==0) break;
    bool first=true;
    ll sum=0;
    for(int i=0;i<12;i++){
      ll M, N;
      cin >> M >> N;
      sum+=M-N;
      if(first && sum>=L){
	first=false;
	cout << i+1 << endl;
      }
    }
    if(first) cout << "NA" << endl;
  }
  return 0;
}

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

rs = [0] * (N+1)
ls = [0] * (N+1)

for i in range(N):
    if S[i] == 'R':
        rs[i+1] = rs[i] + 1
    if S[N-1-i] == 'L':
        ls[N-1-i] = ls[N-i] + 1

rs = rs[1:]
ls = ls[:N]

# print(rs)
# print(ls)

ans = [0] * N
for i in range(N-1):
    if S[i:i+2] == 'RL':
        t = (rs[i] + ls[i+1]) // 2
        d = abs(rs[i]-ls[i+1])
        ans[i] = ans[i+1] = t
        if d % 2 != 0:
            if rs[i] > ls[i+1]:
                if rs[i] % 2 == 0:
                    ans[i+1] += 1
                else:
                    ans[i] += 1
            else:
                if ls[i+1] % 2 == 0:
                    ans[i] += 1
                else:
                    ans[i+1] += 1

print(' '.join([str(c) for c in ans]))

Measured memory_bytes: 16196
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin>>n;
ll ac=0,wa=0,tle=0,re=0;
for(int i=0;i<n;i++)
{
    string s;
    cin>>s;
    if(s=="AC")
    {
        ac++;
    }
    else if(s=="TLE"){
            tle++;
    }
    else if(s=="WA")
    {
        wa++;
    }
    else{
        re++;
    }
}
cout<<"AC"<<" x "<<ac<<endl;
cout<<"WA"<<" x "<<wa<<endl;
cout<<"TLE"<<" x "<<tle<<endl;
cout<<"RE"<<" x "<<re<<endl;
}


Measured memory_bytes: 3612
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int a, b; string op; readV(a, op, b);
  writeln(op == "+" ? a+b : a-b);
}


Measured memory_bytes: 256
from collections import deque
H, W = map(int, input().split())
field = [list(input()) for i in range(H)]
sx, sy, gx, gy = 0, 0, H-1, W-1
x = [1, 0, -1, 0]
y = [0, 1, 0, -1]
def bfs():
    d = [[float("inf")] * W for _ in range(H)]
    d[sx][sy] = 0
    Q = deque([])
    Q.append((sx, sy))
    while Q:
        px, py = Q.popleft()
        if px==gx and py==gy:
            break
        for dx, dy in zip(x, y):
            nx = px+dx
            ny = py+dy
            if 0<=nx<H and 0<=ny<W and field[nx][ny]=='.' and d[nx][ny]==float('inf'):
                d[nx][ny]=d[px][py]+1
                Q.append((nx, ny))
    return d[gx][gy]

count = 0
for i in field:
    count += i.count('.')
res = bfs()
if 0 < res < float("inf"):
    print(count-res-1)
else:
    print(-1)

Measured memory_bytes: 9476
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int d,n,x,y,count=0;
	cin>>n>>d;
	while(n--)
	{
		cin>>x>>y;
		if(sqrt(pow(x,2)+pow(y,2))<=d)
			count++;
	}
	cout<<count<<endl;
}


Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
int n;
int a[200005];
int now[200005];
//bool check(int x){
//	int k,ans[2];
//	ans[0]=0;	ans[1]=0;
//	for(k=1;k<n+n;k++)	now[k]=a[k]>=x;

//	for(k=n-2;k>0;k--)		if(now[k]==now[k+1]){ans[now[k]]=n-k;break;}
//	for(k=n+2;k<n+n;k++)	if(now[k]==now[k-1]){ans[now[k]]=k-n;break;}
//	if(ans[0]&&ans[1])	return ans[0]<ans[1];
//	if(ans[1])	return 1;
//	if(ans[0])	return 0;
//	if(ans[0]==0&&ans[1]==0)	return now[1];	
//}
inline bool check(int x){
	int k;
	for(k=1;k<n+n;k++)	now[k]=a[k]>=x;
	if(now[n]==now[n-1]||now[n]==now[n+1])	return now[n];    
    for(k=1;k<n-1;k++){
        if((now[n+k]&&now[n+k+1])||(now[n-k]&&now[n-k-1]))return 1;
        if(!(now[n+k]||now[n+k+1])||!(now[n-k]||now[n-k-1]))return 0;
    }
    return now[1];
}
int main(){
	int k;
	cin>>n;
	for(k=1;k<=n+n-1;k++)	cin>>a[k];
	int l=1,r=n+n-1,mid;
	while(l<r){
		mid=l+r+1>>1;
		if(check(mid))	l=mid;
		else			r=mid-1;
	}
	cout<<r<<endl;
	return 0;
}

Measured memory_bytes: 1792
N, M = map(int,input().split())
PY = [list(map(int,input().split())) for i in range(M)]

PY_copy = [PY[i] + [i] for i in range(M)]
PY_copy = sorted(PY_copy, key=lambda x:(x[0],x[1]))

order = 0
previous_prefecture = PY_copy[0][0]
for i in range(M):
  if PY_copy[i][0] == previous_prefecture:
    order += 1
  else:
    previous_prefecture = PY_copy[i][0]
    order = 1
  PY_copy[i] = PY_copy[i] + [order]

PY_copy = sorted(PY_copy, key=lambda x:x[2])
## PY_copy = [P, Y, index, dict_order]

for i in range(M):
  P_zfill = str(PY_copy[i][0]).zfill(6)
  order_zfill = str(PY_copy[i][3]).zfill(6)
  print(P_zfill + order_zfill)

  

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll n,m;
ll mk[11][11],kt[11];
ll i, j, k,ans;

void dnyk(ll a,ll b){
    if(a==n){
        ans++;
        return;
    }
    if(b==n){
        if(kt[a]==(n-1)/2){
            dnyk(a + 1, a + 2);
        }
        return;
    }
    if(mk[a][b]!=2){
        kt[a]++;
        dnyk(a, b + 1);
        kt[a]--;
    }
    if(mk[a][b]!=1){
        kt[b]++;
        dnyk(a, b + 1);
        kt[b]--;
    }
}

int main(){
    
    scanf("%lld", &n);
    while(n){
        ans = 0;
        fornum(i,0,11){
            fornum(j,0,11){
                mk[i][j] = 0;
            }
        }
        scanf("%lld", &m);
        fornum(i,0,m){
            ll a, b;
            scanf("%lld%lld", &a, &b);
            mk[a-1][b-1] = 1;
            mk[b-1][a-1] = 2;
        }
        dnyk(0, 1);
        printf("%lld\n", ans);
        scanf("%lld", &n);
    }
    return 0;
}


Measured memory_bytes: 3200
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		String s;
		Scanner sc = new Scanner(System.in);
		s = sc.next();
		int[] ret = new int[s.length()];
		for(int i = 0 ; i < ret.length ; i++) {

			ret[i] = 0;

		}

		// Rを拾う
		int odd = 0;
		int even = 0;
		for(int i = 0 ; i < s.length() ; i++) {
			if(s.charAt(i) == 'R') {
				if(i % 2 == 0) {
					even++;
				} else {
					odd++;
				}
			} else {
				if(i % 2 == 0) {
					ret[i] += even;
					ret[i-1] += odd;
				} else {
					ret[i] += odd;
					ret[i-1] += even;
				}
				odd = 0;
				even = 0;
			}
		}

		odd = 0;
		even = 0;
		for(int i = s.length() - 1 ; i >= 0 ; i--) {
			if(s.charAt(i) == 'L') {
				if(i % 2 == 0) {
					even++;
				} else {
					odd++;
				}
			} else {
				if(i % 2 == 0) {
					ret[i] += even;
					ret[i+1] += odd;
				} else {
					ret[i] += odd;
					ret[i+1] += even;
				}
				odd = 0;
				even = 0;
			}
		}

		for(int i = 0 ; i < ret.length ; i++) {

			if(i == ret.length - 1) {
				System.out.print(ret[i]);
			} else {
				System.out.print(ret[i] + " ");
			}

		}

		sc.close();

	}

}


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

int main(){
  int N;
  cin >> N;
  int A[N];
  int max_e = 0, sec_e = 0;
  for(int i = 0; i < N; i++){
    cin >> A[i];
    if(max_e <= A[i]){
      sec_e = max_e;
      max_e = A[i];
    } else if(sec_e < A[i]) {
      sec_e = A[i];
    }
  }
  for(int i = 0; i < N; i++){
    if(A[i] == max_e) cout << sec_e << endl;
    else cout << max_e << endl;
  }
  return 0;
}

Measured memory_bytes: 2432
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    /**
     * 部分集合の組が共通の要素を一つもつので、共通要素から元の部分集合を構成する。
     * S1,S2 => A
     * S1,S3 => B
     * ならば、S1 = {A,B}ということがわかる。
     * また、kC2個のパターンが存在しており、それはNと一致していなければならない。
     * したがって、以下の方針で問題を解くことが可能となる。
     * ①N=kC2からkを確定する。
     * ②kC2の組み合わせを網羅して、共通要素を昇順に割り当てる
     * ③共通要素をあつめて部分集合Siを構成する
     *
     * <see cref="http://tutuz.hateblo.jp/entry/2018/10/28/085507"/>
     */
    static void Main(string[] args)
    {
        var N = int.Parse(Console.ReadLine());
        int k = 0;
        for (int i = N; i >= 1; i--)
        {
            if (2 * N == i * (i - 1))
            {
                k = i;
                break;
            }
        }

        if (N == 1)
        {
            Console.WriteLine("Yes");
            Console.WriteLine(2);
            Console.WriteLine("1 1");
            Console.WriteLine("1 1");
            return;
        }

        if (k == 0)
        {
            Console.WriteLine("No");
            return;
        }

        var S = new List<List<int>>(k);
        var indexList = new int[k];
        for (int i = 0; i < k; i++)
        {
            indexList[i] = i;
            S.Add(new List<int>(N));
        }

        var combList = Combination.Enumerate(indexList, 2, false).ToArray();
        var n = 1;
        foreach (var comb in combList)
        {
            S[comb[0]].Add(n);
            S[comb[1]].Add(n);
            n++;
        }

        Console.WriteLine("Yes");
        Console.WriteLine(k);
        for (int i = 0; i < S.Count; i++)
        {
            var ans = new System.Text.StringBuilder();
            var count = S[i].Count;
            ans.Append(count);
            foreach (var value in S[i])
            {
                ans.Append(" " + value);
            }

            Console.WriteLine(ans);
        }

    }

    /**
     * 組み合わせを求める
     * <see cref="https://qiita.com/gushwell/items/74a96f56ccb64db3660c"/>
     */
    public static class Combination
    {
        public static IEnumerable<T[]> Enumerate<T>(IEnumerable<T> items, int k, bool withRepetition)
        {
            if (k == 1)
            {
                foreach (var item in items)
                    yield return new T[] { item };
                yield break;
            }
            foreach (var item in items)
            {
                var leftside = new T[] { item };

                // item よりも前のものを除く （順列と組み合わせの違い)
                // 重複を許さないので、unusedから item そのものも取り除く
                var unused = withRepetition ? items : items.SkipWhile(e => !e.Equals(item)).Skip(1).ToList();

                foreach (var rightside in Enumerate(unused, k - 1, withRepetition))
                {
                    yield return leftside.Concat(rightside).ToArray();
                }
            }
        }
    }

}



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

int main(void){
    int sum = 0, N;
    cin >> N;
    for(int i = 0; i < N; i++){
        int l, r;
        cin >> l >> r;
        sum += r - l + 1;
    }
    cout << sum << endl;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

struct UnWeightedGraph {
  struct Edge {
    int to;
    Edge(int to) : to(to) {}
  };
  vector<vector<Edge>> edges;
  int n;
  UnWeightedGraph(int n) : n(n) {
    edges.assign(n, vector<Edge>());
  }
  void add_edge(int v, int u) {
    edges[v].emplace_back(u);
  }
  vector<Edge> &operator[](int x) {
    return edges[x];
  }
};

void solve() {
  int n;
  cin >> n;
  UnWeightedGraph g(n);
  reps(i, n - 1) {
    int a;
    cin >> a;
    a--;
    g.add_edge(i, a);
    g.add_edge(a, i);
  }
  auto dfs = [&](auto dfs, int u, int p) -> int {
    vi32 lst;
    each(e, g[u]) if (e.to != p) {
      int x = dfs(dfs, e.to, u) + 1;
      lst.emplace_back(x);
    }
    if (lst.size() == 0) {
      return 0;
    }
    sort(all(lst));
    rep(i, lst.size()) {
      lst[i] += (int) lst.size() - 1 - i;
    }
    return *max_element(all(lst));
  };
  cout << dfs(dfs, 0, -1) << endl;
}


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

int gcd(int a, int b) {
	if (a == 0 || b == 0) return a + b;
	if (a < b) return gcd(b, a);
	int r;
	while (r = a % b) {
		a = b;
		b = r;
	}
	return b;
}

int main()
{
	int N;
	cin >> N;
	vector<int> A(N + 4, 0);
	int ans = 0, tempL, tempR, tempA;

	for (auto &x : A) cin >> x;

	vector<int> L(N + 1, 0), R(N + 1, 0);
	for (int i = 0; i < N; i++)L[i + 1] = gcd(L[i], A[i]);
	for (int i = N - 1; i >= 0; i--)R[i] = gcd(R[i + 1], A[i]);
	for (int i = 0; i < N; i++)
	{
		int m = gcd(L[i], R[i + 1]);
		ans = max(ans, m);
	}
	/*for (int i = 2; i < N + 2; i++)
	{
		vector<int> cA(A);
		for (int j = 1; j < i; j++)
		{
			tempL = gcd(cA[j - 1], cA[j]);
			cA[j] = tempL;
		}

		for (int j = N + 2; i < j; j--)
		{
			tempR = gcd(cA[j], cA[j + 1]);
			cA[j] = tempR;
		}
		tempA = gcd(tempL, tempR);
		ans = tempA > ans ? tempA : ans;
	}*/
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int N; cin >> N;
  vector<string> S(N);
  vector<int> T(N);
  rep(i,N) cin >> S[i] >> T[i];
  string X; cin >> X;
  vector<int> sums(N+1,0);
  rep(i,N){
    sums[i+1] = sums[i] + T[i];
  }
  rep(i,N){
    if(S[i] == X){
      cout << sums[N] - sums[i+1] << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
const int MaxN = 1e5;

int n, k;
int a[MaxN + 5];
int gcd(int x, int y)
{
	if(y == 0) return x;
	else return gcd(y, x % y);
}
int main()
{
	while(scanf("%d %d", &n, &k) != EOF)
	{
		int GCD = 0;
		int MAX = 0;
		for(int i = 1; i <= n; i++) {
			scanf("%d", &a[i]);
			GCD = gcd(GCD, a[i]);
			MAX = max(MAX, a[i]);
		}
		if(k % GCD == 0 && k <= MAX) 
			printf("POSSIBLE\n");
		else printf("IMPOSSIBLE\n");

		memset(a,  0, sizeof(a));
	}
	return 0;
}

Measured memory_bytes: 512
from itertools import combinations

D, G = map(int, input().split())
PC = []
for i in range(D):
    p, c = map(int, input().split())
    total = ((i + 1) * 100) * p + c
    PC.append([p, c, total])

A = []
B = {i for i in range(D)}
for i in range(D+1):
    A += list(combinations(B, i))

# print(A)

ans = []
for ai in A:
    p = 0  # ポイント
    c = 0  # 問題数
    for aii in ai:
        p += PC[aii][2]
        c += PC[aii][0]
    if p < G:
        x = B.difference(ai)
        max_x = max(x)
        cnt = 0
        while p < G and cnt < PC[max_x][0] - 1:
            p += (max_x + 1) * 100
            cnt += 1
            c += 1
        if p >= G:
            # ans.append([p, c])
            ans.append(c)
    else:
        # ans.append([p, c])
        ans.append(c)

print(min(ans))

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


/*  
    
*/

void test_case(){
    ll n; cin >> n;
    
    ll res = 1;
    ll mod = 1e9 + 7;
    for(int i = 0; i <n; i++){
        res *= 10;
        res %= mod;
    }
    
    ll sub = 2;
    
    for(int i = 0; i <n; i++){
        sub *= 9;
        sub %= mod;
    }

    ll subd = 1;
    for(int i = 0; i <n; i++){
        subd *= 8;
        subd %= mod;
    }
    sub  = sub + mod - subd;
    sub %= mod;
    res = res + mod - sub;
    res %= mod;
    cout<< res << endl;
    
}

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

    int t; t = 1;
    //~ cin >> t;
    while(t--)
        test_case();
    return 0;
}


Measured memory_bytes: 3648
n,m=map(int,input().split())
stair=[False]*(n+1)
for i in range(m):
    a=int(input())
    stair[a]=True


dp=[0]*(n+1)
dp[0]=1

for i in range(1,n+1):
    if stair[i]:
        dp[i]=0
    else:
        dp[i]=(dp[i-1]+dp[i-2])%(10**9+7)
print(dp[n])

Measured memory_bytes: 7668