akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    long long int n;
    vector<long long int> v(5);
    cin>>n;
    REP(i,5){
        cin>>v[i];
    }
    long long int result = 5;
    sort(v.begin(), v.end());
    result += (n-1) / v[0];
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
  long l, r;
  std::cin >> l >> r;
  long min = 2019L;
  if(r-l+1 >= 2019L)
  {
    std::cout << 0 << std::endl;
    return 0;
  }
  
  long size = r-l+1;
  long *rem = new long[size];
  for(long i=0; i<size; i++)
    rem[i] = (l+i)%2019L;
  
  for(long i=0; i<size-1; i++)
    for(long j=i+1; j<size; j++)
    {
      long mod = (rem[i]*rem[j])%2019L;
      min = (mod<min)? mod : min;
    }
  std::cout << min << std::endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
        int n = sc.nextInt();
        int m = sc.nextInt();
        int l = sc.nextInt();
 
        long a[][] = new long[n][m];
        long b[][] = new long[m][l];
 
        long c[][] = new long[n][l];
 
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                a[i][j] = sc.nextLong();
            }
        }
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < l; j++) {
                b[i][j] = sc.nextLong();
            }
        }
 
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                for (int k = 0; k < l; k++) {
                    c[i][k] += a[i][j]*b[j][k];
                }
            }
        }
 
        for (int i=0; i<n; i++) {
            for (int j=0; j<l-1; j++) {
                System.out.print(c[i][j]+" ");
            }
            System.out.println(c[i][l-1]);
        }
 
    }
}

Measured memory_bytes: 55064
import java.util.HashMap;
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    HashMap<Integer,Integer>hm = new HashMap<Integer, Integer>();
    
       int n = sc.nextInt();
       int maxnum = 0;
       int minnum = 0;
     
       int []a = new int [n];
       
       for(int i = 0; i < n ;i++) {
    	   a[i] = sc.nextInt();
       }
       
      
       for(int i = 0 ; i < n ;i++) {
    	   if(hm.get(a[i]) == null) {
    		   hm.put(a[i], 1);
    	   }
    	   else {
    		   hm.put(a[i], hm.get(a[i])+ 1);
    	   }
    	   if(hm.get(a[i]-1) == null) {
    		   hm.put(a[i]-1, 1);
    	   }
    	   else {
    		   hm.put(a[i]-1, hm.get(a[i]-1)+ 1);
    	   }
    	   if(hm.get(a[i]+1) == null) {
    		   hm.put(a[i]+1, 1);
    	   }
    	   else {
    		   hm.put(a[i]+1, hm.get(a[i]+1)+ 1);
    	   }
       }
       
       for(int num : hm.keySet()) {
    	   maxnum = Math.max(hm.get(num), maxnum);
       }
       
       System.out.println(maxnum);
       
       
	}


}


Measured memory_bytes: 57584
import sys
import math
import itertools
import collections
from collections import deque
from collections import defaultdict

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD2 = 998244353
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    K, T = NMI()
    A = NLI()

    max_A = max(A)
    
    if T == 1:
        print(K-1)
    else:
        if max_A <= math.ceil(K/2):
            print(0)
        else:
            if K % 2 == 0:
                print(2*(max_A-math.ceil(K/2))-1)
            else:
                print(2*(max_A-math.ceil(K/2)))


if __name__ == '__main__':
    main()

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

int main(void){
    int n;
    long long count = 0, sum = 0;

    cin >> n;
    
    vector<long long> d(n), u(n);
    vector<string> s(n);

    rep(i, n){
        cin >> s.at(i);
        sort(s.at(i).begin(), s.at(i).end());
    }
    
    sort(s.begin(), s.end());
  
    rep(i, n-1){
            if(s.at(i) == s.at(i+1)){
                count++; 
                sum += count;
            } else {
                count = 0;
            }
    }
    
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 8832
N,M,K=map(int,input().split())
P=1000000007
import math
print(M*N*(M+N)*(M*N-1)//6*math.factorial(N*M-2)*pow(math.factorial(K-2),P-2,P)*pow(math.factorial(N*M-K),P-2,P)%P)


Measured memory_bytes: 100888
import std.stdio, std.c.string;

int dp[5][4001];

int solve_rec(int n, int index) {
  if (index > 4 || n < 0) return 0;
  if (n == 0 && index == 4) return 1;
  if (dp[index][n] >= 0) return dp[index][n];
  int counter;
  for(int i = 0; i <= 1000; i++) {
    counter += solve_rec(n - i, index + 1);
  }
  return dp[index][n] = counter;
}

void main() {
  memset(cast(void *)dp, -1, dp.sizeof);
  for(int n; readf("%d\n", &n);)
    solve_rec(n, 0).writeln;
}

Measured memory_bytes: 1144
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,x = LI()
    a = LI()
    t = [abs(c-x) for c in a if x != c]
    g = min(t)
    for c in t:
        g = fractions.gcd(c,g)

    return g


print(main())


Measured memory_bytes: 16640
#include "bits/stdc++.h"
using namespace std;
using LL=long long;

const int INF = 1'000'000'000;
const long long INFLL = 1'000'000'000'000'000'000;

using Weight=int;
using P=pair<Weight, int>;
struct Edge {
	int to; Weight cost;
	Edge(int _to, Weight _cost) :to(_to), cost(_cost) {}
};
bool operator>(const Edge& e1, const Edge& e2) { return e1.cost > e2.cost; }
struct Edge2 { int u, v; Weight cost; };
using Graph=vector<vector<Edge>>;

void Dijkstra(const Graph& graph, vector<Weight>& dist, int s) {
	int V = graph.size();
	dist.assign(V, INF); dist[s] = 0;

	priority_queue<Edge, vector<Edge>, greater<Edge>> pq;
	pq.emplace(s, 0);

	while (!pq.empty()) {
		Edge p = pq.top(); pq.pop(); int v = p.to;
		if (dist[v] < p.cost)continue;
		for (auto e : graph[v]) {
			if (dist[e.to] > dist[v] + e.cost) {
				dist[e.to] = dist[v] + e.cost;
				pq.emplace(e.to, dist[e.to]);
			}
		}
	}
}

int main() {
	int v, e, r; cin >> v >> e >> r;
	Graph g(v);
	for (int i = 0; i < e; i++) {
		int s, t, d; cin >> s >> t >> d;
		g[s].emplace_back(t, d);
	}
	vector<Weight> dist;
	Dijkstra(g, dist, r);
	for (auto aa : dist) {
		if (aa == INF)cout << "INF" << endl;
		else cout << aa << endl;
	}
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define REP(i,n) for (int i = 0; i < n; ++i)
#define FORE(x,xs) for (auto x : xs)
#define PB(x) push_back(x)
#define MP(x, y) make_pair(x, y)

const int MAX = 1e5+10;

int N, K, root;
vi edges[MAX];
vi children[MAX];
int parent[MAX];
vi val;
vii range;
bool isOdd[MAX];

void makeTree(int n) {
    FORE (m, edges[n]) if (children[m].size() == 0) {
        children[n].PB(m);
        parent[m] = n;
        isOdd[m] = !isOdd[n];
        makeTree(m);
    }
}

bool dfs(int n) {
    int v = val[n];
    if (v != -1) {
        if (range[n].first <= v && v <= range[n].second && ((v&1) == isOdd[n])) {
            range[n] = MP(v,v);
        } else return false;
        FORE (m, children[n]) {
            range[m] = MP(v-1, v+1);
            if (!dfs(m)) return false;
        }
        range[parent[n]].first = max(range[parent[n]].first, v-1);
        range[parent[n]].second = min(range[parent[n]].second, v+1);
        if (parent)
        return true;
    } else if (children[n].size() == 0) {
        return true;
    } else {
        FORE (m, children[n]) {
            range[m] = MP(range[n].first-1, range[n].second+1);
            if (!dfs(m)) return false;
            range[parent[n]].first = max(range[parent[n]].first, range[n].first-1);
            range[parent[n]].second = min(range[parent[n]].second, range[n].second+1);
        }
        return true;
    }
}

void solution(int n) {
    int v = val[n];
    FORE (m, children[n]) {
        if (range[m].second >= v+1) {
            val[m] = v+1;
        } else {
            val[m] = v-1;
        }
        solution(m);
    }
}

void answer() {
    REP (i, N) cout << val[i] << endl;
}

int main() {
    cin >> N;
    val = vi(N, -1);
    range = vii(N, MP(-1e7, 1e7));
    REP (i, N-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        edges[a].PB(b);
        edges[b].PB(a);
    }
    cin >> K;

    root = -1;
    REP (k, K) {
        int v, p;
        cin >> v >> p;
        v--;
        if (root == -1) {
            root = v;
            isOdd[v] = p&1;
        }
        val[v] = p;
        range[v] = MP(p,p);
    }
    parent[root] = -1;

    makeTree(root);
  
    if (dfs(root)) {
        cout << "Yes" << endl;
        solution(root);
        answer();
    } else {
        cout << "No" << endl;
    }
}

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

int main() {
 int N,X;
 cin >> N >> X;
 vector<int>a(109);
 for(int i=0; i<N; i++) {
   cin >> a.at(i);
 }
 int D=0;
 int cnt=0;
 for(int i=0; i<N; i++) {
   D += a.at(i);
   if(D<=X) cnt++;
 }
 cout << cnt+1 << endl;
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
char a[100];
REP(i,3) {
  cin >> a;
  cout << a[0];
}
cout << endl;
return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

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

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

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  lint a,b,x;
  cin>>a>>b>>x;
  if(a==0){
    cout<<b/x+1;
  }else{
    cout<<b/x-(a-1)/x;
  }


  return 0;
}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int a = scan.nextInt();
	int b = scan.nextInt();
	int c = scan.nextInt();
	if (c>=a&&c<=b) {
		System.out.println("Yes");
	}else {
		System.out.println("No");
	}
}
}


Measured memory_bytes: 21204
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int h,w;
        while(true){
            h = scan.nextInt();
            w = scan.nextInt();
            if(h == 0 && w == 0) break;
            for(int i=0;i<h;i++){
                for(int j=0;j<w;j++){
                    if(i == 0 || i == h-1 || j == 0 || j == w-1) System.out.print("#");
                    else System.out.print(".");
                }
                System.out.println();
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 32816
#include<iostream>
#include<string>
using namespace std;
int N_MAX = 100000;
int main()
{
  int n,i,j,res;
  int p[N_MAX],c[4][2]={{0,0},{0,1},{1,0},{1,1}};
  string s;
  cin >> n >> s;
  for(i=0;i<4;i++){
    p[0]=c[i][0];
    p[1]=c[i][1];
    for(j=1;j<=n-2;j++){
      if(s[j]=='o')
        p[j+1]=(p[j]+p[j-1])%2;
      else
        p[j+1]=1-(p[j]+p[j-1])%2;
    }
    if(s[n-1]=='o'&&(p[n-2]+p[n-1]+p[0])%2==1
       || s[n-1]=='x'&&(p[n-2]+p[n-1]+p[0])%2==0
       || s[0]=='o'&&(p[n-1]+p[0]+p[1])%2==1
       || s[0]=='x'&&(p[n-1]+p[0]+p[1])%2==0)
      continue;
    for(j=0;j<n;j++){
      if(p[j]==0)
        cout << "S";
      else
        cout << "W";
    }
    cout << endl;
    return 0;
  }
  cout << "-1" << endl;
  return 0;
}

Measured memory_bytes: 4128
#include <stdio.h>

int main(void){
int S,y,m; 
scanf("%d",&S);
m = S%100;
y = (S-m)/100;

//printf("%d %d",y,m);//debag

if(0<m&&m<=12){
	if(0<y&&y<=12){ 
	printf("AMBIGUOUS");
	return 0;
	}
printf("YYMM");
return 0;
}

if(0<y&&y<=12){
printf("MMYY");
return 0;
}

printf("NA");
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>                        
#define pb push_back                            
#define mp make_pair                            
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)((x).size())
#define jonathan ios_base::sync_with_stdio(0)
#define livingston cin.tie(0)
using namespace std;                            
                                                
void yes() {cout << "Yes" << endl;}                                               
void no() {cout << "No" << endl;}                                                        
                                                
int dx[] = {1, 0, -1, 0, -1, -1, 1, 1};         
int dy[] = {0, 1, 0, -1, -1, 1, -1, 1}; 

const int INF = 1e9 + 9;
const long long LINF = 1e18 + 8;
const double EPS = 1e-9;
const long long MOD = 1e9 + 7; //998244353
const double PI = acos(-1);

void solve() {
    int n; cin >> n;
    long long res = 0;
    long long last = 0;
    for (int i = 0; i < n; i++) {
        long long x; cin >> x;
        x--;
        long long d = x / (last + 1);
        res += d;
        if (d > 0) last = max(last, 1ll);
        else last = max(last, x + 1);
    }
    cout << res << endl;
}   

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

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int INF = 1e9;
struct point{
  ll x, y;
  point() {
    x = 0;
    y = 0;
  }
  point(ll a, ll b) {
    x = a;
    y = b;
  }
};
int main() {
  int n, k;
  cin >> n >> k;
  point p[51];
  for (int i = 0; i < n; i++) {
    cin >> p[i].x >> p[i].y;
  }
  ll ans = 4e18;
  for (int p1 = 0; p1 < n; p1++) {
    for (int p2 = 0; p2 < n; p2++) {
      for (int p3 = 0; p3 < n; p3++) {
        for (int p4 = 0; p4 < n; p4++) {
          ll xmax = -1e9, ymax = -1e9, xmin = 1e9, ymin = 1e9;
          xmax = max(xmax, max(p[p1].x, max(p[p2].x, max(p[p3].x, p[p4].x))));
          ymax = max(ymax, max(p[p1].y, max(p[p2].y, max(p[p3].y, p[p4].y))));
          xmin = min(xmin, min(p[p1].x, min(p[p2].x, min(p[p3].x, p[p4].x))));
          ymin = min(ymin, min(p[p1].y, min(p[p2].y, min(p[p3].y, p[p4].y))));
          int cnt = 0;
          for (int i = 0; i < n; i++) {
            if (xmin <= p[i].x && p[i].x <= xmax && ymin <= p[i].y && p[i].y <= ymax) {
              cnt++;
            }
          }
          if (cnt < k) continue;
          ans = min(ans, (xmax - xmin) * (ymax - ymin));
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

void Constraints(int n,int m)
{

    if(!(1<=n&&n<=100&&1<=m&&m<=100))
    {
      printf("条件を満たす入力をしてください。\n");
      exit(0);
    }
}

int main(void){
  int n,m;
  scanf(" %d %d",&n,&m);
  Constraints(n,m);
  int a[n][m];
  int b[m];
  int c[n];
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      a[i][j]=0;
      b[j]=0;
    }
    c[i]=0;
  }

  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      scanf(" %d",&a[i][j]);
    }
  }
  for(int i=0;i<m;i++){
    scanf(" %d",&b[i]);
  }
  for(int i=0;i<n;i++)
  {
    for(int j=0;j<m;j++)
    {
      c[i] += a[i][j] * b[j];
    }
  }
  for(int i=0;i<n;i++){
    printf("%d\n",c[i]);
  }

}



Measured memory_bytes: 2104
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

int main(){
	int n;
	ll ans = 0;
	cin >> n;
	vector<int> a(n+1);
	vector<int> b(n);
	for (int i = 0; i < n+1; i++){
		cin >> a[i];
	}
	for (int i = 0; i < n; i++){
		cin >> b[i];
	}
	for (int i = 0; i < n; i++){
		ans += min(a[i], b[i]);
		b[i] -= min(a[i], b[i]);
		ans += min(a[i+1], b[i]);
		a[i+1] -= min(a[i+1], b[i]);
	}
	cout << ans << endl;
	return 0;
}



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

int gcd(int a,int b){
int r,tmp;
if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
return b;
}
int main(){

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

int yaku[N]={0};
yaku[0]=A[0];
int count=1;
int sagari[N]={-1};
sagari[0]=0;

for(int i=1;i<N;i++){
    yaku[i]=gcd(yaku[i-1],A[i]);
    if(yaku[i]!=yaku[i-1]){
        
        sagari[count]=i;
        count++;
    }
}
int ans =  yaku[N-1];


for(int i=0;i<count;i++){
    yaku[0]=A[0];
    for(int j=0;j<N;j++){
        if(j==sagari[i]){
            if(j!=0){
            yaku[j]=yaku[j-1];
            continue;
       
            }
            else{
               
                yaku[0]=A[1];
                continue;
            }
        }
         if(j==0){
                    continue;
                }
    yaku[j]=gcd(yaku[j-1],A[j]);

    }

if(yaku[N-1]>ans){
    ans=yaku[N-1];
}
}

cout<<ans;

    return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
int main(void)
{
	int i,n,k,x,y,z;
	z=0;
	scanf("%d",&n);
	scanf("%d",&k);
	scanf("%d",&x);
	scanf("%d",&y);
	for(i=1;i<=n;i++){
		if(i>k){
			z+=y;
		}
			else{
				z+=x;
			}
	}
	printf("%d\n",z);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdbool.h>
#define true 1
#define false 0
#define MAX 1000
#define VMAX 10000

int n,A[MAX],s;
int B[MAX],T[VMAX+1];

void sort(int C[])
{
	
	int tmp;
	int flag = 1;
	while(flag == 1)
	{
		flag = 0;
		for( int j = n-1; j >= 1; j--)
		{
			if(C[j] < C[j-1])
			{
				tmp = C[j];
				C[j] = C[j-1];
				C[j-1] = tmp;
				flag = 1;
			}
		}
	}
}

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

int solve()
{
	int ans = 0;
	
	bool V[MAX];
	for( int i = 0; i < n; i++)
	{
		B[i] = A[i];
		V[i] = false;
	}
	sort(B);
	for( int i = 0; i < n; i++) T[B[i]] = i;
	for( int i = 0; i < n; i++) 
	{
		if(V[i])continue;
		int cur = i;
		int S = 0;
		int m = VMAX;
		int count = 0;
		while(1)
		{
			V[cur] = true;
			count++;
			int v = A[cur];
			m = min(m,v);
			S += v;
			cur = T[v];
			if(V[cur])break;
		}
		ans += min(S+(count-2)*m,m+S+(count+1)*s);
	}
	return ans;
}

int main(void)
{
	scanf("%d",&n);
	s = VMAX;
	for( int i = 0; i < n; i++)
	{
		scanf("%d",&A[i]);
		s = min(s,A[i]);
	}
	int ans = solve();
	printf("%d\n",ans);
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
#define ll long long int
using namespace std;

int main()
{   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll n,count=0;
    string s;
    ll ans=0;
    cin>>n>>s;
    for(int i=0;i<n;i++)
    if(s[i]=='R')
    count++;

    if(count==n)
    {cout<<"0"<<endl;
    return 0;}	
    for(int i=0;i<n;i++)
    {
    	if(s[i]=='R'&&i>count-1)
         ans++;
    }
    cout<<ans<<endl;
    return 0;
   }	


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

using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void debugF(ostream &os) {os << endl;}
template <typename Head, typename... Tail>
void debugF(ostream &os, Head H, Tail... T) { os << " " << H; debugF(os, T...); }
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debugF(cout, __VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); os << (i>0 ? " ":"") << v[i++]); return os;}

ll inf = 2e18; 
ll mod = 1e9 + 7;

void resposta(vector<pll> &a, int k){
    ll ans = 1;
    int i;
    for(i=0;i<k;i++){
        ans *= a[i].second;
        ans %= mod;
        if(ans < 0) ans += mod;
    }
    cout << ans << "\n";
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k, i, j;
    cin >> n >> k;
    vector<pll> a(n);
    bool hasP = false;
    for(i=0;i<n;i++){
        ll x; cin >> x;
        a[i] = {abs(x), x};
        if(x > 0) hasP  = true;
    }
    if(n == k){
        resposta(a, k);
        return 0;
    }
    sort(all(a));
    ll ans = 1;
    if(k%2 == 1 && (!hasP)){
        resposta(a, k);
        return 0;
    }
    reverse(all(a));
    // for(i=0;i<n;i++){
    //     cout << a[i].first << " " << a[i].second << "\n";
    // }
    ll minP = inf, minN = inf;
    int imp, imn;
    int cntN = 0;
    for(i=0;i<k;i++){
        if(a[i].second < 0){
            cntN++;
            minN = a[i].second;
            imn = i;
        }else{
            minP = a[i].second;
            imp = i;
        }
    }
    ll nxtP = inf, nxtN = inf;
    for(i=k; i < n;i++){
        if(a[i].second < 0){
            if(nxtN == inf) nxtN = a[i].second;
        }else{
            if(nxtP == inf) nxtP = a[i].second;
        }
    }
    if(cntN%2 == 0){
        resposta(a, k);
        return 0;
    }
    if(minP == inf){
        a[imn] = {abs(nxtP), nxtP};
        resposta(a, k);
        return 0;
    }
    assert(minP != inf && minN != inf);
    ll op1, op2;
    if(nxtN == inf){
        op1 = -inf;
    }else{
        op1 = minN * nxtN;
    }
    if(nxtP == inf){
        op2 = -inf;
    }else{
        op2 = nxtP * minP;
    }
    if(op1 > op2){
        a[imp] = {abs(nxtN), nxtN};
    }else{
        a[imn] = {nxtP, nxtP};
    }
    resposta(a, k);
    return 0;
}

Measured memory_bytes: 6344
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long 
#define PI 3.141592653589793238

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pref_trie;
typedef tree<long int,null_type,less<long int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef cc_hash_table<long int,long int, hash<long int>, equal_to<long int>, direct_mask_range_hashing<long int>, 
hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>, true>> ht;
typedef gp_hash_table<long int,long int> HashTable;

int main(){
   IOS;
 /*    #ifndef ONLINE_JUDGE
         freopen("in.txt",  "r",  stdin);
         freopen("out.txt", "w", stdout);
     #endif */
   
   long int n,m;
   cin>>n>>m;

   for(long int i = 0; i <= n; i++){
      if(2 * i + 4 * (n - i) == m)
        return cout<<"Yes",0;
   }
   cout<<"No";
   return 0;
}

Measured memory_bytes: 3656
import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


fun solve() {
    val (N, M) = rd.readIntArray()
    val X = IntArray(M); val Y = IntArray(M)
    for (i in 0 until M) {
        val (x, y) = rd.readIntArray().map { it -1 }
        X[i] = x; Y[i] = y
    }

    val possible = BooleanArray(N) { false }
    val cnt = IntArray(N){1}
    possible[0] = true
    for (i in 0 until M) {
        if (possible[X[i]]) {
            possible[Y[i]] = true
        }

        cnt[X[i]]--
        cnt[Y[i]]++

        if (cnt[X[i]] <= 0) possible[X[i]] = false
    }

    val ans = possible.count { it }
    println(ans)
}


//val rd = debug.Reader("agc", "002", "b", "sample-1")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!! }
    catch (e: Exception) { throw e }
    finally { rd.close() }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
data class IntPair(val first: Int, val second: Int); data class LongPair(val first: Long, val second: Long)
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
    val readListIntCol: (Int) -> List<Int> = { N -> (0 until N).map { readInt() } }
    val readListLongCol: (Int) -> List<Long> = { N -> (0 until N).map { readLong() } }
    val close: () -> Unit = { br.close() }
    protected fun finalize() { close() }
}


Measured memory_bytes: 62616
from collections import deque,defaultdict

d = [(1,0),(-1,0),(0,1),(0,-1)]

def bfs(sly,slx,sry,srx):
    bfs_map = defaultdict(lambda : 1)
    bfs_map[(sly,slx,sry,srx)] = 0
    q = deque()
    q.append((sly,slx,sry,srx))
    while q:
        ly,lx,ry,rx = q.popleft()
        for dy,dx in d:
            ly_ = ly+dy
            lx_ = lx+dx
            ry_ = ry+dy
            rx_ = rx-dx
            if ly_ < 0 or h <= ly_ or lx_ < 0 or w <= lx_:
                ly_,lx_ = ly,lx
            elif l[ly_][lx_] == "#":
                ly_,lx_ = ly,lx
            if ry_ < 0 or h <= ry_ or rx_ < 0 or w <= rx_:
                ry_,rx_ = ry,rx
            elif r[ry_][rx_] == "#":
                ry_,rx_ = ry,rx
            if ly_ == gly and lx_ == glx and ry_ == gry and rx_ == grx:
                return "Yes"
            if bfs_map[(ly_,lx_,ry_,rx_)]:
                if l[ly_][lx_] != "%" and r[ry_][rx_] != "%":
                    q.append((ly_,lx_,ry_,rx_))
                    bfs_map[(ly_,lx_,ry_,rx_)] = 0

    return "No"

while 1:
    w,h = map(int, input().split())
    if w == h == 0:
        break
    s = [input().split() for i in range(h)]
    l = [s[i][0] for i in range(h)]
    r = [s[i][1] for i in range(h)]
    for y in range(h):
        for x in range(w):
            if l[y][x] == "L":
                sly,slx = y,x
            elif l[y][x] == "%":
                gly,glx = y,x
    for y in range(h):
        for x in range(w):
            if r[y][x] == "R":
                sry,srx = y,x
            elif r[y][x] == "%":
                gry,grx = y,x
    print(bfs(sly,slx,sry,srx))



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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N, K;
    cin >> N >> K;
    int ans = 0;
    rep(i, N) {
        int h;
        cin >> h;
        if (h >= K) ans ++;
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}


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

int n;
int a[1001];

int main(void){
    int ans=0;

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

    for(int i =0; i<n; i++){
        if( (a[i] % 2) ==0){
            if( ((a[i]% 3)==0) || ((a[i]% 5)==0) ){
                continue;
            }else{
                ans = 1;
                break;
            }
        }
    }

    if(ans){
        cout <<  "DENIED" << endl;
    }else{
        cout << "APPROVED" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
//    ifstream in("input.txt");
//    cin.rdbuf(in.rdbuf());

    ll a,b;
    cin >> a >> b;
    if(b%a == 0){
        cout << a+b << endl;
    }else{
        cout << b-a << endl;
    }
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define     __        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define     pi        acos(-1)
#define     ll        long long int
#define     fopen     freopen("input.txt","r",stdin)
#define     fwrite    freopen("output.txt","w",stdout)
#define     f0(n)     for(int i=0;i<n;i++)
#define     mem(a)    memset(a,0,sizeof(a))
#define     mems(a)   memset(a,-1,sizeof(a))
double a[111];
int main()
{
    __
    //fopen;
    //fwrite;
    int n,res=0;
    cin>>n;
    double sum=0.0,ans=1000.0,p;
    p=(double) n;
    f0(n) cin>>a[i],sum+=a[i];
    sum/=p;
    f0(n)
    {
        double dis=abs(a[i]-sum);
        if(dis<ans) {
            ans=dis;
            res=i;
        }
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

// 足りないトランプを探し、それを表示する
int main()
{
	int iTrumpSize;			// そろっているトランプの枚数
	int iSpadeTrump[13] = { 0 };	// スペードのトランプ
	int iHeartTrump[13] = { 0 };	// ハートのトランプ
	int iClubTrump[13] = { 0 };		// クラブのトランプ
	int iDiamondTrump[13] = { 0 };	// ダイヤのトランプ
	char chInputMark;		// 入力されたトランプの柄
	int iInputNumber;		// 入力されたトランプの数字
	int iCount;				// ループカウンタ

	// 入力：トランプの枚数
	scanf("%d", &iTrumpSize);

	// そろっているトランプを1枚ずつ確認する
	for (iCount = 0; iCount < iTrumpSize; iCount++)
	{
		// 入力：トランプの記号と数字
		scanf(" %c %d", &chInputMark, &iInputNumber);

		// 該当する配列の要素にチェック(=1)する
		switch (chInputMark)
		{
		case 'S':
			iSpadeTrump[iInputNumber - 1] = 1;
			break;
		case 'H':
			iHeartTrump[iInputNumber - 1] = 1;
			break;
		case 'C':
			iClubTrump[iInputNumber - 1] = 1;
			break;
		case 'D':
			iDiamondTrump[iInputNumber - 1] = 1;
			break;
		default:
			break;
		}
	}

	// そろっていないトランプの札を表示する
	for (iCount = 0; iCount < 13; iCount++)
	{
		if (iSpadeTrump[iCount] != 1)
		{
			printf("S %d\n", iCount + 1);
		}
	}
	for (iCount = 0; iCount < 13; iCount++)
	{
		if (iHeartTrump[iCount] != 1)
		{
			printf("H %d\n", iCount + 1);
		}
	}
	for (iCount = 0; iCount < 13; iCount++)
	{
		if (iClubTrump[iCount] != 1)
		{
			printf("C %d\n", iCount + 1);
		}
	}
	for (iCount = 0; iCount < 13; iCount++)
	{
		if (iDiamondTrump[iCount] != 1)
		{
			printf("D %d\n", iCount + 1);
		}
	}
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;

//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int x, y; cin >>x>>y;
  bool ok = true;
  int foo = 4*x - y;
  if (foo < 0 ||  foo&1 || foo>x*2) ok = false;
  ok();
  return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	string s;

	cin>>s;

	int o=s.size();
	while(o>4){
		if(s.substr(o-5,5)=="dream"){
			o=o-5;
		}else if(o>=7&&s.substr(o-7,7)=="dreamer"){
			o=o-7;
		}else if(s.substr(o-5,5)=="erase"){
			o=o-5;
		}else if(o>=6&&s.substr(o-6,6)=="eraser"){
			o=o-6;
		}else{
			cout<<"NO"<<endl;
			return 0;
		}
	}
	if(o==0){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
}


Measured memory_bytes: 512
#!/usr/bin python3
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10001000)

class UnionFindWeighted:
    def __init__(self, n):                      #初期化
        self.n = n                              # 要素数
        self.parents = [i for i in range(n)]    # 親
        self.ranks = [0] * n                    # 木の深さ
        self.sizes = [1] * n                    # グループの要素数
        self.weights = [0] * n                  # 親との重み

    def find(self, x):          #親を出力
        if self.parents[x] == x:
            return x
        else:
            p = self.find(self.parents[x])
            self.weights[x] += self.weights[self.parents[x]]
            self.parents[x] = p
            return p

    def unite(self, x, y, w):          # ユニオン
        # a[x]->a[y]  の差はw  # a[y]=a[x]+w
        rx = self.find(x)
        ry = self.find(y)
        wx = self.weight(x)
        wy = self.weight(y)
        if rx == ry: return
        if self.ranks[rx] > self.ranks[ry]:
            rx , ry = ry, rx    #ryを親にする
            wx , wy = wy, wx
            w *= -1
            print("a")
        self.parents[rx] = ry
        self.sizes[ry] += self.sizes[rx]
        self.weights[rx] = wy - wx - w
        if self.ranks[rx]==self.ranks[ry]:
            self.ranks[rx] += 1

    def same(self, x, y):       #xとyが同じグループかどうか
        return self.find(x) == self.find(y)

    def members(self, x):       #xと同じグループの要素
        root = self.find(x)
        return {i for i in range(self.n) if self.find(i) == root}

    def size(self, x):          #グループの要素数
        root = self.find(x)
        return self.sizes[root]

    def roots(self):            #親の要素一覧
        return {i for i, x in enumerate(self.parents) if i == x}

    def group_count(self):      #グループの個数
        return len(self.roots())

    def all_group_members(self):      #グループのメンバー一覧
        return {r: self.members(r) for r in self.roots()}

    def weight(self, x):       #重みの差
        _ = self.find(x)
        return self.weights[x]

    def diff(self, x, y):       #重みの差
        return self.weight(y) - self.weight(x)

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

################

n, m = map(int, input().split())
uf = UnionFindWeighted(n)
for _ in range(m):
    a, b, w = map(int,input().split())
    a -= 1
    b -= 1
    if uf.same(a, b):
        if uf.diff(a, b)!=w:
            print('No')
            exit()
    else:
        uf.unite(a, b, w)
print('Yes')


Measured memory_bytes: 16764
sx, sy, tx, ty = map(int, input().split())

dx, dy = tx-sx, ty-sy
u = 'U'*dy+'R'*dx+'D'*dy+'L'*(dx+1)+'U'*(dy+1)+'R'*(dx+1)+'DR'+'D'*(dy+1)+'L'*(dx+1)+'U'

print(u)


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

typedef long long ll;
const ll MOD = 1000000007;

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<double> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    vector<double> a(n / 2 + 1, 1.0), b(n / 2 + 1);
    a[0] = p[n - 1];
    for (int i = n - 2; i >= 0; i--) {
        b[0] = p[i] * a[0];
        for (int j = 1; j <= n / 2; j++) {
            b[j] = p[i] * a[j] + (1 - p[i]) * a[j - 1];
        }
        a.swap(b);
    }
    cout.precision(12);
    cout << a[n / 2];

    return 0;
}

Measured memory_bytes: 256
//???????????????
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N;
	cin>>N;
	vector<int> A(N);
	for(int i=0; i<N; ++i){
		cin>>A[i];
	}
	
	int kaisuu=0;
	for(int i=0;i<N;++i){
		int minj = i;//????°??????????????????¨?????????index
		for(int j=i; j<N; ++j){
			if(A[j]<A[minj]){
				minj=j;
			}
		}
		if(minj != i){
			swap(A[i],A[minj]);
			kaisuu++;
		}
	}

	for(int i=0; i<N-1;++i){
		cout<<A[i]<<" ";
	}
	cout<<A[N-1]<<endl;
	cout<<kaisuu<<endl;
}

Measured memory_bytes: 3100
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")


using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 200000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000010;
const ll LOG = 25;

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll x, y;
	cin >> x >> y;
	
	int cnt = 1;
	while (x * 2 <= y){
		x *= 2;
		cnt++;
	}
	cout << cnt;











	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ld long double
#define ll long long
#define ull unsigned ll
#define pll pair<ll, ll>
#define itr(a) begin(a), end(a)
#define pb push_back
#define x first
#define y second
#define endl '\n'
#define FAST cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define FILES(namein, nameout) freopen(namein, "r", stdin); freopen(nameout, "w", stdout);
#define M 1000000007
#define N 200000
#define INF 101111111111111
using namespace std;
main(){
	FAST;
	ll a, b;
	cin >> a >> b;
	cout << max<ll>(0, a-b*2) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;
using pll=pair<ll,ll>;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

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

int main() {
	int N;
	cin >> N;
	string s,t;
	cin >> s >> t;
	int cnt=0;
	rep(i,N) {
		rep(j,i+1) {
			if(s[N-1-(i-j)] != t[j]) break;
			if(j == i) chmax(cnt, i+1);
		}
	}
	cout << N*2 - cnt << endl;


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sqr(x) ((x) * (x))
using namespace std;
int a[3], p, q, r;
int main() {
    ios::sync_with_stdio(false);
    while(cin >> a[0] >> a[1] >> a[2]) {
        sort(a, a + 3);
        if(a[0] + a[1] <= a[2]) break;
        if(sqr(a[0]) + sqr(a[1]) == sqr(a[2])) p++;
        else if(sqr(a[0]) + sqr(a[1]) > sqr(a[2])) q++;
        else r++;
    }
    cout << p + q + r << ' ' << p << ' ' << q << ' ' << r << endl;
    return 0;
}

Measured memory_bytes: 3176
package main

import "fmt"

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func main() {
	var n int
	fmt.Scan(&n)
	acc := make([]int, n+1)
	var a int
	for i := 1; i <= n; i++ {
		fmt.Scan(&a)
		acc[i] = acc[i-1] + a
	}
	minAbs := 2000000000
	for i := 1; i < n; i++ {
		a := abs(acc[i] - (acc[n] - acc[i]))
		if a < minAbs {
			minAbs = a
		}
	}
	fmt.Println(minAbs)
}

Measured memory_bytes: 5376
#include <iostream>
using namespace std;
int main(void){
	int a,b=0;
	while(cin>>a){
		for (int A=0;A<10;A++){
			for (int B=0;B<10;B++){
				for (int C=0;C<10;C++){
					for (int D=0;D<10;D++){
						if (A+B+C+D==a) b++;
					}
				}
			}
		}
		cout<<b<<endl;
		b=0;
	}
	return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <string>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = (a); i < (n); i++)
#define MP make_pair
#define all(s) (s).begin(), (s).end()

using namespace std;

typedef long long ll;
typedef vector<int> vi;

int getdist(int a, int b, int w){
	int ax = a%w, bx = b%w;
	int ay = a/w, by = b/w;
	return abs(ax-bx)+abs(ay-by);
}

int main(){
	int n;
	int a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	a--;b--;c--;d--;

	int ans = 1000000;
	for(int w = 1; w <= n; w++){
		ans = min(ans, getdist(a,b,w)+getdist(c,d,w));
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <utility>
#include <cstring>
using namespace std;

int nxt_x[110][110], nxt_y[110][110], checked[110][110];

int main() {
  int N;
  while(cin >> N, N) {
    memset(nxt_x, 0, sizeof(nxt_x));
    memset(nxt_y, 0, sizeof(nxt_y));
    memset(checked, 0, sizeof(checked));
    
    for(int i=0; i<N; i++) {
      for(int j=0; j<N; j++) {
        int col, row; cin >> col >> row;
        nxt_x[i][j] = row;
        nxt_y[i][j] = col;
      }
    }

    int ans = 0;
    for(int i=0; i<N; i++) {
      for(int j=0; j<N; j++) {
        if(checked[i][j]) continue;
        int id = ans + 1, res = -1;
        int x = i, y = j;

        while(1) {
          int nx = nxt_x[x][y];
          int ny = nxt_y[x][y];

          // printf("(x, y) = %d, (nx, ny) = %d, id = %d\n", x, y, nx, ny, checked[nx][ny]);
          if(checked[nx][ny] == 0) {
            checked[nx][ny] = id;
          }
          else {
            if(checked[nx][ny] == id) {
              ans++;
            }
            res = checked[nx][ny];
            break;
          }

          x = nx, y = ny;
        }

        x = i, y = j;
        while(1) {
          if(checked[x][y] == res) break;
          checked[x][y] = res;
          int nx = nxt_x[x][y], ny = nxt_y[x][y];
          x = nx, y = ny;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3148
X[2001];i,p,g;main(N,M){for(;scanf("%d%d",&N,&M)*N;printf("%d\n",g)){for(g=i=0;i++<N+M;p=1)scanf("%d",X+i);for(i=0;i++<M;g=g|p<N?g:i)p+=X[N+i],p+=p<N?X[p]:0;}}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
// Union Find

template<typename T>
struct UnionFind
{
	vector<T> par;
	vector<T> rank;
	vector<T> sizes;
	UnionFind(T n):par(n),rank(n,0),sizes(n,1){
	   for(T i=0;i<n;i++){
	     par[i]=i;
	   }
	}
	T root(T x){
	  return par[x]==x?x:par[x]=root(par[x]);
	}

	bool unite(T x,T y){
	  if(x==y) return false;
	  x=root(x); y=root(y);
	  if(x==y) return false;
	  if(rank[x]<rank[y]) swap(x,y);
	  if(rank[x]==rank[y]) rank[x]++;
	  par[y]=x;
	  sizes[x]=sizes[x]+sizes[y];
	  return true;
	}
	bool same(T x,T y){
	  return root(x)==root(y);
	}
	T size(T x){
	  return sizes[root(x)];
	}
};
int main(){
  ll n,m;
  cin>>n>>m;
  UnionFind<ll> uf(n);
  rep(i,m){
    ll x,y,z;
    cin>>x>>y>>z;
    x--;
    y--;
    uf.unite(x,y);
  }
  set<ll> s;
  rep(i,n){
    s.insert(uf.root(i));
  }
  COUT(sz(s));
}

Measured memory_bytes: 10364
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;

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

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

int main()
{
  int n;
  cin >> n;
  int p[200005];
  int q[200005];

  rep(i, n)
  {
    cin >> p[i];
  }

  rep(i, n)
  {
    q[--p[i]] = i;
  }

  // rep(i, n)
  // {
  //   cout << q[i] << " ";
  // }
  // cout << endl;

  int left, right;
  left = right = 0;
  int tmp = q[0];
  int m = 0;

  while (right <= n - 1)
  {
    while (q[right + 1] > tmp && right <= n - 2)
    {
      right++;
      tmp = q[right];
    }
    // cout << left << right << endl;
    chmax(m, right - left);
    left = ++right;
    tmp = q[left];
  }

  cout << n - m - 1 << endl;
  return 0;
}

Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int s = sc.nextInt();
		List lst = new ArrayList<Integer>();

		while (!lst.contains(s)) {
			lst.add(s);
			if (s % 2 == 0) {
				s /= 2;
			} else {
				s = 3 * s + 1;
			}
		}

		System.out.println(lst.size() + 1);
	}
}


Measured memory_bytes: 23636