akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

class Main {

	@SuppressWarnings("unchecked")
	public void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		System.out.println(0);
		String str1 = sc.next();
		if (str1.equals("Vacant")) {
			return;
		}
		System.out.println(N - 1);
		String str2 = sc.next();
		if (str2.equals("Vacant")) {
			return;
		}
		int s = 0;
		int t = N - 1;
		while (true) {
			int m = (s + t) / 2;
			System.out.println(m);
			String str = sc.next();
			if (str.equals("Vacant"))
				return;
			if ((s % 2 == m % 2) == (str1.equals(str))) {
				s = m;
				str1 = str;
			} else {
				t = m;
				str2 = str;
			}
		}
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


Measured memory_bytes: 24228
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int w = sc.nextInt();
            int n = sc.nextInt();
            int[] values = new int[w];
            for (int i = 0; i < values.length; i++) {
                values[i] = i + 1;
            }
            for (int i = 0; i < n; i++) {
                String str = sc.next();
                String[] ab = str.split(",");
                int a = Integer.parseInt(ab[0]) - 1;
                int b = Integer.parseInt(ab[1]) - 1;
                int value = values[a];
                values[a] = values[b];
                values[b] = value;
            }
            for (int j = 0; j < values.length; j++) {
                System.out.println(values[j]);
            }
        }
    }
}


Measured memory_bytes: 26100
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

using namespace std;
struct edge {int to; int cost;};
const int MAX_N = 100002;
int color[MAX_N];
vector<edge> G[MAX_N];

int flip(int c) {
  if(c == 0) return 1;
  else if (c == 1) return 0;
  else return -1;
}

bool dfs (int v, int c) {
  if (color[v] != -1) return false;
  color[v] = c;
  for (int i = 0; i < G[v].size(); i++) {
    int to = G[v][i].to;
    int w  = G[v][i].cost;
    if (w % 2 == 0) dfs(to, c);
    else dfs(to, flip(c));
  }
  return true;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  int N, u, v, w;
  cin >> N;
  for (int i = 0; i < N-1; i++) {
    cin >> u >> v >> w;
    edge e1, e2;
    e1.to = v; e1.cost = w;
    G[u].push_back(e1);
    e2.to = u; e2.cost = w;
    G[v].push_back(e2);
  }

  fill(color, color + MAX_N, -1);
  dfs(1, 0);

  for (int i = 1; i <= N; i++) cout << color[i] << " ";
  cout << endl;
  return 0;
}


Measured memory_bytes: 9216
#include <stdio.h>
#include <stdlib.h>
#define N 101
#define X 1000000
int main(){
  int i=0,top=1,num1=0,r;
  char s[X];
  long array[N];
  while( scanf("%s",s) !=  EOF){
    
    if(s[0]!='+' && s[0]!='-' && s[0]!='*') {
      num1=atoi(s);
      i++;
      array[i]=num1;
      continue;
    }
    
    if(s[0]=='+')      {num1=array[i-1]+array[i]; top=i-1; array[i-1]=num1; i=top;}
    else if(s[0]=='-') {num1=array[i-1]-array[i]; top=i-1; array[i-1]=num1; i=top;}
    else if(s[0]=='*') {num1=array[i-1]*array[i]; top=i-1; array[i-1]=num1; i=top;}
      
  }

  printf("%ld\n",array[i]);

  return 0;
}


Measured memory_bytes: 2100
import java.util.Scanner;

public class Main {

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

		double x1 = sc.nextDouble();
		double y1 = sc.nextDouble();
		double x2 = sc.nextDouble();
		double y2 = sc.nextDouble();

		double dis = Math.sqrt((x2 - x1)*(x2 - x1)+ (y2 - y1)*(y2 - y1));
		
		System.out.println(String.format("%.4f", dis));
		
		sc.close();
	}
}

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

int main(){
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
    	if(i%2==0){
    		if(s[i]=='L'){
			    cout<<"No"<<endl;
			    return 0;
			}
		}
		else if(i%2==1){
			if(s[i]=='R'){
			    cout<<"No"<<endl;
			    return 0;
		    }
		} 
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static ArrayList<HashMap<Integer, Integer>> graph;
    static int[] counts;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		counts = new int[n];
		for (int i = 1; i < n; i++) {
		    counts[i] = sc.nextInt();
		}
		graph = new ArrayList<>();
		for (int i = 0; i < n; i++) {
		    graph.add(new HashMap<>());
		}
		for (int i = 0; i < n - 1; i++) {
		    int a = sc.nextInt();
		    int b = sc.nextInt();
		    int c = sc.nextInt();
		    graph.get(a).put(b, c);
		    graph.get(b).put(a, c);
		}
		System.out.println(getCost(0, 0));
	}
	
	static int getCost(int from, int to) {
	    int sum = 0;
	    if (counts[to] != 0) {
	        return graph.get(from).get(to);
	    }
	    for (Map.Entry<Integer, Integer> entry : graph.get(to).entrySet()) {
	        if (entry.getKey() == from) {
	            continue;
	        }
	        if (getCount(to, entry.getKey()) == 0) {
	            continue;
	        }
	        sum += Math.min(getCost(to, entry.getKey()), entry.getValue());
	    }
	    return sum;
	}
	
	static int getCount(int from, int to) {
	    int sum = counts[to];
	    for (int x : graph.get(to).keySet()) {
	        if (x == from) {
	            continue;
	        }
	        sum += getCount(to, x);
	    }
	    return sum;
	}
}



Measured memory_bytes: 35676
import qualified Data.ByteString.Char8 as BS
import Data.Maybe (fromJust)
import Data.List

solve :: [Int] -> Int
solve = sum . (take 2) . sort

main :: IO()
main = do
    a <- map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
    print $ solve a 


Measured memory_bytes: 380
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
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; }

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int t,f,q;
char c;
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    deque<int> s;
    string S;
    cin >> S;
    for(auto x:S)s.push_back(x-'a');
    cin >> q;
    int sw = 0;
    rep(_,q){
        cin >> t;
        if(t==1){
            sw++;
            sw%=2;
        }else{
            cin >> f >> c;
            if(f==1 && sw==0){
                s.push_front(c-'a');
            }else if(f==1 && sw==1){
                s.push_back(c-'a');
            }else if(f== 2 && sw== 0){
                s.push_back(c-'a');
            }else s.push_front(c-'a');
        }
    }
    if(sw==0)for(auto x:s)cout << (char)(x+'a');
    else{
        reverse(ALL(s));
        for(auto x:s)cout << (char)(x+'a');
    }
    cout << endl;
}

Measured memory_bytes: 1872
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;


public class Main {

	int[][] rhombus;
	int[][] max;
	int row;
	
	int solve(){
		max[0][1]=rhombus[0][0];
		for(int i=1;i<row;++i){
			if(i<=row/2){
				for(int j=1;j<=i+1;++j){
					max[i][j]=Math.max(max[i-1][j-1],max[i-1][j])+rhombus[i][j-1];
				}
			}
			else{
				for(int j=1;j<=row-i;++j){
					max[i][j]=Math.max(max[i-1][j],max[i-1][j+1])+rhombus[i][j-1];
				}
			}
		}
		return max[row-1][1];
	}
	
	void io(){
		rhombus=new int[100][];
		max=new int[100][];
		BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
		String str;
		try {
			for(row=0;row<100&&(str=input.readLine())!=null;++row){
				StringTokenizer token=new StringTokenizer(str,",");
				int n=token.countTokens();
				rhombus[row]=new int[n];
				max[row]=new int[n+2];
				Arrays.fill(max[row],0);
				for(int i=0;i<n;++i){
					rhombus[row][i]=Integer.parseInt(token.nextToken());
				}
			}
			System.out.println(solve());
			
		}catch (IOException e) {
		}
	}

	public static void main(String[] args) {
		new Main().io();
	}

}

Measured memory_bytes: 19820
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  int n, k;
  cin >> n >> k;

  ll ans = 0;
  ll cnt1 = 0, cnt2 = 0;
  for (int i = 1; i <= n; ++i) {
    if (i % k == 0) cnt1 += 1;
    if (k % 2 == 0 and i % k == k / 2) cnt2 += 1;
  }
  // debug(cnt1);
  if (cnt1 or cnt2) {
    ans += cnt1 * cnt1 * cnt1;
    ans += cnt2 * cnt2 * cnt2;
  }
  cout << ans << endl;
}


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

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    
    vector<int> dp(n, INT_MAX);
    dp[0] = 0;

    for (int i = 0; i < n; i++)
    {
        for (int j : {i + 1, i + 2})
        {
            if (j < n)       
                dp[j] = min(dp[j], dp[i] + abs(a[i] - a[j]));
        }
    }
    cout << dp[n - 1] << endl;
    return 0;
}

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

const int md = 1e9 + 7;
const int maxn = 1e6 + 7;

int dp[maxn];
int suf[maxn];
int ss[maxn];

int main() {

	fill(dp,dp+maxn,0); fill(suf,suf+maxn,0); fill(ss,ss+maxn,0);

	int n; cin>>n; 
	if (n == 1) { cout<<1<<endl; return 0; }
	
	dp[n] = suf[n] = ss[n] = n-1;

	int n2 = ((long long)(n-1) * (n-1))%( (long long) md);

	for (int j = n-1; j >= 1; j--) {
		if (j == 1) dp[j] = (n + suf[2])%md;
		else dp[j] = n-1;

		dp[j] = (dp[j] + (n2 + ss[j+3])%md)%md;
		suf[j] = (suf[j+1] + dp[j])%md;
		ss[j] = (ss[j+1] + suf[j])%md;
	}

	cout<<dp[1]<<endl;
}


Measured memory_bytes: 11904
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>

const long INF = (1l << 30);
const long LINF = (1l << 60);

long l, r;
int main(){
    scanf("%ld%ld", &l, &r);
    if(r >= l + 2019){
        r = l + 2019*2;
    }
//    printf("%ld %ld\n", l, r);
    long min = LINF;
    for(long i = l; i <= r; i++){
        for(long j = i+1; j <= r; j++){
            /*
            if((i*j)%2019 < min){
                printf("%ld %ld : %ld\n", i, j, (i*j)%2019);
            }
            //*/
            min = std::min(min, (i*j)%2019);
        }
    }
    printf("%ld\n", min);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct A
{
    ll x,y;
};
bool cmp(A a,A b)
{
    if(a.y==b.y)
    {
        return a.x>b.x;
    }
    return a.y>b.y;
}
int par[100005];
int fnd(int x)
{
    if(par[x]==x) return x;
    return par[x]=fnd(par[x]);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m;
    while(cin>>n>>m)
    {
        vector<A> arr;
        for(int i=0; i<n; i++)
        {
            //par[i+1]=i+1;
            A a;
            cin>>a.x>>a.y;
            arr.push_back(a);
        }
        sort(arr.begin(),arr.end(),cmp);
        ll ans=0;
        //int day=1;
        m++;
        for(int i=0; i<=m; i++)
        {
            par[i]=i;
        }
        for(int i=0; i<n; i++)
        {
            ll req=m-arr[i].x;
            if(req>=1)
            {
                int f=fnd(req);
                if(f!=0)
                {
                    ans += arr[i].y;
                    //cout<<par[req]<<" "<<req<<" ";
                    par[f]=fnd(par[f]-1);
                    //cout<<par[req]<<endl;
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


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

#define ll long long

const int N = 100;

int n, a, b;
ll v[N], com[N][N];

ll comb(int n, int m){
	if (m < 0 || m > n){
		return 0;
	}
	if (m == 0 && n == 0){
		return com[0][0] = 1;
	}
	if (~com[n][m]){
		return com[n][m];
	}
	return com[n][m] = comb(n - 1, m) + comb(n - 1, m - 1);
}

int main(){
	memset(com, -1, sizeof(com));
	scanf("%d%d%d", &n, &a, &b);
	for (int i = 0; i < n; ++ i){
		scanf("%lld", &v[i]);
	}
	std::sort(v, v + n, std::greater <ll>());
	if (v[a - 1] == v[0]){
		int cnt = 0;
		for (int i = 0; i < n; ++ i){
			if (v[i] == v[0]){
				++ cnt;
			}
		}
		ll ans = 0;
		for (int i = a; i <= std::min(cnt, b); ++ i){
			ans += comb(cnt, i);
		}
		return printf("%.10lf\n%lld\n", (double) v[0], ans), 0;
	}
	int cnt1 = 0, cnt2 = 0;
	ll sum = 0;
	for (int i = 0; i < n; ++ i){
		if (v[i] > v[a - 1]){
			++ cnt1;
			sum += v[i];
		}
		else if (v[i] == v[a - 1]){
			++ cnt2;
		}
	}
	return printf("%.10lf\n%lld\n", (double) (sum + (a - cnt1) * v[a - 1]) / a, comb(cnt2, a - cnt1)), 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
using namespace std;

int main(){
	int A[5];
	for(int i=0;i<5;i++){
		cin >> A[i];
	}
	int ans = 1000000;
	for(int i=0;i<5;i++){
		int ansdash = 0;
		for(int j=0;j<5;j++){
			if(i != j){
				if(A[j] % 10) ansdash += A[j] + 10 - (A[j] % 10);
				else ansdash += A[j];
			}
			else ansdash += A[j];

		}
		ans = min(ansdash, ans);
	}
	cout << ans << endl;
}

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

input_data = []
for i in range(H):
    input_list = list(input())
    input_data.append(input_list)

input_H_list = []
for i in range(2 ** H):
    para_ = i
    temp_ = []
    for k in range(H):
        if para_ % 2 == 0:
            temp_.append(0)
        else:
            temp_.append(1)
        para_ = para_ // 2
    input_H_list.append(temp_)

input_W_list = []
for i in range(2 ** W):
    para_ = i
    temp_ = []
    for k in range(W):
        if para_ % 2 == 0:
            temp_.append(0)
        else:
            temp_.append(1)
        para_ = para_ // 2
    input_W_list.append(temp_)

ans_count = 0    
    
for H_list in input_H_list:
    for W_list in input_W_list:
        not_black_counter = 0
        for i in range(H):
            if H_list[i] == 1:
                not_black_counter += W
            else:
                
                for j in range(W):
                    if W_list[j] == 1:
                        not_black_counter += 1
                    else:
                        if input_data[i][j] == ".":
                            not_black_counter += 1
        if not_black_counter + K  == H * W:
            ans_count += 1
print(ans_count)
                

Measured memory_bytes: 9276
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;


int main(){
  int n;
  cin >> n;
  vector<vector<int> > p(n,vector<int> (3,0));
  vector<unsigned long> x(n,0);
  
  for(int i=0;i<n;++i){
    cin >> p[i][0] >> p[i][1] >> p[i][2];
    sort(p[i].begin(),p[i].end());
    x[i] = 100000000*p[i][0]+10000*p[i][1]+p[i][2];
  }
  sort(x.begin(),x.end());

  int cnt=0;
  for(int i=0;i<n-1;++i){
    if(x[i]==x[i+1]) cnt++;
  }

  cout << cnt << endl;
  
  return 0;
}



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

int main() {
    int n, m, p;
    while (cin >> n >> m >> p, n || m || p) {
        vector<int> x(n);
        int sum = 0;
        for (auto& i : x) cin >> i, sum+=i;

        if (x[m-1] > 0) cout << sum * (100 - p) / x[m-1] << endl;
        else cout << 0 << endl;
    }

    return 0;
}



Measured memory_bytes: 3084
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

D, G = map(int, input().split())
P = [] * D
C = [] * D
for i in range(D):
    p, c = map(int, input().split())
    P.append(p)
    C.append(c)

ans = float('inf')
for i in range(1<<D):
    total = 0
    num = 0
    for j in range(D):
        if ((i >> j) & 1):
            total += C[j] + 100*P[j]*(j+1)
            num += P[j]

    if total >= G:
        ans = min(ans, num)
    else:
        for j in range(D-1, -1, -1):
            if ((i >> j) & 1):
                continue

            for k in range(P[j]):
                if total >= G:
                    break
#                print(k, total, num)
                total += 100*(j+1)
                num += 1

#        print('x', k, total, num, ans)
        ans = min(ans, num)

print(ans)

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    int N;
    string S;
    cin >> N >> S;
    vector<int> a(N);
    rep(i, N) {
        if (S[i] == 'R') a[i] = 0;
        if (S[i] == 'G') a[i] = 1;
        if (S[i] == 'B') a[i] = 2;
    }

    vector<ll> cnt(3);
    rep(i, N) cnt[a[i]]++;
    ll ans = cnt[0] * cnt[1] * cnt[2];
    rep(j, N) {
        rep(i, j) {
            int k = j + (j - i);
            if (k < N) {
                if (a[i] == a[j]) continue;
                if (a[i] == a[k]) continue;
                if (a[k] == a[j]) continue;
                ans--;
            }
        }
    }

    cout << ans << endl;
}


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

int main() {
    long long n ,m, ans;
    cin >> n >> m;
    long long l[m], r[m];
    for(int i = 0; i < m; ++i) {
        cin >> l[i] >> r[i];
    }
    sort(l, l+m);
    sort(r, r+m);
    ans = r[0] - l[m-1] + 1;
    if(ans >= 0) {
        cout << ans << '\n';
    } else {
        cout << 0 << '\n';
    }
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main(void){
  int N;
  cin >> N;
  int before, H, temp;
  cin >> before;
  for(int i = 1; i < N; i++){
    cin >> H;
    if(H < before){
      cout << "No";
      return 0;
    }
    else if(H != before){
      before = H - 1;
    }
    else before = H;
  }
  
  cout << "Yes";
  
 return 0; 
}

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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef long double ld ;

const ll MOD = 998244353, INF = 2E18 + 5 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

int arr[100005] ;
vector <int> vec[100005] ;

int check(int node)
{
    if (vec[node].size() == 0)  return 0 ;
    if (arr[node] != -1)    return arr[node] ;
    for (int i = 0; i < vec[node].size(); i++) {
        arr[node] = max(arr[node], 1 + check(vec[node][i])) ;
    }
    return arr[node] ;
}

int main()
{
    int n, m, u, v, ans = 0 ;
    cin >> n >> m ;
    for (int i = 0; i <= n; i++) {
        arr[i] = -1 ;
    }
    for (int i = 0; i < m; i++) {
        scanf("%d %d", &u, &v) ;
        vec[u].push_back(v) ;
    }
    for (int i = 1; i <= n; i++) {
        ans = max(ans, check(i)) ;
    }
    cout << ans ;

    return 0 ;
}


Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,x;
    cin>>n>>x;
    vector<ll> a(n+1,0);
    FOR(i,1,n+1) cin>>a[i];
    ll ans=0;
    rep(i,n){
      ll sum=a[i]+a[i+1];
      if(sum>x){
        ans+=sum-x;
        a[i+1]-=sum-x;
      }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back 
#define pf push_front 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i,n) for(int i=0;i<(n);i++)
#define All(v) v.begin(),v.end()
typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;


main()
{
  int N;
  string s[101];

  cin >> N;
  Rep(i, N) cin >> s[i];

  int ac = 0, unc = 0;
  bool flag = true;
  Rep(i, N) {
    if( s[i] == "A" ) {
      ac++;
    }
    else {
      unc++;
      if( unc > ac ) {flag = false; break;}
    }
  }

  if( flag ) {
    if( ac == unc ) cout << "YES" << endl;
    else cout << "NO" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 3168
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 1
#define INF (1LL<<50)
 
int gcd(lli x,lli y)
{
        if (y == 0) {
                return x;
        } else {
                return gcd(y, x % y);
        }
}
 
signed main(){
 
	lli n,k;
	cin>>n>>k;
	vector<lli> a(n);
	lli maxA=0;
	REP(i,0,n){
		cin>>a[i];
		maxA = max(maxA,a[i]);
	}
 
	lli num = gcd(max(a[0],a[1]),min(a[0],a[1]));
	REP(i,2,n)num = gcd(max(num,a[i]),min(num,a[i]));
 
	if(k>maxA){
		cout<<"IMPOSSIBLE"<<endl;
	}
	else if(k%num==0){
		cout<<"POSSIBLE"<<endl;
	}
	else{
		cout<<"IMPOSSIBLE"<<endl;
	}
 
	return 0;
}

Measured memory_bytes: 1024
import sys
input=sys.stdin.readline
N=int(input())
P=[tuple(map(int,input().split())) for i in range(N)]
X=[(i,P[i][0]) for i in range(N)]
Y=[(i,P[i][1]) for i in range(N)]
X.sort(key=lambda x:x[1])
Y.sort(key=lambda x:x[1])
Z=[(X[i][0],X[i+1][0],X[i+1][1]-X[i][1]) for i in range(N-1)]+[(Y[i][0],Y[i+1][0],Y[i+1][1]-Y[i][1]) for i in range(N-1)]
Z.sort(key=lambda x:x[2])
root=[-1]*N
def search(i):
    global root
    if root[i]>=0:
        root[i]=search(root[i])
        return root[i]
    return i
ans=0
for i,j,k in Z:
    ri=search(i)
    rj=search(j)
    if ri==rj:
        continue
    elif root[ri]<=root[rj]:
        root[ri]+=root[rj]
        root[rj]=ri
        ans+=k
    else:
        root[rj]+=root[ri]
        root[ri]=rj
        ans+=k
print(ans)

Measured memory_bytes: 63736
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    sort(ALL(a));
    map<int, queue<int>> m;
    rep(i, n){
        if(m.find(a[i]) == m.end()){
            m[a[i]] = queue<int>();
        }
        m[a[i]].push(i);
    }

    vector<int> two;
    two.push_back(1);
    rep(i, 30){
        two.push_back(two[i] * 2);
    }

    int ans = 0;
    vector<bool> used(n, false);
    for(int i = n - 1; i >= 0; i--){
        if(used[i]){
            continue;
        }
        rep(j, 31){
            int dst = two[j] - a[i];
            int ok = false;
            if(m.find(dst) == m.end()){
                continue;
            }
            int head = m[dst].front();
            while(not m[dst].empty()){
                int idx = m[dst].front();
                m[dst].pop();

                if(used[idx] || idx == i){
                    m[dst].push(idx);
                    if(m[dst].front() == head){
                        break;
                    }
                    continue;
                }
                ans++;
                used[idx] = true;
                used[i] = true;
                ok = true;
                break;
            }
            if(ok){
                break;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 831872
#define MOD_TYPE 1

#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
using multiInt = boost::multiprecision::cpp_int;
*/
/*
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
*/
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
constexpr int INF = (int)1e9;
constexpr ll LINF = (ll)4e18;
constexpr ld PI = acos(-1.0);
constexpr ld EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

inline void init_main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
}
template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
#pragma endregion

int main()
{
  init_main();

  ll n;
  cin >> n;
  ll a[5];
  rep(i, 5) cin >> a[i];
  ll Min = *min_element(a, a + 5);
  cout << CEIL(n, Min) + 4 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000009;

int main(){
	map<string,bool> mp;
	int n;
	cin >> n;
	for(int i =0;i < n;i++){
		string s;
		cin >> s;
		mp[s] = true;
	}

	cout << mp.size() << endl;
}


Measured memory_bytes: 19044
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	var n, k, r, s, p int
	var t string
	fmt.Scanf("%d %d", &n, &k)
	fmt.Scanf("%d %d %d", &r, &s, &p)
	fmt.Scanf("%s", &t)

	m := map[int]string{}
	for i:=0;i<n;i++ {
		m[i%k] += string(t[i])
	}

	total := 0
	for _, str := range m {
		total += subTotal(str, r, s, p)
	}

	fmt.Printf("%d",total)
}

func subTotal(str string, r, s, p int) int {
	total := 0
	pre := '0'
	for _, c := range str {
		if c == 'r' && pre != 'p' {
			total += p
			pre = 'p'
		} else if c == 's' && pre != 'r' {
			total += r
			pre = 'r'
		} else if c == 'p' && pre != 's' {
			total += s
			pre = 's'
		} else {
			pre = '0'
		}
	}
	return total
}


Measured memory_bytes: 14080
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
 
using namespace std;
 
//container util
//------------------------------------------
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
 
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).end()) i=(c).end(); i!=(c).begin(); --i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
 
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).begin(),(c).end(),greater<int>())
 
#define PB(a) push_back(a)
#define PF(a) pop_front(a)
 
#define MP(a,b) make_pair(a,b)
 
#define FS first
#define SE second
 
#define ALL(x) (x).begin(),(x).end()
#define MAX_EL(c) *max_element((c).begin(),(c).end())
#define MIN_EL(c) *min_element((c).begin(),(c).end())
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef string str;
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 
 
//------show vector---------
template <typename T>
void showV(vector < T > a){
  EACH(i,a){
    cerr << *i << ',';
  }  
  cerr << endl;
}
 
//------show matrix---------
template <typename T>
void showVV(vector < vector < T > > a){
  EACH(i,a){
    showV(*i);
  }  
}
//grobal var
//------------------------------------------
LL dp[2000][2000];
 
int main(){
// magic spell------------------------------
  cin.tie(0);
  ios::sync_with_stdio(false);
//------------------------------------------
  int N;
  while(cin >> N){
    VI av;
    REP(i,N){
      int a;
      cin >> a;
      av.PB(a);
    }
    VI bv = av;
    RSORT(bv);
    EACH(i,av){
    int ans = *(bv.begin());
    if(*i==ans) ans = *(bv.begin()+1);
    cout << ans << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e14;
const int ZERO = 0;
const int MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

signed main() {
    string S,T;
    cin >> S >> T;
    vector<int> s[26];
    for(int i = 0;i < S.size();i++) {
        s[S.at(i) - 'a'].push_back(i + 1);
    }
    int ret = 0;
    for(int i = 0;i < T.size();i++) {
        int A = T.at(i) - 'a';
        if(s[A].empty()) {
            cout << -1 << endl;
            return 0;
        }
        int cnt = ret / S.size() * S.size();
        int cnt2 = ret % S.size();
        auto itr = upper_bound(s[A].begin(), s[A].end(), cnt2);
        int cnt3 = itr - s[A].begin();
        if(cnt3 == s[A].size()) {
            ret = cnt + S.size() + s[A].at(0);
        }
        else {
            ret = cnt + s[A].at(cnt3);
        }
    }
    cout << ret << endl;
}

Measured memory_bytes: 1724
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
bool vis[100005];
int dp[100005];
vector<int> adj[100005];
void dfs(int u){
	vis[u]=true;
	for(auto v:adj[u]){
		if(!vis[v]){
			dfs(v);
		}
		dp[u]=max(dp[v]+1,dp[u]);
	}
}
int main() {
	// your code goes here
	int n,m,i,a,b;
	cin>>n>>m;
	for(i=0;i<m;i++){
		cin>>a>>b;
		adj[a].pb(b);
	}
	for(i=0;i<=n;i++){
		dp[i]=0;
		vis[i]=false;
	}
	for(i=1;i<=n;i++){
		if(vis[i]==false){
			dfs(i);
		}
	}
	int maxi=INT_MIN;
	for(i=1;i<=n;i++){
		maxi=max(maxi,dp[i]);
	}
	cout<<maxi<<endl;
	return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 string c;
 cin >> c;
 if(c.at(0) == 'a' || c.at(0) == 'i' || c.at(0) == 'u' || c.at(0) == 'e' || c.at(0) == 'o'){
   cout << "vowel" << endl;
 }
 else{
   cout << "consonant" << endl;
 }
 
}
  

Measured memory_bytes: 3596
s = str(input())
MOD = 2019
modl = [0 for _ in range(2019)]
modl[0] = 1
cnt = 1
x = 0
for i in range(len(s)):
	x = (x+(int(s[len(s)-1-i])*cnt))%MOD
	modl[x] += 1
	cnt = (cnt*10)%MOD

ans = 0
for i in range(2019):
	z = modl[i]
	ans += (z*(z-1))//2
print(ans)

Measured memory_bytes: 9264
#include <iostream>
#include <vector>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <bits/stdc++.h>

using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;


int main() {

    ll N,A,tmp;
    cin >> N >> A;

    tmp = N % 500;

    string res = "No"; 

    if(tmp <= A)
    {
        res = "Yes";
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIII pair< int, pair<int,int> >
const int MXN = 1e5;
int a[MXN+5], dp[MXN+5];
int N,K;

int rec(int pos){

    if(pos==N) return 0;
    if(pos>=N) return 1<<30;
    if(dp[pos]!=-1) return dp[pos];
    return dp[pos] = min( rec(pos+1) + abs(a[pos+1]-a[pos]) , rec(pos+2) + abs(a[pos+2]-a[pos]) );
}

void solve(){

    cin>>N;
    memset(dp,-1,sizeof(dp));
    for(int i=1; i<=N; i++) cin>>a[i];
    cout<< rec(1) << "\n";
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}

Measured memory_bytes: 7460
from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush,heappop
from math import floor,ceil
from collections import *
from functools import reduce,cmp_to_key
import sys
input = sys.stdin.readline

M = mod = 998244353
def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))
def inv_mod(n):return pow(n, mod - 2, mod)

def li():return [int(i) for i in input().rstrip('\n').split()]
def st():return input().rstrip('\n')
def val():return int(input().rstrip('\n'))
def li2():return [i for i in input().rstrip('\n').split(' ')]
def li3():return [int(i) for i in input().rstrip('\n')]


s = st()
q = val()
l = []

cou = 0

d = deque()
for i in s:d.append(i)


for j in range(q):
    l = li2()
    if len(l) == 1:cou = not cou
    else:
        if cou:
            a = 3 - int(l[1])
        else:a = int(l[1])
        if a == 2:
            d.append(l[-1])
        else:d.appendleft(l[-1])

s = ''.join(e for e in d)
if cou:s = s[::-1]
print(s)



Measured memory_bytes: 9056
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int A, B;
    cin >> A >> B;

    int ans = 0;
    for(int i = 0; i < 2; i++){
        if(A >= B){
            ans += A;
            A--;
        }else{
            ans += B;
            B--;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

void solve(ll N, ll M, vector<string> A, vector<string> B) {
  int W = N - M + 1;
  REP(i,W) REP(j,W) {
    bool ok = true;
    REP(ii,M) REP(jj,M) {
      if (A[i+ii][j+jj] != B[ii][jj]) ok = false;
    }
    if (ok) {
      cout << true << endl;
      return;
    }
  }
  cout << false << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll N;
	ll M;
	scanf("%lld", &N);
	vector<string> A(N-1+1);
	scanf("%lld", &M);
	vector<string> B(M-1+1);
	for (int i = 0 ; i <= N-1 ; i++) {
	  cin >> A[i];
	}
	for (int i = 0 ; i <= M-1 ; i++) {
	  cin >> B[i];
	}
	solve(N, M, A, B);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<deque>
#include<string>
using namespace std;
#define ll long long
#define pb push_back
#define end "\n"
#define lar 1000000007;
int main()
{
    char a;
    cin>>a;
    if(a>='A'&&a<='Z')cout<<'A';
    else cout<<'a';
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)


int main(){
   int n,k;
   cin >> n >> k;
   double ans=0.0;
   for (int i=1;i <= n;i++){
      int cnt = 0;
      int tmp = i;
      while (tmp < k){
         cnt++;
         tmp*=2;
      }
      double pre = 1.0;
      for (int j=0;j < cnt;j++){
         pre /= 2.0;
      }
      ans+=pre;
   }
   printf("%.10f\n",ans/n);
   return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]
#[allow(unused_imports)]
use std::io::{self, Write};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
     };
     ($next:expr, $t:ty) => {
         $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
const MOD: u64 = 1000000007;
#[allow(dead_code)]
fn to_num(c: char) -> i64 {
    c as i64 - 48
}


fn main() {
    input!{
        s: chars
    }
    let P = s.iter().fold(0, |acc, &c| acc + if c=='p' {1} else {0});
    println!("{}", s.len() / 2 - P) ;
}

Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long int
int main() {
	ll n, a[100005], result;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	result = a[0];
	for (int i = 1; i < n; i++) {
		result = __gcd(result, a[i]);
	}
	cout << result << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<cmath>
#include<bitset>
#include<cassert>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<iomanip>
#include<fstream>
using namespace std;
typedef long long ll;
typedef long double ld;
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
 
int main()
{
    fast_io;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int x;
    cin >> x;

    if (x == 0)
        cout << 1 << endl;
    else 
        cout << 0 << endl;

    return 0;
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin>>n;
	vi v(n);
	REP(i,n)cin>>v[i];
	if(is_sorted(ALL(v))){
		cout<<"YES"<<endl;
		return 0;
	}
	REP(i,n)FOR(j,i+1,n){
		swap(v[i],v[j]);
		if(is_sorted(ALL(v))){
			cout<<"YES"<<endl;
			return 0;
		}
		swap(v[i],v[j]);
	}
	cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int i,data[5]={0},ave=0;
  for(i=0;i<5;i++){
    scanf("%d",&data[i]);
  }
  for(i=0;i<5;i++){
    if(data[i]<40){
      data[i]=40;
    }
    ave += data[i];
  }
  printf("%d\n",ave/5);
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int K;
  cin>>K;
  
  
  int i=1;
  
  int L;
  if(K%7==0){
    L=9*K/7;
  }
  else{
    L=9*K;
  }
  
  int check=10%L;
  
  
  if(K%2==0||K%5==0){
    i=-1;
    cout<<i<<endl;
  }
  else{
    while(true){
    if(check==1){
      cout<<i<<endl;
      break;
    }
    check=(check*10)%L;
    i++;
    }
  }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 998244353

using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	ll A, V, B, W, T;
	cin >> A >> V >> B >> W >> T;
	if (abs(A - B) <= T* (V - W))
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}


Measured memory_bytes: 3624
s = list(map(int, list(input())))[::-1]

sum = 0
cnt = [0] * 2019
cnt[0] = 1
n = len(s)
#print(s)
for i in range(n):
    d = s[i] * pow(10, i, 2019)
    sum = (sum + d) % 2019
    cnt[sum] += 1
ans = 0
for i in range(2019):
    ans += cnt[i] * (cnt[i]-1)//2

print(ans)

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

using namespace std;

int main(){
  long long n;
  cin >> n;
  vector<int> ans;
  while(n>0){
    ans.push_back((n-1)%26);
    n=(n-1)/26;
  }
  for(int i=ans.size()-1;i>=0;i--){
    printf("%c", ans[i]+'a');
  }
  cout << endl;
}



Measured memory_bytes: 3628
#include<iostream>
#include <cmath>
using namespace std;
int main()
{
    long long a ,b ,c;
    cin >> a >> b >> c;
    if(a>c){
        cout << (a-c) << " " << b;

    }else{
        c=c-a;
        a=0;
        if(b>c){
            cout << 0 << " " << (b-c);
        }else{
            cout << 0 << " " << 0;
        }
    }
    
    
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 1009
using namespace std;
typedef long long LL;
const LL mod = 1e9+7;

int a[N];

int main()
{
    int n, k;
    scanf("%d%d", &n, &k);
    for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
    sort(a+1, a+1+n);
    int ans = 0;
    for(int i = n; i > n - k; i--)
    {
        ans += a[i];
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 2;

int main(){
    
    
      char ch;
	  scanf("%c", &ch);
	  if(ch == 'A') printf("T\n");
	  else if(ch == 'T') printf("A\n");
	  else if(ch == 'C') printf("G\n");
	  else if(ch == 'G') printf("C\n");
	  return 0;
}

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

#define INF 1LL << 30;
typedef long long ll;

// Nバーガーは1+N-1バーガー+1+N-1バーガー+1
// Nバーガーの厚さはをl(N)とすると
// Nバーガーのパティーをp(N)とすると
// p(N) = 2*p(N-1) + 1
// l(N) = 2*l(N-1) + 3であり
// f(N,X)をパティの枚数とすると、
// f(N,X) = 0 (X=1)
// f(N,X) = f(N-1,X-1) ()
// f(N,X) = p(N-1)+1 (X=l(N-1)+2)
// f(N,X) = f(N-1,X-l(N-1)-2) + p(N-1)+1 ()
// f(N,X) = 2*p(N-1) + 1

ll N,X;
vector<ll> l,p;
ll rec(ll n, ll x);

int main() {

  cin >> N >> X;
  l = vector<ll>(N+1);
  p = vector<ll>(N+1);
  l[0] = 1;
  p[0] = 1;
  for (int i=0;i<N;i++){
    l[i+1] = 2*l[i]+3;
    p[i+1] = 2*p[i]+1;
  }
  cout << rec(N,X) << endl;
}

ll rec(ll n, ll x){
  if (n==0) {
    if (x<=0){
      return 0;
    } else {
      return 1;
    }
  }
  if (x==1){
    return 0;
  } else if (x<l[n-1]+2){
    return rec(n-1,x-1);
  } else if (x==l[n-1]+2){
    return p[n-1]+1;
  } else if (l[n-1]+2 < x && x < 2*l[n-1]+3){
    return rec(n-1,x-l[n-1]-2)+p[n-1]+1;
  } else {
    return 2*p[n-1]+1;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 200100;
ll arr[maxn], n, l;
ll pref[maxn], temp[maxn];
ll suff[maxn], sufftemp[maxn];

ll solve() {
    memset(pref,0,sizeof(pref));
    memset(suff,0,sizeof(suff));
    memset(sufftemp,0,sizeof(sufftemp));
    for(int i=1;i<=n;i++) {
        pref[i] = pref[i-1] + arr[i];
    }
    for(int i=n;i>=1;i--) {
        sufftemp[i] = sufftemp[i+1] + l - arr[i];
        suff[n-i+1] = sufftemp[i];
    }
    ll result = 0LL;
    for(int i=1;i<=n;i++) {
        // rotate over the first i points if first move is clockwise
        ll rest = n - i;
        ll right = rest / 2;
        ll left = (rest+1)/2;
        ll rightcost = 2 * (pref[i+right] - pref[i-1]);
        ll leftcost = 2 * suff[left];
        if(rest % 2 == 0) rightcost -= arr[i+right];
        else leftcost -= l - arr[n-left+1];
        //cout<<i<<": "<<arr[i]<<" -> "<<leftcost<<", "<<rightcost<<"\n";
        result = max(result, rightcost + leftcost);
    }
    return result;
}

int main() {
    cin>>l>>n;
    for(int i=1;i<=n;i++) {
        cin>>arr[i];
    }

    ll result = solve();
    //cout<<result<<"\n";
    for(int i=1;i<=n;i++) {
        temp[i] = l - arr[i];
    }
    for(int i=1;i<=n;i++) {
        arr[i] = temp[n-i+1];

    }
    result = max(result, solve());
    cout<<result<<"\n";
    return 0;
}


Measured memory_bytes: 8064