akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll dp[33][305],ans=0,all;
int p[7],a[7],n,c;
inline void solve()
{int i,j,k,t=(1<<(n-1))-1;
for (i=0;i<n*c;i++)
{int o=p[i%n],nl=min(n*c,a[o]*n+i);
if (!o) continue;
o=(1<<(o-1));
for (j=t;j>=0;j--)
{if (o&j) continue;
for (k=n*c;k>=i;k--)
{if (!dp[j][k]) continue;
dp[j|o][max(k,nl)]+=dp[j][k];
}
}
}
ans+=dp[t][n*c];
return;
}
int main (){
	int i;
	scanf ("%d%d",&n,&c);
	for (i=1;i<=n;i++)
	{scanf ("%d",&a[i]);}
	sort(a+1,a+n+1);
	for (i=1;i<=n-1;i++) p[i]=i;
	int num=0;
	do{memset(dp,0,sizeof(dp));dp[0][a[n]*n]=1;solve();num++;
	}while(next_permutation(p+1,p+n));
	double res=1.0/((double)(num));
	for (i=1;i<=n-1;i++)res/=((double)(c));
	printf ("%.12lf\n",res*((double)(ans)));
	return 0;
}

Measured memory_bytes: 384
/*
	Copyright: razouq (c)
	Author: Anass BENDARSI
	Date: 10/06/2017 12:00:44
	flamers will **** you
*/
#include<bits/stdc++.h>
//#include<flamers.h>
#define ull unsigned long long
using namespace std;

int main(){
	string c, str = "";
	for(int i = 0; i < 3; i++){
		cin>>c;
		str += c;
	}
	int n = stoi(str);
	if(n % 4 == 0) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include "iostream"

using namespace std;

int binary(int n,int A[],int key){
  int left = 0;
  int right = n;
  while(left<right){
    int mid = (left + right)/2;
    if(key == A[mid]) return 1;
    else if(key > A[mid]) left = mid + 1;
    else right = mid;
  }
  return 0;
}

int main(){
  int n,A[100100],b,m;
  int cnt = 0;
  cin >> n;
  for(int i=0;i<n;i++){
     cin >> A[i];
   }
  cin >> m;
  for(int j = 0;j<m;j++) {
    cin >> b;
    if(binary(n,A,b) == 1) cnt++;
  }
  cout << cnt << '\n';
}



Measured memory_bytes: 3488
#include <iostream>
using namespace std;
int print(int a[],int N){ 
  int i;
  for(i=0;i<N;i++){
    if(i<N-1){
      cout<<a[i]<<" ";
    }
    if(i==N-1){
      cout<<a[i]<<endl;
  }
  }
}
int Insertion(int a[],int N){
  int i,V,j,v;
  for(i=1;i<N;i++){
    v=a[i];
    j=i-1;
    while(j>=0){
      if(a[j]>v){
	V=a[j];
	a[j]=v;
	a[j+1]=V;
      }
      j--;
    }
    print(a,N);
  }
}
int main(){
  int a[1000];
  int N,i;
  cin>>N;
  for(i=0;i<N;i++){
    cin>>a[i];
  }
  for(i=0;i<N;i++){
    if(i<N-1){
    cout<<a[i]<<" ";
    }
    if(i==N-1){
      cout<<a[i]<<endl;
  }
  }
  Insertion(a,N);
  // print(a,N);
  return 0;
  
}

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

using namespace std;

#define ll long long int

int main()
{
ios_base::sync_with_stdio(false);
cout.tie(NULL);
cin.tie(NULL);
              ll i,j,d,n,k,x,coun=0;
  cin>>n>>k;
  vector<ll>A(n);
  for(i=0;i<k;i++)
  {
    cin>>d;
    for(j=0;j<d;j++)
    {
      cin>>x;
      A[x-1]=1;
    }
  }
  for(i=0;i<n;i++)
  {
    if(A[i]==0)
      coun++;
  }
  cout<<coun;
              return(0);
}


Measured memory_bytes: 3636
//
//  discount_ticket.cpp
//  learningCplusplus
//
//  Created by Tran Duc Chinh on 2020/04/04.
//  Copyright © 2020 Tran Duc Chinh. All rights reserved.
//

#include <iostream>
#include <queue>
#include <math.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
#define PI 3.14159265

int main(int argc, const char* argv[]) {

  double n, m;
  std::cin >> n >> m;
  std::priority_queue<ll> q;
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    ll a;
    std::cin >> a;
    q.push(a);
    sum += a;
  }

  while (m>0) {
    ll a = q.top();
    // std::cout << " " << a << std::endl;
    q.pop();
    sum -= (a+2-1)/2;
    q.push(a/2);
    m -= 1;
  }

  std::cout << sum << std::endl;
  return 0;
}


Measured memory_bytes: 1400
using System;

namespace abc144B
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int N = Int32.Parse(Console.ReadLine());
            string P = "";
            for(int M = 1; M <=9; M++)
            {
                if(N % M ==0 && N / M <= 9)
                {
                    P = "Yes";
                }
            }
            if (P == "Yes")
            {
                Console.WriteLine(P);
            }
            else
                Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 13140
def differ_length(i, j, k):
  return (i != j) and (j != k) and (i != k)

def exist_triangle(i, j, k):
  return (i + j > k) and (j + k > i) and (i + k > j)

n_stick = int(input())

length = list(map(int, input().split()))

count = 0

for i in range(n_stick):
  for j in range(i + 1, n_stick):
    for k in range(j + 1, n_stick):
      
      if differ_length(length[i], length[j], length[k]) and exist_triangle(length[i], length[j], length[k]):
        count += 1
        
print(count)

Measured memory_bytes: 9208
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <utility>
#include <vector>

using std::cout;
using std::cin;
using std::string;

using hoge = std::pair<long long , long long>;
using hoges = std::vector<hoge>;

int main()
{
  int N, M;
  cin >> N >> M;
  hoges store_infos(N);
  for(size_t i = 0; i < N;++i)
  {
    int a,b;
    cin >> a >> b;
    store_infos[i] = std::make_pair(a,b);
  }

  std::sort(store_infos.begin(), store_infos.end(), [](const hoge& a, const hoge& b){ return a.first < b.first;});

  long long sum = 0;
  for(const auto& item : store_infos)
  {
    int num = 0;
    if(M - item.second > 0) 
    {
      M -= item.second;
      sum += item.first * item.second;
    }else
    {
      sum += item.first * M;
      M = 1;
      break;
    }
  }

  cout << sum << "\n";
  return 0;
}


Measured memory_bytes: 1792
n = int(input())
a = list(map(int, input().split()))
if n % 3 == 0:
    a.sort()
    for i in range(n // 3 - 1):
        if a[i] != a[i + 1]:
            print('No')
            exit(0)
    for i in range(n // 3, n // 3 * 2 - 1):
        if a[i] != a[i + 1]:
            print('No')
            exit(0)
    for i in range(n // 3 * 2, n - 1):
        if a[i] != a[i + 1]:
            print('No')
            exit(0)
    if a[0] ^ a[n // 3] == a[n // 3 * 2]:
        print('Yes')
    else:
        print('No')
else:
    if any(a):
        print('No')
    else:
        print('Yes')


Measured memory_bytes: 60784
import java.util.*;

public class Main{
      public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            String str1 = sc.next();
            String str2 = sc.next();
            StringBuffer str = new StringBuffer(str1);
        	String str3 = str.reverse().toString();
        
            if(str3.equals(str2)){
              System.out.println("YES");
            } else {
              System.out.println("NO");
            }
          }
}

Measured memory_bytes: 21844
import sys
from collections import defaultdict
from bisect import bisect_left, bisect_right
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    airplane = {'U':[], 'R':[], 'D':[], 'L':[]}
    for _ in range(N):
        x, y, u = input().split()
        airplane[u].append((int(x), int(y)))
    out = float('inf')

    X = defaultdict(list)
    for x, y in airplane['U']: X[x].append((y, 1))
    for x, y in airplane['D']: X[x].append((y, -1))
    for x in X:
        X[x].sort()
        pre_y, pre_u = None, -2
        for y, u in X[x]:
            if pre_u > u: out = min(out, (y - pre_y) * 5)
            pre_y, pre_u = y, u

    Y = defaultdict(list)
    for x, y in airplane['R']: Y[y].append((x, 1))
    for x, y in airplane['L']: Y[y].append((x, -1))
    for y in Y:
        Y[y].sort()
        pre_x, pre_u = None, -2
        for x, u in Y[y]:
            if pre_u > u: out = min(out, (x - pre_x) * 5)
            pre_x, pre_u = x, u

    D = defaultdict(list)
    for x, y in airplane['U']: D[x + y].append((x, -1))
    for x, y in airplane['R']: D[x + y].append((x, 1))
    for z in D:
        D[z].sort()
        pre_x, pre_u = None, -2
        for x, u in D[z]:
            if pre_u > u: out = min(out, (x - pre_x) * 10)
            pre_x, pre_u = x, u

    D = defaultdict(list)
    for x, y in airplane['D']: D[x + y].append((x, 1))
    for x, y in airplane['L']: D[x + y].append((x, -1))
    for z in D:
        D[z].sort()
        pre_x, pre_u = None, -2
        for x, u in D[z]:
            if pre_u > u: out = min(out, (x - pre_x) * 10)
            pre_x, pre_u = x, u

    D = defaultdict(list)
    for x, y in airplane['D']: D[x - y].append((x, -1))
    for x, y in airplane['R']: D[x - y].append((x, 1))
    for z in D:
        D[z].sort()
        pre_x, pre_u = None, -2
        for x, u in D[z]:
            if pre_u > u: out = min(out, (x - pre_x) * 10)
            pre_x, pre_u = x, u

    D = defaultdict(list)
    for x, y in airplane['U']: D[x - y].append((x, 1))
    for x, y in airplane['L']: D[x - y].append((x, -1))
    for z in D:
        D[z].sort()
        pre_x, pre_u = None, -2
        for x, u in D[z]:
            if pre_u > u: out = min(out, (x - pre_x) * 10)
            pre_x, pre_u = x, u
    if out == float('inf'):
        print("SAFE")
    else:
        print(out)


if __name__ == "__main__":
    main()


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

const long long mod = 1000000007;


int main(){
	int N, M;
	cin >> N >> M;
	long long ans[] = {0, 0, 1};

	int n = 0;
	for (int m = 0; m < M; m++)
	{
		int a;
		cin >> a;
		for(; n < a; n++)
		{
			ans[0] = ans[1];
			ans[1] = ans[2];
			ans[2] = (ans[0] + ans[1]) % mod;
		}
		ans[2] = 0;
	}
	for(; n < N; n++)
	{
		ans[0] = ans[1];
		ans[1] = ans[2];
		ans[2] = (ans[0] + ans[1]) % mod;
	}
	
	cout << ans[2] << endl;
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
H = [int(x) for x in input().split()]

a = [0]*len(H)

for i in range(M):
    A = [int(x) for x in input().split()]
    if H[A[0]-1] > H[A[1]-1]:
        a[A[1]-1] += -1
    elif H[A[0]-1] == H[A[1]-1]:
        a[A[0]-1] += -1
        a[A[1]-1] += -1
    else:
        a[A[0]-1] += -1

print(a.count(0))

Measured memory_bytes: 20128
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
//const long long MOD = 1000000007;
const long long MOD = 998244353;
using namespace std;

ll solve( int n, const int* a, int* b, set<pair<int,int> >& setb )
{
    if(setb.empty()) {
        return 0;
    }
    auto it = setb.rbegin();
    int val=it->first;
    int id=it->second;
    if(a[id]==b[id]) { 
        setb.erase(make_pair(b[id],id));
        return solve(n, a, b, setb);
    }

    int prev=b[(id-1+n)%n];
    assert(prev>0);
    int next=b[(id+1+n)%n];
    assert(next>0);
    int step=prev+next;
    if(val<=step) {
        return -1;
    }
    int valnew=val%step;
    int add=val/step;

    if(a[id]>valnew) {
        if(a[id]%step!=valnew) {
            return -1;
        }
        valnew = a[id];
        add = (val - valnew) / step;
        setb.erase(make_pair(b[id],id));
        b[id]=valnew;
    }
    else {
        if(valnew==0) {
            return -1;
        }
        setb.erase(make_pair(b[id],id));
        b[id]=valnew;
        setb.insert(make_pair(b[id],id));
    }

    ll ans0 = solve( n, a, b, setb);
    if(ans0<0) {
        return -1;
    }
    ll ans = ans0 + add;

    return ans;
}

int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

    vector<int> a(n), b(n);
    int i;
    for(i=0; i<n; i++) {
        scanf("%d", &a[i]);
    }
    set<pair<int,int> > setb;
    for(i=0; i<n; i++) {
        scanf("%d", &b[i]);
        setb.insert(make_pair(b[i], i));
    }

    ll ans = solve( n, &a[0], &b[0], setb );
    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 132224
#include <iostream>

int main() {
    long long a,b,c,k;
    std::cin >> a >> b >> c >> k;
    for (int i = 0; i < k; ++i) {
        if(a < b){
            if(b < c)
                c *= 2;
            else
                b *= 2;
        }
        else if(a < c){
            c *= 2;
        }
        else
            a *= 2;
    }
    long long ans = a + b + c;

    std::cout << ans << std::endl;

}

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

int main(){
    int a, b, k;
    cin >> a >> b >> k;
    rep(i, (b-a+1>2*k?2*k:b-a+1)){
        cout << ((b-a+1>2*k)?(i<k?(a+i):(b-2*k+1+i)):a+i) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <cassert>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr ll INF = 3000000000000000000;

int main() {
    int n;
    cin >> n;
    vector<vector<int>> G(n);
    vector<int> cnt(n, 0);
    REP(i, n - 1) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        G[a].push_back(b);
        G[b].push_back(a);
        ++cnt[a];
        ++cnt[b];
    }
    
    queue<int> q;
    REP(i, n) {
        if (cnt[i] == 1) q.push(i);
    }
    
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (int v : G[u]) {
            if (!cnt[v]) continue;
            cnt[v] = 0;
            int k = 0;
            for (int v_ : G[v]) {
                if (!cnt[v_]) continue;
                --cnt[v_];
                if (cnt[v_] == 1) q.push(v_);
                if (!cnt[v_]) ++k;
            }
            if (k >= 2) {
                cout << "First\n";
                return 0;
            }
        }
        cnt[u] = 0;
    }
    
    cout << "Second\n";
    return 0;
}


Measured memory_bytes: 9368
#include <iostream>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <utility>
 
using namespace std;

int ord(int n){
if(n%2==1){return 0;}
else{return 1+ord(n/2);}
}


int main() {

int N;
cin >>N;

int a;
int ans=0;

for(int i=0;i<N;i++){
cin >>a;
ans=ans+ord(a);}

cout <<ans;

}



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

const int MAX_V = 100000;

vector<int> G[MAX_V];
int vertex, edge;
bool visited[MAX_V];
int prenum[MAX_V], parent[MAX_V], lowest[MAX_V];
int timer;
set<int> ap;

void dfs(int current, int prev) {
    prenum[current] = lowest[current] = timer;
    timer++;

    visited[current] = true;

    int next;
    for (auto i = 0; i < G[current].size(); i++) {
        next = G[current][i];
        if (!visited[next]) {
            parent[next] = current;
            dfs(next, current);
            lowest[current] = min(lowest[current], lowest[next]);
        } else if (next != prev) {
            lowest[current] = min(lowest[current], prenum[next]);
        }
    }
}

void ArticulationPoints(void) {
    timer = 1;
    dfs(0, -1);

    int np = 0;
    for (int i = 1; i < vertex; i++) {
        int p = parent[i];
        if (p == 0) np++;
        else if (prenum[p] <= lowest[i]) ap.insert(p);
    }
    if (np > 1) ap.insert(0);
}

int main(void) {
    cin >> vertex >> edge;
    for (int i = 0; i < vertex; i++) {
        visited[i] = false;
    }

    int s, t;
    for (int i = 0; i < edge; i++) {
        cin >> s >> t;
        G[s].push_back(t);
        G[t].push_back(s);
    }

    ArticulationPoints();

    for (auto it = ap.begin(); it != ap.end(); it++) {
        cout << *it << endl;
    }

    return 0;
}

Measured memory_bytes: 5128
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int M; cin >> M;
  cout << 24 + 24 - M << endl;
  return 0;
}

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

using namespace std;
const int N=4e3+10;
const int inf=0x3f3f3f3f;

char c[N];
int a[N], n, dp[N][N], b[N][N], w[N][N], sumb[N], sumw[N];

int main() {
	scanf("%d", &n);
	for(int i=1; i<=n*2; i++) {
		cin>>c[i];
		scanf("%d", &a[i]);
	}
	for(int i=1; i<=n*2; i++) {
		if (c[i]=='B') {
			for(int j=0; j<=n; j++) {
				b[a[i]][j]=sumb[a[i]+1]+sumw[j+1];
			}
			for(int j=0; j<=a[i]; j++) {
				sumb[j]+=1;
			}
		}
		else {
			for(int j=0; j<=n; j++) {
				w[j][a[i]]=sumb[j+1]+sumw[a[i]+1];
			}
			for(int j=0; j<=a[i]; j++) {
				sumw[j]+=1;
			}
		}
	}
	for(int i=0; i<=n; i++) {
		for(int j=0; j<=n; j++) {
			if (!i&&!j) dp[i][i]=0;else dp[i][j]=inf;
			if (i) dp[i][j]=min(dp[i][j], dp[i-1][j]+b[i][j]);
			if (j) dp[i][j]=min(dp[i][j], dp[i][j-1]+w[i][j]);
		}
	}
	cout<<dp[n][n]<<endl;
	return 0;
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;
const ll MOD = 1e9 + 7;

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

int main() {
    int h, w; cin >> h >> w;
    V<string> b(h);
    for(int i = 0; i < h; i++) cin >> b[i];

    int sum = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(b[i][j] == '.') sum++;
        }
    }

    int dis[h + 1][w + 1];
    memset(dis, -1, sizeof(dis));
    dis[0][0] = 1;

    int gy = h - 1, gx = w - 1;
    queue<P<int, int> > que;
    que.push({0, 0});

    while(!que.empty()){
        auto p = que.front();
        que.pop();

        int y = p.first;
        int x = p.second;
        for(int i = 0; i < 4; i++){
            int ny = y + dy[i];
            int nx = x + dx[i];
            if(ny < 0 || h <= ny || nx < 0 || w <= nx) continue;
            if(b[ny][nx] == '#') continue;
            if(dis[ny][nx] != -1) continue;
            if(ny == gy && nx == gx){
                dis[gy][gx] = dis[y][x] + 1;
                break;
            }
            dis[ny][nx] = dis[y][x] + 1;
            que.push({ny, nx});
        }
    }

    if(dis[gy][gx] == -1) cout << -1 << endl;
    else cout << sum - dis[gy][gx] << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
	int n;
	cin>>n;
	if(n==1)cout<<"Hello World";
	else{
		int a,b;
		cin>>a>>b;
		cout<<a+b;
	}
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
import math
from functools import reduce


def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)


# 最小公倍数
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

# AでもBでも割り切れる数の最小値、それが最小公倍数だ
A, B = [int(x) for x in input().split()]

ans = lcm(A, B)
print(ans)

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

int main(){
  int k;cin>>k;
  if(k==4||k==6||k==9||k==10||k==14||k==21||k==22||k==25||k==26){
    cout<<2<<endl;
  }else if(k==28||k==30){
    cout<<4<<endl;
  }else if(k==8||k==12||k==18||k==20||k==27){
    cout<<5<<endl;
  }else if(k==16){
    cout<<14<<endl;
  }else if(k==24){
    cout<<15<<endl;
  }else if(k==32){
    cout<<51<<endl;
  }else cout<<1<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main(){
  int h=0,a=0,x=0;
  cin>>h>>a;
  while(a--){
  	int r=0;
  	cin>>r;
  	x+=r;
  }
  if(h<=x)cout<<"Yes"<<endl;
  else
	cout<<"No"<<endl;
  
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

class Main {
	
	static class BinarySearch {
		static Node root = null;
		
		public void binarysearch (InputReader ir) {
			
			int m = ir.nextInt();
			
			for (int i = 0; i < m; i++) {
				String ord = ir.nextString();
				
				if (ord.equals("insert")) Insert (ir.nextInt());
				else if (ord.equals("print")) Print ();
				else if (ord.equals("find")) Find (ir.nextInt());
				
			}
			
		}
		
		static void Insert (int k) {
			
			Node x = root;
			Node y = null;
			Node z = new Node ();
			
			z.key = k;
			while (x != null) {
				y = x;
				if (z.key < x.key) {
					x = x.left;
				} else {
					x = x.right;
				}
			}
			
			z.parent = y;
			
			if (y == null) {
				root = z;
			} else if (z.key < y.key) {
				y.left = z;
			} else {
				y.right = z;
			}
			
			
		}
		
		static void Print () {
			
			StringBuilder sb = new StringBuilder();
			
			Inorder (sb, root);
			System.out.println(sb);
			sb.setLength(0);
			Preorder (sb, root);
			System.out.println(sb);
		}
		
		static void Find (int k) {
			
			Node x = root;
			
			while(x != null && k != x.key) {
				if(k < x.key) x = x.left;
				else x = x.right;
				}
			
			StringBuilder sb = new StringBuilder ();
			if (x != null) sb.append("yes");
			else sb.append("no");
			
			System.out.println(sb);
			
		}
		
		static void Preorder (StringBuilder sb, Node root) {
			if(root == null) return;
	        sb.append(" ").append(root.key);
	        Preorder(sb, root.left);
	        Preorder(sb, root.right);
		}
		
		static void Inorder (StringBuilder sb, Node root) {
			if(root == null) return;
	        Inorder(sb, root.left);
	        sb.append(" ").append(root.key);
	        Inorder(sb, root.right);
		}
	}
	
	static class Node {
		Integer key = null;
		Node parent;
		Node left;
		Node right;
	}
	
	static class InputReader {
		BufferedReader br;
		StringTokenizer st;
		
		public String nextString() {
			
			 while (!st.hasMoreTokens()) {
	                try {
	                    st = new StringTokenizer(br.readLine(), " ");
	                } catch (IOException e) {
	                    throw new InputMismatchException();
	                }
	            }
			return st.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(nextString());
		}
					
		public InputReader (InputStream inputStream) {
			br = new BufferedReader (new InputStreamReader (inputStream));
			st = new StringTokenizer ("");
		}
		
	}
	
	public static void main (String[] args) {
		InputStream inputStream = System.in;
		InputReader in = new InputReader (inputStream);
		BinarySearch obj = new BinarySearch();
		obj.binarysearch(in);
	}
	
	
}



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

int main() {
  
  string S; cin >> S;
  
  int A, B, C, D;
  
  A = stoi(S.substr(0, 1)); B = stoi(S.substr(1, 1));
  
  C = stoi(S.substr(2, 1)); D = stoi(S.substr(3, 1));
  
  char op1, op2, op3; int op1i = 1, op2i = 1, op3i = 1;
  
  for (int i = 0; i < 2; i++) {
    
    if (i == 0) { op1 = '+'; op1i = 1; }
    else { op1 = '-'; op1i = -1; }
    
    for (int j = 0; j < 2; j++) {
      
      if (j == 0) { op2 = '+'; op2i = 1; }
      else { op2 = '-'; op2i = -1; }
      
      for (int k = 0; k < 2; k++) {
        
        if (k == 0) { op3 = '+'; op3i = 1; }
        else { op3 = '-'; op3i = -1; }
        
        string opB = op1 + to_string(B);
        
        string opC = op2 + to_string(C);
        
        string opD = op3 + to_string(D);
        
        if (A + B * op1i + C * op2i + D * op3i == 7) {
          
          cout << to_string(A) + opB + opC + opD + "=7" << endl;
          
          return 0;
          
        }
        
      }
      
    }
    
  }
  
}

Measured memory_bytes: 256
crd = []
a = int(input())
crd.append(a)
b = int(input())
crd.append(b)
c = int(input())
crd.append(c)
d = int(input())
crd.append(d)
e = int(input())
crd.append(e)
k = int(input())

#print(len(crd))
for x in range(len(crd)):
    for y in range(x+1, len(crd)-x):
        #print(x, y)
        #print(crd[int(x)], crd[int(y)])
        z = k - (crd[y] - crd[x])
        #print("z= ", z)
        if z < 0:
            print(":(")
            break
    else:
        continue
    break
else:
    print("Yay!")


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

using namespace std;

typedef long long ll;
const ll INF = 1e18;
ll n, ans;

int getNum(ll tmp) {
	ll ret = 0;

	while (tmp > 0) {
		tmp /= 10;
		ret++;
	}

	return ret;
}

int getFirst(ll tmp) {
	ll ret = 0;

	while (tmp > 0) {
		ret = tmp % 10;
		tmp /= 10;
	}

	return ret;
}

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

	cin >> n;

	ans = 1LL;
	bool flag = false;

	for (int i = 0; i < n; i++) {
		ll cur;
		cin >> cur;

		int a = getNum(ans) - 1;
		int b = getNum(cur) - 1;
		int t = getFirst(ans);
		int y = getFirst(cur);
		int c = getNum(t* y);
		
		if (a + b + c > 19) {
			flag = true;
			continue;
		}

		ans *= cur;

		if (ans> INF) {
			flag = true;
		}
	}

	if (ans == 0) cout << ans << "\n";
	else if (flag) cout << -1 << "\n";
	else cout << ans << "\n";


	return 0;
}

Measured memory_bytes: 3648
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int a = scanner.nextInt() - 1;
        int b = scanner.nextInt() - 1;
        int c = scanner.nextInt() - 1;
        int d = scanner.nextInt() - 1;
        String s = scanner.next();

        System.out.println(f(a, b, c, d, s) ? "Yes" : "No");
    }

    static boolean f(int a, int b, int c, int d, String s) {
        boolean before = false;
        for (char ch : s.substring(a, c).toCharArray()) {
            if (before && ch == '#') {
                return false;
            }
            before = ch == '#';
        }
        before = false;
        for (char ch : s.substring(b, d).toCharArray()) {
            if (before && ch == '#') {
                return false;
            }
            before = ch == '#';
        }

        if (c > d) {
            String t = s.substring(b - 1, d + 2);
            int max = 0;
            int count = 0;
            for (int i = 0; i < t.length(); i++) {
                if (t.charAt(i) == '.') {
                    count++;
                } else {
                    max = Math.max(max, count);
                    count = 0;
                }
            }
            return Math.max(max, count) >= 3;
        }
        return true;
    }
}

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

using namespace std;
typedef long long ll;
#define DBG(v) cerr << #v << " = " << (v) << endl;

int n;
string s;

int fR(int x) {
    for (;;) {
        if (x + 1 < n && s[x + 1] == '.')
            x += 1;
        else if (x + 2 < n && s[x + 2] == '.')
            x += 2;
        else
            break;
    }
    return x;
}

void no() {
    cout << "No";
    exit(0);
}

void yes() {
    cout << "Yes";
    exit(0);
}

bool contains(pair<int, int> r, int x) {
    return r.first <= x && x <= r.second;
}

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

    int A, B, C, D;
    cin >> n >> A >> B >> C >> D >> s;
    --A, --B, --C, --D;

    if (fR(A) < C || fR(B) < D)
        no();

    if (C < D)
        yes();

    for (int x = B; x <= D; ++x)
        if (s[x] == '.' && s[x - 1] == '.' && s[x + 1] == '.')
            yes();
    no();



return 0;
}

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

int main() {
	int a, b, k;
	scanf("%d %d %d", &a, &b, &k);
	if(b-a+1 <= 2*k) 
		for(int i = a; i <= b; i++) printf("%d\n", i);
	else {
		for(int i = a; i < a + k; i++) printf("%d\n", i);
		for(int i = b - k + 1; i <= b; i++) printf("%d\n", i);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int>> PQ;
const int MOD = 1000000007;

int main(){
    
    ll N, K; cin >> N >> K;
    vector<int> p(N);
    rep(i,N) cin >> p[i];
    vector<long double> cum(N);
    rep(i,N){
        cum[i+1] = cum[i] + (p[i]+1);
    }
    long double ans = 0;
    rep(i,N){
        if (i+K > N) break;
        ans = max(ans, (cum[i+K] - cum[i]));
    }
    cout << fixed << setprecision(15);
    cout << ans/2.0 << endl;
}

Measured memory_bytes: 7200
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
using namespace std;
using ll =long long;
int main() {
	int N, M;
	vector<pair<int,int>>s;
	cin >> N >> M;
	int a,b;
	for (int i = 0; i < M; i++) {
		cin >> a >> b;
		s.push_back(make_pair(a, b));
		
	}
	
	sort(s.begin(), s.end());
	//０の時
	int test=0;
	for (int i = 0; i < M; i++) {
		if (s[i].first == 1 && s[i].second == 0) {
			test++;
			
		}
		
	}
	if (N == 1 && test == M) {
		cout << 0;
		return 0;
	}
	//－１の時
	for (int i = 0; i < M;i++) {
		if ((s[i].second==0&&s[i].first==1)||(i<M-1&&s[i].first == s[i + 1].first && s[i].second != s[i + 1].second)) {
			cout << -1;
			return 0;
		}
	}
	//0以外の正の整数の時
	int ans=0;
	for (int i = 0; i < M; i++) {
		if (s[i].first == 1) {
			ans += pow(10, N - 1)*s[i].second;
			break;
		}

	}
	for (int i = 0; i < M; i++) {
		if (s[i].first == 2) {
			ans += pow(10, N - 2) *s[i].second;
			break;
		}
	}
	for (int i = 0; i < M; i++) {


		if (s[i].first == 3) {

			ans += pow(10, N - 3)*s[i].second;

			break;
		}

	}
	if (ans < pow(10,N-1)) {

		ans += pow(10,N-1);

	}
	cout << ans;


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mx 10000010
using namespace std;
int main()
{
	long long int i,n,j,sum=0;
	vector<int> div(mx+1);
	cin>>n;
	for(i=1;i<=n;i++)
	{
		for(j=i;j<=n;j+=i)
		{
			div[j]++;
		}
	}
	for(i=1;i<=n;i++)
	{
		sum+=div[i]*i;
	}
	cout<<sum<<endl;
	return 0;
	
}

Measured memory_bytes: 42152
// +build ignore
package main

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

func solve(sc *scanner, wr *bufio.Writer) int {
	S := sc.s()

	fmt.Println(S[:3])

	return 0
}

func main() {
	sc := newScanner(os.Stdin)
	wr := bufio.NewWriter(os.Stdout)
	ret := solve(sc, wr)
	wr.Flush()
	os.Exit(ret)
}

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}


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

int main(){
  int m1,d1,m2,d2, cnt=0;
  scanf("%d %d %d %d", &m1, &d1, &m2, &d2);
  if(m1==1 || m1==3 || m1==5 || m1==7 || m1==8 || m1==10 || m1==12){
    if(d1==31) cnt++;
  }
  else if(m1==2){if(d1==28) cnt++;}
  else if(d1==30) cnt++;
  printf("%d", cnt);
}

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

template<typename F, typename S>
ostream &operator<<(ostream &os, const pair<F, S> &p) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    typename vector<T>::const_iterator it;
    for (it = v.begin(); it != v.end(); it++) {
        if (it != v.begin()) os << ", ";
        os << *it;
    }
    return os << "}";
}

template<typename T>
ostream &operator<<(ostream &os, const set<T> &v) {
    os << "[";
    typename set<T>::const_iterator it;
    for (it = v.begin(); it != v.end(); it++) {
        if (it != v.begin()) os << ", ";
        os << *it;
    }
    return os << "]";
}

template<typename F, typename S>
ostream &operator<<(ostream &os, const map<F, S> &v) {
    os << "[";
    typename map<F, S>::const_iterator it;
    for (it = v.begin(); it != v.end(); it++) {
        if (it != v.begin()) os << ", ";
        os << it->first << " = " << it->second;
    }
    return os << "]";
}

#define debug(x) cerr << #x << " = " << x << endl;

typedef long long int ll;
typedef long double ld;

#define endl "\n";
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define tr(cont, it) for(decltype((cont).begin()) it = (cont).begin(); it != (cont).end(); it++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c),x) != (c).end())
#define F first
#define S second

const ll mod = 1000000007;
const ll inf = (ll) 1e15;

ll power(ll a, ll b, ll m = mod) {if (b == 0) return 1; if (b == 1) return (a % m); ll x = power(a, b / 2, m); x = (x * x) % m; if (b % 2) x = (x * a) % m;return x;}
ll max(ll a, ll b) { return (a > b ? a : b); }
ll min(ll a, ll b) { return (a < b ? a : b); }


void solve() {

    int n,h,w;
    cin >> n >> h >> w;
    cout << (n-h+1)*(n-w+1) << endl;

}

int main() {
    IOS;
    int t = 1, num = 1;   ///// change this t for number of testcase globally
    while (t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
    static final int[] STICK_NUMS = { -1, 2, 5, 5, 4, 5, 6, 3, 7, 6 };

    static BigInteger solution;
    static int lengthForSolution;

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

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] A = new int[M];
        for (int i = 0; i < A.length; ++i) {
            A[i] = sc.nextInt();
        }

        System.out.println(solve(N, A));

        sc.close();
    }

    static BigInteger solve(int N, int[] A) {
        Map<Integer, Integer> stickNumToDigit = new HashMap<>();
        for (int digit : A) {
            stickNumToDigit.put(STICK_NUMS[digit], Math.max(stickNumToDigit.getOrDefault(STICK_NUMS[digit], 0), digit));
        }

        int[] stickNums = stickNumToDigit.keySet().stream().sorted().mapToInt(x -> x).toArray();

        lengthForSolution = 0;
        solution = BigInteger.ZERO;
        search(stickNumToDigit, stickNums, new int[stickNums.length], 0, 0, N);

        return solution;
    }

    static void search(Map<Integer, Integer> stickNumToDigit, int[] stickNums, int[] lengths, int index,
            int totalLength, int rest) {
        if (index == lengths.length) {
            List<Integer> digits = new ArrayList<>();
            for (int i = 0; i < lengths.length; ++i) {
                for (int j = 0; j < lengths[i]; ++j) {
                    digits.add(stickNumToDigit.get(stickNums[i]));
                }
            }

            String s = digits.stream().sorted(Collections.reverseOrder()).map(String::valueOf)
                    .collect(Collectors.joining());
            BigInteger current = new BigInteger(s);
            if (current.compareTo(solution) > 0) {
                solution = current;
                lengthForSolution = s.length();
            }

            return;
        }

        if (totalLength + rest / stickNums[index] < lengthForSolution) {
            return;
        }

        if (index == lengths.length - 1) {
            if (rest % stickNums[index] == 0) {
                lengths[index] = rest / stickNums[index];
                search(stickNumToDigit, stickNums, lengths, index + 1, totalLength + lengths[index], 0);
            }

            return;
        }

        for (int length = rest / stickNums[index]; length >= 0; --length) {
            lengths[index] = length;
            search(stickNumToDigit, stickNums, lengths, index + 1, totalLength + lengths[index],
                    rest - stickNums[index] * lengths[index]);
        }
    }
}

Measured memory_bytes: 38908
N = int(input())

ans = ""
i = 0
while N != 0:
  if N%2**(i+1) == 2**i:
    N -= (-2)**i
    ans += "1"
  else:
    ans += "0"
  i += 1

if ans == "":
  print(0)
else:
  print(ans[::-1])

Measured memory_bytes: 3060
package main

import "fmt"

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func main() {
	var n int
	fmt.Scan(&n)

	b := make([]int, n-1)
	for i := range b {
		fmt.Scan(&b[i])
	}
	ans := b[0] + b[len(b)-1]
	for i := range b[:len(b)-1] {
		ans += min(b[i], b[i+1])
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
n=int(input())

x=list(map(int,input().split()))

maxX=max(x)
minX=min(x)

mindis=0

for i in range(minX,maxX+1):
  dis=0
  for j in x:
    dis+=(j-i)*(j-i)

  if mindis==0 or mindis>dis:
    mindis=dis

print(mindis)

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

int n, A[30];

bool solve(int i, int m) {
    if (m == 0) {
        return true;
    }
    if (i >= n) {
        return false;
    }
    bool flag = solve(i + 1, m - A[i]) || solve(i + 1, m);
    return flag;
}

int main() {
    int q;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int m;
        cin >> m;
        if (solve(0, m)) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }


}


Measured memory_bytes: 3128
N,M = map(int,input().split())
XY = [list(map(int,input().split())) for i in range(M)]
Q = [1 for i in range(N)]

dp = [0 for i in range(N)] #dp[m][n]
dp[0]=1

for i in range(1,M+1):
  x=XY[i-1][0]
  y=XY[i-1][1]

  if dp[x-1]>=1:
    if Q[x-1]==1:
      dp[x-1]=0
    else:
      dp[x-1]=1
    dp[y-1]+=1
  Q[x-1]-=1
  Q[y-1]+=1
  
ans=0
for i in range(N):
  if dp[i]>=1:
    ans+=1
print(ans)

Measured memory_bytes: 69720
import java.util.ArrayList;
import java.util.Scanner;

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

		ArrayList<Integer> numList1 = new ArrayList<Integer>();
		ArrayList<Integer> numList2 = new ArrayList<Integer>();

		while (true) {
			String[] lines = sc.nextLine().split(" ");
			int num1 = Integer.parseInt(lines[0]);
			int num2 = Integer.parseInt(lines[1]);
			if(num1 == 0 && num2 == 0) {
				break;
			} else {
				numList1.add(num1);
				numList2.add(num2);
			}
		}
		for(int i = 0;i < numList1.size();i++) {
			if(numList1.get(i) > numList2.get(i)) {
				int x = numList1.get(i);
				numList1.set(i, numList2.get(i));
				numList2.set(i, x);
			}
			System.out.println(numList1.get(i) + " " + numList2.get(i));
		}
		sc.close();
	}
}

Measured memory_bytes: 36124
import java.util.Scanner;
public final class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		int count=0;
		
		for(int i =0;i<a.length();i++) {
			if(!(a.charAt(i)==b.charAt(i))) {
				count++;
			}
		}
		
		System.out.println(count);
	}

}


Measured memory_bytes: 41184
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iostream>
#include<string>
using namespace std;
int main(void)
{
	long long int ans=0;
	int n, t;
	cin >> n >> t;
	vector<int> num(n);
	int i, m, j;
	for (i = 0; i < n; i++)
	{
		cin >> num[i];
	}
	for (i = 0; i < n-1; i++) //最後の人だけは別にたす確実にt秒追加される
	{
		if (num[i + 1] - num[i] < t)
		{
			ans = ans+ (num[i + 1] - num[i]);
		}
		else
		{
			ans = ans +t;
		}
	}
	ans = ans + t;

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


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    int a[n],cnt=0;

    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]>=k)
        {
            cnt++;
        }

    }
    if(cnt==0)
    {
        cout<<0<<endl;
    }
    else
    {
        cout<<cnt<<endl;
    }
    exit(0);
}


Measured memory_bytes: 3952
import java.util.Scanner;

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

        int n = sc.nextInt();
        sc.close();

        if(4 > n && 7 > n) {
            System.out.println("No");
            System.exit(0);
        }

        for(int i=0; i<=30; i++) {
            for(int j=0; j<20; j++) {
                if((i*4) + (j*7) == n) {
                    System.out.println("Yes");
                    System.exit(0);
                }
            }
        }
        System.out.println("No");
    }
}


Measured memory_bytes: 23636
import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
sys.setrecursionlimit(4100000)
from functools import lru_cache
INF = 1 << 60

#ここから書き始める
n, r = map(int, input().split())
if n >= 10:
    print(r)
else:
    print(r + 100 * (10 - n))


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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
typedef vector<vector<int>> VV;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define PRALL(a) a.begin(),a.end(),greater<pair<int,int>>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/
typedef struct{
    string s;
    int p;
    int i;
}Dat;

//比較関数を定義
bool mycmp(Dat &a,Dat &b){//アドレスを持ってくる
    //名前は昇順,得点は降順
    if(a.s==b.s)return a.p>b.p;
    return a.s<b.s;
}

int main(){
    int n;cin>>n;
    vector<Dat> dat;
    rep(i,n){
        Dat tmp;
        cin>>tmp.s>>tmp.p;
        tmp.i=i+1;
        dat.PB(tmp);
    }
    sort(ALL(dat),mycmp);
    rep(i,n){
        cout<<dat[i].i<<endl;
    }
}


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

int main(){
  int N, M;
  cin >> N >> M;
  pair<int,int> A[N];
  for(int i=0;i<N;i++){
    cin >> A[i].first >> A[i].second;
  }
  sort(A, A+N);
  int64_t ans = 0;
  int j = 0;
  for(int i=0;i<M;i++){
    for(j;j<N;j++){
      if(A[j].second > 0){
        ans += A[j].first;
        A[j].second -= 1;
        break;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
n = int(input())
a_list = list(map(int, input().split()))

a_list = a_list + [0]

# sumの計算
s = 0
before = 0
for i in a_list:
    s += abs(before - i)
    before = i

# print(s)

diff = 0
before = 0

for ind, i in enumerate(a_list):
    # print("i: {}".format(i))
    new_diff = i - before
    if diff * new_diff >= 0:
        if ind != 0:
            print(s)

    else:
        if ind != 0:
            print(s - 2 * min(abs(diff), abs(new_diff)))

    diff = new_diff
    before = i

Measured memory_bytes: 14176
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
long long int __lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
 //__gcd 最大公約数
 //__lcm 最小公倍数

int main() {
  int a;
  cin>>a;
  if(a==1)
    cout<<4;
  else if(a==2)
    cout<<4;
  else{
    for(int i=0;i<100000;i++){
      if(a==4){
        cout<<i+4;
        break;
      }
      else if(a%2==0)
        a=a/2;
      else
        a=3*a+1;
    }
  }
}

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

using namespace std;

int a, b, i;
string s;

void INP()
{
    cin >> a >> b;
}

void Solve()
{
    if (a > b)
    {
        for (i = 1; i <= a; i++)
        {
            s += char(b + 48);
        }
    }
    else
    {
        for (i = 1; i <= b; i++)
        {
            s += char(a + 48);
        }
    }
    cout << s;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freoepn("B.INP", "r", stdin);
    //freoepn("B.OUT", "w", stdout);
    INP();
    Solve();
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;


int main() {
  string s;
  cin >> s;
  string ans = "";
  rep(i, s.size()) ans += "x";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	writer = bufio.NewWriter(os.Stdout)
)

func main() {
	defer writer.Flush()
	var N int
	fmt.Fscanf(reader, "%d\n", &N)
	for i := 0; i <= N; i += 7 {
		if (N-i)%4 == 0 {
			fmt.Fprintf(writer, "Yes\n")
			return
		}
	}
	fmt.Fprintf(writer, "No\n")
}


Measured memory_bytes: 640