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

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    
    int[] a = new int[N];
    for(int i = 0; i < N; i++){
      a[i] = Integer.parseInt(sc.nextLine());
    }
    int count = 0;
    int n = 0;
    boolean c = false;
    for(int i = 0; i < N;i++){
      if(n+1 == 2){
        c = true;
        break;
      }
      n = a[n] - 1;
      count++;
    }
    
    if(c){
      System.out.println(count);
    }else{
      System.out.println(-1);
    }
  }
}

Measured memory_bytes: 101800
#include <stdio.h>
#include <stdint.h>

int main(void){
  unsigned long long N,A,B;
  unsigned long long p;
 scanf("%lld%lld%lld",&N,&A,&B);
 p=(N-2)*(B-A)+1;
 if(A>B) p=0;
 if(A!=B&&N==1) p=0;
 printf("%lld\n",p);

 return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1000000007;
int p(int A,int B){
  if(B==0)return 1;
  if(B%2)return p(A,B-1)*A%mod;
  int C=p(A,B/2);
  return C*C%mod;
}
signed main(){
  int N,K;
  cin>>N>>K;
  vector<int> A(N),B(100010);
  for(int &i:A)cin>>i;
  sort(A.begin(),A.end());
  B[0]=1;
  for(int i=1;i<=100000;i++)B[i]=B[i-1]*i%mod;
  int mx=0,mn=0;
  for(int i=0;i<N;i++){
    if(i>=K-1)mx=(mx+B[i]*p(B[i-K+1]*B[K-1]%mod,mod-2)%mod*A[i]%mod)%mod;
    if(N-i>=K)mn=(mn+B[N-1-i]*p(B[N-i-K]*B[K-1]%mod,mod-2)%mod*A[i]%mod)%mod;
  }
  cout<<(mx-mn+mod)%mod<<endl;
}

Measured memory_bytes: 4824
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
const ll LINF = 0x1fffffffffffffff;
const ll MOD = 1000000007;
#define name3(_1,_2,_3,name,...) name
#define rep1(n) for(ll i=0;i<(n);++i)
#define rep2(i,n) for(ll i=0;i<(n);++i)
#define rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) name3(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__)
#define rrep(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define each(i,a) for(auto &i : a)
#define sum(a) accumulate(all(a), 0LL)
#define all(i) begin(i), end(i)
template<class T, class U> inline bool chmin(T &a, const U &b){ if(a > b) { a = b; return 1; } else return 0; }
template<class T, class U> inline bool chmax(T &a, const U &b){ if(a < b) { a = b; return 1; } else return 0; }


ll n;
struct T{
    ll cnt[800] = {};
    T operator*(const T& a) const {
        T ans;
        rep(n)rep(j,n)ans.cnt[(i+j)%n]+=cnt[i]*a.cnt[j]%MOD;
        each(i,ans.cnt)i%=MOD;
        return ans;
    }
    T pow(ll x) const {
        T ans, a = *this;
        ans.cnt[0]  = 1;
        while(x){
            if(x & 1) ans = ans * a;
            a = a * a;
            x >>= 1;
        }
        return ans;
    }
};
int main(){
    ll m, k;
    cin >> n >> m >> k;
    T ans;
    ans.cnt[0] = 1;
    rep(m){
        ll p;
        cin >> p;
        ans.cnt[p % n]++;
    }
    ans = ans.pow(k);
    rep(n) cout << ans.cnt[i] << endl;
}



Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () {
    int N, M;
    cin >> N >> M;
    vector<int> S(N, -1);
    for (int i = 0; i < M; i++) {
        int s, c;
        cin >> s >> c;
        s--;
        if (S[s] == -1) {
            S[s] = c;
        }
        else if (S[s] != c) {
            puts("-1");
            return 0;
        }
    }
    if (N != 1 && S[0] == 0) {
        puts("-1");
        return 0;
    }
    if (N == 1 && S[0] == -1)  {
        puts("0");
        return 0;
    }
    if (S[0] == -1) {
        S[0] = 1;
    }
    for (int i = 1; i < N; i++) {
        if (S[i] == -1) S[i] = 0;
    }
    for (int i = 0; i < N; i++) {
        cout << S[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
import sys
n=[1,9,36,84,126]
for x in sys.stdin:
 a,b,c,d,e,f,g,h,i,j=map(int,x[:-1])
 print(sum(s*t for s,t in zip(n,[a+j,b+i,c+h,d+g,e+f]))%10)


Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
int a[4],f[100001][4];
int main()
{
	int i,j,n,m;
	scanf("%d",&n);
	f[0][1]=0,f[0][2]=0,f[0][3]=0;
	for(i=1;i<=n;i++)
	{
		scanf("%d %d %d",&a[1],&a[2],&a[3]);
		f[i][1]=max(f[i-1][2],f[i-1][3])+a[1];
		f[i][2]=max(f[i-1][1],f[i-1][3])+a[2];
		f[i][3]=max(f[i-1][1],f[i-1][2])+a[3];
	}
	printf("%d",max(max(f[n][1],f[n][2]),f[n][3]));
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
typedef long long ll;
const ll INF = 1ll<<60;
using namespace std;

int h,w;
ll mp[10][10]; 

int main(){
    cin>>h>>w;
    ll ans=0;

    for(int i=0; i<10; i++){
        for(int j=0; j<10; j++){
            cin>>mp[i][j];
        }
    }

    for(int  i=0; i<10; i++){
        for(int j=0; j<10; j++){
            for(int k=0; k<10; k++){
                mp[j][k] = min(mp[j][k],mp[j][i]+mp[i][k]);
            }
        }
    }

    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            int v; cin>>v;
            if(abs(v) != 1)ans += mp[v][1];
        }
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int number[16];
int graph[100][100];
int creak(int idx, int k, int D, vector<int>& cand){
  if(D - k > cand.size() - idx) return 0;
  if(k == D){
    int res = 0;
    for(int i = 0; i < D; i++){
      int m = INF;
      for(int j = 0; j < D; j++) if(i != j) {
        m = min(m, graph[number[i]][number[j]]);
      }
      if(m == 0) return 0;
      res += m;
    }
    return res;
  }else{
    int ret = creak(idx + 1, k, D, cand);
    number[k] = cand[idx];
    ret = max(ret, creak(idx + 1, k + 1, D, cand));
    return ret;
  }
}
int main(){
  int N, M;
  while (cin>>N>>M && N) {
    memset(graph, 0, sizeof(graph));
    int dim[100] = {};
    REP(i, M){
      int u, v, f;
      cin>>u>>v>>f;
      u--; v--;
      graph[u][v] = graph[v][u] = f;
      dim[u]++;
      dim[v]++;
    }
    vector<int> cand[16];
    REP(i, N){
      for(int d = 2; d <= dim[i] + 1 && d <= 15; d++){
        cand[d].push_back(i);
      }
    }
    int ans = 0;
    for(int d = 2; d <= 15; d++){
      if(cand[d].size() < d) break;
      ans = max(ans, creak(0, 0, d, cand[d]));
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1268
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)
#define REPIT(i,x) for(auto i{(x).begin()}; i != (x).end(); i++) 

#define PB push_back
#define MP make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef double dbl;
typedef vector<bool> Vb;
typedef vector<char> Vc;
typedef vector<double> Vd;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<string> Vs;
typedef vector<vector<int>> VVi;
typedef vector<vector<ll>> VVl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }
inline void YES() { cout << "YES" << endl; } inline void Yes() { cout << "Yes" << endl; }
inline void NO() { cout << "NO" << endl; } inline void No() { cout << "No" << endl; }

const int inf = 1 << 30;
const ll linf = 1LL << 60;
const int MOD = 1000000007;

typedef tuple<int, int, ll> tup;

int n, m;
ll p;
vector<ll> d;
Vb loop, accessible;
vector<tup> edges, effectiveEdges;


void init()
{
	cin >> n >> m >> p;

	edges.reserve(m);
	d.resize(n, -linf); d[0] = 0;
	loop.resize(n, false);
	accessible.resize(n, false); accessible[0] = true;

	REP(i, m)
	{
		int a, b; ll c; cin >> a >> b >> c;
		--a; --b;
		c -= p;
		edges.emplace_back(tup(a, b, c));
	}
}

void pseudo_BellmanFord()
{
	d[0] = 0;

	REP(_i, n - 1)
		for (tup edge : edges)
		{
			int a = get<0>(edge);
			int b = get<1>(edge);
			ll c = get<2>(edge);
			chmax(d[b], d[a] + c);

			if (!a || accessible[a])
				accessible[b] = true;
		}

	REP(_i, n)
		for (tup edge : edges)
		{
			int a = get<0>(edge);
			int b = get<1>(edge);
			ll c = get<2>(edge);

			if (chmax(d[b], d[a] + c))
			{
				if (accessible[b])
					loop[b] = true;
			}

			if (accessible[a] && loop[a])
				loop[b] = true;
		}

}


int main()
{
	init();

	pseudo_BellmanFord();

	if (!loop[n - 1])
	{
		if (d[n - 1] < 0)
			cout << 0 << endl;
		else
			cout << d[n - 1] << endl;
	}
	else
		cout << -1 << endl;
}


Measured memory_bytes: 384
N, M = map(int, input().split())
sc = sorted(set([tuple(map(int, input().split()))
                 for i in range(M)]))
ans = 0
position = 0
for s_c_i in sc:
    if (s_c_i == (1, 0) and N > 1) or s_c_i[0] == position:
        ans = -1
        break
    position = s_c_i[0]
    ans += (10**(N-position))*s_c_i[1]
if ans != -1 and N > 1 and ans < 10**(N-1):
    ans += 10**(N-1)
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < (int)n;i++)
#define repb(i, n) for(int i = (int)n;i >= 0;i--)
#define reps(i, m, n) for(int i = (int)m;i < (int)n;i++)
#define repsb(i, m, n) for(int i = (int)m;i >= (int)n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF 999999999999999999
using namespace std;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
using namespace std;
int main(int argc, char const *argv[]) {
  int n,temp,mx=0,mi=1000000000;
  vector<int> v;
  cin>>n;
  rep(i,n){
    cin>>temp;
    v.pb(temp);
    mi=min(temp,mi);
    mx=max(mx,temp);

  }
  cout<<mx-mi<<endl;

 return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){

int a,b,c,z;

scanf("%d %d %d",&a,&b,&c);

if(a>b){

z=b; b=a; a=z;

}
if(a>c){

z=c; c=a; a=z;

}

if(b>c){

z=c; c=b; b=z;

}

printf("%d %d %d\n",a,b,c);

return 0;

}

Measured memory_bytes: 596
import itertools

n=int(input())
arr=[list(map(int,input().split())) for _ in range(n)]
ans=0
for places in itertools.permutations([i for i in range(n)]):
  for i in range(n-1):
    x1,y1=arr[places[i]]
    x2,y2=arr[places[i+1]]
    ans+=((x2-x1)**2+(y2-y1)**2)**0.5
for i in range(1,n+1):
  ans=ans/i
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include<numeric>
#include<cstdlib>
#define ll long long int
#define all(x) x.begin(),x.end()
 
 #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
 
#define v vector<long long int> 
#define vv vector< int> 
#define gcd(m,n) __gcd(m,n)
#define vp vector<pair<long long int ,long long int>>
#define pb push_back
#define mp make_pair
#define pp pop_back
#define iter vector<int>::iterator
#define pa pair<long long int ,long long int> 
#define f(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,n) for (ll i=a ; i<n ;i+=1)
#define fe(d,e) for(auto d:e)
#define mod 1000000007
#define F first
#define S second
#define sett set<long long int>
#define um unordered_map<ll,ll>
# define N 100005LL
using namespace std;

vector<vector<ll>> graph(200005);
ll visited[200005]; 

void dfs(ll node){
    visited[node]=1;
    cout<<node<<" ";
    for (ll u:graph[node]){
        if(!visited[u])dfs(u);
    }
}



int main(){
    ll n;
    cin>>n;
    string s;cin>>s;
    v a,b;
    f(i,n){
        if(s[i]=='R')a.pb(i);
        else{
            b.pb(i);
        }
    }
    // if (a.size()==0 || b.size()==0)cout<<0<<"\n";
    sort(a.begin(),a.end());
    reverse(all(a));
    sort(all(b));
    ll i=0;
    ll j=0;
    ll ans=0;
    // f(i,a.size())cout<<a[i]<<" ";
    // cout<<endl;
    //     f(i,b.size())cout<<b[i]<<" ";
    // cout<<endl;
   
    f(k,min(a.size(),b.size())){
            if (a[i]>b[i]){ans+=1;i+=1;j+=1;}  
            else break;    
       }
    cout<<ans<<"\n";


}

    


Measured memory_bytes: 10520
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
void _main() {
	int T[3];
	cin >> T[0]>> T[1] >> T[2];
	int ans = T[0]+T[1]+T[2];
	rep(i, 0, 3) {
		rep(j, 0, 3) {
			if (i != j) ans = min(ans, T[i] + T[j]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int taro=0,hanako=0;
        while(n-->0){
            String str[] = br.readLine().split(" ");
            if(str[0].compareToIgnoreCase(str[1])==0){
                taro++;
                hanako++;
            }else if(str[0].compareToIgnoreCase(str[1])>0){
                taro += 3;
            }else{
                hanako += 3;
            }
        }
        System.out.println(taro+" "+hanako);
    }
}

Measured memory_bytes: 25404
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

class UnionFindPathCompression():
    def __init__(self, n):
        self.parents = list(range(n))
        self.rank = [1]*n
        self.group_size = [1]*n

    def find(self, x):
        if self.parents[x] == x:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        px = self.find(x)
        py = self.find(y)

        if px == py:
            return
        else:
            if self.rank[px] < self.rank[py]:
                self.parents[px] = py
                self.group_size[py] += self.group_size[px]
            else:
                self.parents[py] = px
                self.group_size[px] += self.group_size[py]
                if self.rank[px] == self.rank[py]:
                    self.rank[px] += 1
                
n,m = map(int,input().split())
ufpc = UnionFindPathCompression(n)
query = []
for i in range(m):
    a, b = (int(x) for x in input().split())
    a,b = a-1, b-1
    query.append([a,b])

ans = [0]*m
ans[m-1] = n*(n-1)//2

for i in range(m-2, -1, -1):
    a,b = query[i+1][0], query[i+1][1]
    if ufpc.find(a) == ufpc.find(b):
        ans[i] = ans[i+1]
    else:
        ans[i] = ans[i+1] - ufpc.group_size[ufpc.parents[a]] * ufpc.group_size[ufpc.parents[b]]

    ufpc.union(a,b)
for aa in ans:
    print(aa)

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




int main()
{
	char S[20],T[20];
	
	scanf("%s",S);
	scanf("%s",T);
	
	int i,YorN=0;
	
	
	for(i=0;i<strlen(S);i++){
		if(S[i]!=T[i]){
			YorN=1;
			break;
		}
	}
	
	if(YorN==0){
		printf("Yes");
	}
	else{
		printf("No");
	}
	
	return 0;
}


Measured memory_bytes: 1732
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>

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; }

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;


int main()
{
    int n; cin >> n;
    ll count[5] = {0};//[0]:M, [1]:A, [2]:R, [3]:C, [4]:H
    string march = "MARCH";

    for(int i = 0; i < n; i++){
        string s; cin >> s;
        for(int j = 0; j < 5; j++){
            if(s[0] == march[j]){
                count[j]++;
            }
        }
    }

    ll ans = 0;
    for (int i = 0; i < 5; i++){
        for(int j = i + 1; j < 5; j++){
            for(int k = j + 1; k < 5; k++){
                ans += count[i] * count[j] * count[k];
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main ( )  {
	short x ;
	std :: cin >> x ;

	std :: string s = std :: to_string ( x ) ;

	for ( int i = 0 ; i < 2 ; ++ i )
		if ( s [i] == s [i + 1] && s [i] == s [i + 2] )  {
			return ! puts ( "Yes" ) ;
		}
	return ! puts ( "No" ) ;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#include <deque>
#include <tuple>
#include <map> 
#include <set>
#include <stack>
#include <functional>
#define ll long long
using namespace std;

int main() {

	int N;
	cin >> N;
	N = N % 10;

	if (N == 2 || N == 4 || N == 5 || N == 7 || N == 9) {
		cout << "hon" << endl;
	}
	else if (N == 0 || N == 1 || N == 6 || N == 8) {
		cout << "pon" << endl;
	}
	else {
		cout << "bon" << endl;
	}
}

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

#define int long long

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

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

const int INF=1001001001001001001ll;

int N,M;
vpint G[111111];

int uku[222222];

signed main(){
    cin>>N>>M;
    rep(i,M){
        int a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        G[a].pb({b,c});
        G[b].pb({a,c});
    }

    fill_n(uku,2*N,INF);
    uku[0]=0;
    queue<int>que;que.push(0);
    while(que.size()){
        int x=que.front();que.pop();
        int v=x/2;
        int p=x&1;
        for(auto &e:G[v]){
            if(uku[e.fi*2+1-p]!=INF){
                if(uku[e.fi*2+1-p]!=e.se-uku[x]){
                    cout<<0<<endl;
                    return 0;
                }
                continue;
            }
            uku[e.fi*2+1-p]=e.se-uku[x];
            que.push(e.fi*2+1-p);
        }
    }


    int L=1,R=INF;
    rep(i,N){
        if(uku[i*2]!=INF&&uku[i*2+1]!=INF){
            int tmp=uku[i*2+1]-uku[i*2];
            if(tmp%2){
                cout<<0<<endl;
                return 0;
            }
            tmp/=2;
            chmax(L,tmp);
            chmin(R,tmp);
        }
        if(uku[i*2]!=INF){
            chmax(L,-uku[i*2]+1);
        }
        if(uku[i*2+1]!=INF){
            chmin(R,uku[i*2+1]-1);
        }
    }
    cout<<max(0ll,R-L+1)<<endl;
    return 0;
}


Measured memory_bytes: 10112
import java.io.*;
import java.util.*;
import java.util.stream.*;

class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int[] a = new int[n];
		int[] ans = new int[n];
		int num = 1;
		for(int i = 0;i < n-1;i++){
			num = saori.saori_hayami();
			ans[num-1]++;
		}
		for(int i = 0;i < n;i++){
			System.out.println(ans[i]);
		}
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 56828
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tommy6073
 */

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

class BDigitSums {
public:
    void solve(std::istream& in, std::ostream& out) {
        int n;
        in >> n;
        string n_string = to_string(n);
        int s_n = 0;
        for (auto c : n_string) {
            s_n += c - '0';
        }

        out << (n % s_n == 0 ? "Yes" : "No");
    }
};


int main() {
	BDigitSums solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

using namespace std;

int main()
{
	string s;
	cin>>s;
	int ans=0;
	for(int i=0;i<(int)s.size();i++)
	{
		int cnt=0;
		for(;i+cnt<(int)s.size();cnt++)
			if(s[i+cnt]!='A'&&s[i+cnt]!='C'&&s[i+cnt]!='G'&&s[i+cnt]!='T')
				break;
				ans=max(ans,cnt);
	}
	cout<< ans<< endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>
#include<iomanip>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using ppi = pair<pii, int>;

int f_dir[2][4] = {{-1, 0, 1, 0}, {0, 1, 0, -1}}; //↑→↓←
int e_dir[2][8] = {{-1, -1, -1, 0, 0, 1, 1, 1}, {-1, 0, 1, -1, 1, -1, 0, 1}};
bool is_in_field(int y, int x, int h, int w){
  return (y >= 0 && y < h && x >= 0 && x < w);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  double r; cin >> r;
  cout << fixed << setprecision(10) << r * 6.28318530717958623200 << endl;

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 3800
//inlclude before define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
#include<assert.h>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>
using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> P1;
typedef long long int ll;

//define
#define INF 1e9
#define NUM 1000000007
#define all(x) begin(x), end(x)
#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)
#define REP(i,a,b) for(int i=int(a);i<int(b);i++)
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))


int main() {
	int n, y;
	cin >> n >> y;
	
	REP(i, 0, n+1) {
		REP(j, 0, n - i+1) {
			REP(k, 0, n - i - j+1) {
				if (i * 10000 + j * 5000 + k * 1000 == y) {
					if (i + j + k == n) {
						cout << i << " " << j << " " << k << endl;
						return 0;
					}
				}
			}
		}
	}
	cout << -1 << " " << -1 << " " << -1 << endl;
}





Measured memory_bytes: 256
/*16D8103005J 相良和希 ayachi0117 C++*/
#include<iostream>
#include<cmath>
bool Pnumber(int x)
{
	for(int i=2;i<=std::sqrt(x);i++){
		if(i/10 != 0){
			if(i%10==1 || i%10==3 || i%10==7 || i%10==9){
				if(x%i == 0){
					return false;
				}
			}
		}else{
			if(x%i == 0){
				return false;
			}
		}
	}
	return true;
}

int main()
{
	int n;
	std::cin >> n;
	int x[n];
	int cou=0;
	for(int i=0;i<=n-1;i++){
		std::cin >> x[i];
	}
	for(int i=0;i<=n-1;i++){
		if(Pnumber(x[i])){
			cou++;
		}
	}
	std::cout << cou << "\n" ;
	return 0;
}

/*
11
7
8
9
10
11
12
13
14
15
16
17
4

*/



Measured memory_bytes: 3068
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String[] s = new String[n];
    for (int i = 0; i < n; i++) {
      s[i] = sc.next();
    }
    int m = sc.nextInt();
    String[] t = new String[m];
    for (int i = 0; i < m; i++) {
      t[i] = sc.next();
    }

    int max = 0;
    for (int i = 0; i < n; i++) {
      int countS = 0;
      int countT = 0;
      for (int j = i; j < n; j++) {
        if (s[i].equals(s[j])) {
          countS++;
        }
      }
      for (int j = 0; j < m; j++) {
        if (s[i].equals(t[j])) {
          countT++;
        }
      }
      if (countS - countT > max) {
        max = countS - countT;
      }
    }
    System.out.println(max);
  }

}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define int long long
using namespace std;
vector<vector<int>> edges;
vector<int> dist, visited, offset;
int ans;
int dfs(int i)
{
    //cout << i + 1 << "\n";
    if (visited[i] == 1)
        return dist[i];
    visited[i] = 1;
    if ((int)edges[i].size() == 0)
        return 0;
    int temp = 0;
    for (int j : edges[i])
    {
        temp = max(temp, dfs(j));
    }
    dist[i] = temp+1;
    ans = max(ans, dist[i]);
    return dist[i];
}
int32_t main()
{
    //freopen("input.txt", "r", stdin);
    int n, m;
    cin >> n >> m;
    edges = vector<vector<int>>(n);
    dist = vector<int>(n);
    visited = vector<int>(n);
    offset = vector<int>(n);
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        edges[a].push_back(b);
        //edges[b].push_back(a);
    }
    for (int i = 0; i < n; i++)
        if (visited[i] == 0)
            dfs(i);
    cout << ans;
    return 0;
}
// 0 1 4
// 1 2 5


Measured memory_bytes: 12808
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <numeric>



int main()
{
	int a, b;

	std::cin >> a >> b;

	std::string s;

	std::cin >> s;

	if (std::count(s.begin(), s.end(), '-') != 1) {
		std::cout << "No" << std::endl;
		return 0;
	}

	if (std::find(s.begin(), s.end(), '-') - s.begin() != a) {
		std::cout << "No" << std::endl;
		return 0;
	}


	std::cout << "Yes" << std::endl;
	return 0;
}


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

const double INF = 1e9;

int main() {
  int n; cin >> n;
  vector<int> a(n); for (int i = 0; i < n; ++i) cin >> a[i];
  sort(begin(a), end(a));
  cout << a[n - 1] << ' ';
  double c = a[n - 1] / 2;
  int pos = 0;
  double m = INF;
  for (int i = 0; i < n; ++i) {
    if (abs((a[n - 1] - a[i]) - c) < m) {
      m = (a[n - 1] - a[i]) - c;
      pos = i;
    }
  }
  cout << a[pos] << endl;
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;


int main(void){
 int H,W;
 int check=1;
 char s[150][150];
 bool flag[150][150];

 cin>>H>>W;
 for(int i=0; i<H; i++)
  for(int j=0; j<W; j++)flag[i][j]=true;

 for(int i=0; i<H; i++)cin>>s[i];
 
 for(int i=0; i<H; i++){
  for(int j=0; j<W; j++){
   if(s[i][j]=='.');
   else check=0;
  }
  if(check==1)for(int j=0; j<W; j++)flag[i][j]=false;
  check=1;
 }
 
 for(int i=0; i<W; i++){
  for(int j=0; j<H; j++){
   if(s[j][i]=='.');
   else check=0;
  }
  if(check==1)for(int j=0; j<H; j++)flag[j][i]=false;
  check=1;
 }

 for(int i=0; i<H; i++){
  check=0;
  for(int j=0; j<W; j++){
   if(flag[i][j]==true){
    std::cout<<s[i][j];
	check=1;
   }
  }
  if(check==1)std::cout<<std::endl;
 }
 
 return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>

using namespace std;

double calc_dist(int x1, int x2, int y1, int y2) {
	int dx = x1 - x2;
	int dy = y1 - y2;

	double ret = sqrt(dx * dx + dy * dy);
	return ret;
}

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

	vector<int> x(n), y(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
	}

	double ans = 0;
	for (int i = 0; i < n; i++) {
		double dist_i = 0;
		for (int j = 0; j < n; j++) {
			if (i == j) {
				continue;
			}

			double dist = calc_dist(x[i], x[j], y[i], y[j]);
			ans += dist;
		}
	}

	ans /= n;
	printf("%.9f\n", ans);
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace Topic01
{
    class ALDS1_1_B
    {
        static void Main(string[] args)
        {
            int[] init = ReadLine().Split()
                .Select(n => int.Parse(n))
                .OrderByDescending(n => n).ToArray();
            
            int A = init[0];
            int B = init[1];
            int R = B;
            while (R > 0)
            {
                R = A % B;
                A = B;
                B = R;
            }

            int gcd = A;
            WriteLine(gcd.ToString());
            ReadKey();
        }
    }
}


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

using namespace std;

int main() {
    //X:鶴亀個体数　Y:足の数
    int X, Y, turu;
    bool fg=false;
    cin >> X >> Y;

    for (turu = 0; turu <= X; turu++) {
        if (Y - (turu * 4) - ((X - turu) * 2) == 0) {
            cout << "Yes" << endl;
            fg=true;
        }
    }

    if(!fg)cout << "No" << endl;

}

Measured memory_bytes: 3652
from itertools import combinations_with_replacement
N, M, Q = map(int, input().split())
ABCD = []
for _ in range(Q):
    ABCD.append(list(map(int, input().split())))
ref = list(range(1, M+1))
all_candidate = list(combinations_with_replacement(ref, N))
ans = 0
for candidate in all_candidate:
    point = 0
    for abcd in ABCD:
        if candidate[abcd[1]-1] - candidate[abcd[0]-1] == abcd[2]:
            point += abcd[3]
    ans = max(ans, point)
print(ans)

Measured memory_bytes: 21616
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

// using
using namespace std;

// typedef
typedef long long ll;
typedef unsigned long long ull;

// assert
template <typename T>
void assert_between(T val, T min, T max)
{
    assert(min <= val && val <= max);
}

// math
// 最大公約数(Gratest Common Divisor)を求める.
template <typename T>
T gcd(T a, T b)
{
    assert(a > 0 && b > 0);
    T num1 = max(a, b);
    T num2 = min(a, b);
    T mod = num1 % num2;
    return (mod == 0) ? num2 : gcd(num2, mod);
}

// 最小公倍数(Least Common Multiple)を求める.
template <typename T>
T lcm(T a, T b)
{
    return (a * b) / gcd(a, b);
}

void test();
string solve(int number);

void test()
{
    map<int, string> test_cases = {
        {   0, "NA"},
        {   1, "YYMM"},
        {  12, "YYMM"},
        {  13, "NA"},
        {  99, "NA"},

        { 100, "MMYY"},
        { 101, "AMBIGUOUS"},
        { 112, "AMBIGUOUS"},
        { 113, "MMYY"},
        { 199, "MMYY"},
        
        {1300, "NA"},
        {1301, "YYMM"},
        {1312, "YYMM"},
        {1313, "NA"},
        {1399, "NA"},

        {9900, "NA"},
        {9901, "YYMM"},
        {9912, "YYMM"},
        {9913, "NA"},
        {9999, "NA"},
    };

    for (auto test_case: test_cases) {
        string actual = solve(test_case.first);
        if (test_case.second == actual) {
            printf("success! number:%d\n", test_case.first);
        } else {
            printf("fail! number:%d expected:%s actual:%s\n", test_case.first, test_case.second.c_str(), actual.c_str());
        }
    }
}

string solve(int number)
{
    int upper = static_cast<int>(number / 100);
    int lower = static_cast<int>(number % 100);

    if (1 <= upper && upper <= 12) {
        if (1 <= lower && lower <= 12) {
            return "AMBIGUOUS";
        } else {
            return "MMYY";
        }
    } else {
        if (1 <= lower && lower <= 12) {
            return "YYMM";
        } else {
            return "NA";
        }
    }
}

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

    int N;
    scanf("%d", &N);
    assert(0 <= N && N <= 9999);

    int upper = static_cast<int>(N / 100);
    int lower = static_cast<int>(N % 100);

    // test();

    string answer = solve(N);
    printf("%s\n", answer.c_str());

    return 0;
}


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

int main() {


	long int n, a;

	cin >> n >> a;

	for (int i = 0; i <= a; i++) {
		if ((n - i) % 500 == 0) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
typedef long long ll;
#define FOR(i,n) for(int i=0;i<n;i++)

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int Maxn=2010;
const int inf=2147483647;
const int mod=1000000007;
int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int f[Maxn];
int main()
{
	int S=read();
	f[0]=1;f[1]=f[2]=0;
	for(int i=3;i<=S;i++)
	for(int j=3;j<=i;j++)
	f[i]=(f[i]+f[i-j])%mod;
	printf("%d",f[S]);
}


Measured memory_bytes: 3696
import sys
from heapq import *

n, *a = map(int, sys.stdin.read().split())

def optimize(arr):
    res = arr[:n]
    heapify(res)
    sum_arr = [sum(res)]
    for x in arr[n:]:
        y = heappop(res)
        heappush(res, max(x, y))
        sum_arr.append(sum_arr[-1] + max(0, x - y))
    return sum_arr

def main():
    left = a[:n*2]
    right = [-x for x in a[n:]][::-1]

    sum_left = optimize(left)
    sum_right = optimize(right)

    res = []
    for i in range(n+1):
        res.append(sum_left[i] + sum_right[n-i])
        
    ans = max(res)
    return ans

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 38352
#include <iostream>
using namespace std;
int main(){
    int k, s;
    cin >> k >> s;
    int ans = 0;
    for(int x=0; x<k+1; x++){
        for(int y=0; y<k+1; y++){
            int z = s - x - y;
            if(0<=z && z<=k) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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


int main(){
  int K,S;
  cin >> K >> S;
  
  int cnt=0;
  for(int i=0;i<=K;i++){
    for(int j=0;j<=K;j++){
      int m = S-(i+j);
        if(m+i+j==S && m<=K && m>=0)
          cnt++;
    }
  }
  
  cout << cnt << endl;
  
  
  return 0;
}

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

int gcd( int x, int y )
{
  return ( y > 0 and x >= y )? gcd( y, x % y ) : x;
}

int main()
{
  int x, y;
  cin >> x;
  cin >> y;
  if( y > x ) swap( x, y );
  cout << gcd( x, y ) << endl;
}



Measured memory_bytes: 3112
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
	int n; cin >> n;
	long long ans = 1;
	bool bad = false;
	while (n--) {
		long long a; cin >> a;
		if (a == 0) {
			cout << "0\n";
			return 0;
		}
		if (ans > 1000000000000000000LL / a)
			bad = true;
		if (!bad)
			ans *= a;
	}
	cout << (!bad ? ans : -1) << '\n';
	return 0;
}


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

vector<string> bubble_sort(vector<string> C, int N) {
  for (int i = 0; i < N; i++) {
    for (int j = N - 1; j >= i+1; j--) {
      int l = (int) C.at(j-1).at(1);
      int r = (int) C.at(j).at(1);
      if (l > r) {
        swap(C.at(j-1), C.at(j));
      }
    }
  }
  return C;
}

vector<string> selection_sort(vector<string> C, int N) {
  for (int i = 0; i < N; i++) {
    int minj = i;
    for (int j = i; j < N; j++) {
      int j_value = (int) C.at(j).at(1);
      int minj_value = (int) C.at(minj).at(1);
      if (j_value < minj_value) {
        minj = j;
      }
    }
    swap(C.at(i), C.at(minj));
  }
  return C;
}

void print_vector(vector<string> C, int N) {
  for (int i = 0; i < N; ++i) {
    cout << C.at(i);
    if (i < N - 1) {
      cout << " ";
    }
  }
  cout << endl;
}

void print_stable_condition(vector<string> origin, vector<string> sorted, int N) {
  bool stable = true;
  for (int i = 0; i < N-1; i++) {
    string l_card = sorted.at(i);
    string r_card = sorted.at(i+1);

    // カードの数字が同じ場合に、絵柄の並びもソート前と同じであること
    // 以下の例では H4 と S4 の並び順について、ソート後も H4, S4 の順番に並んでいることを確認する
    //
    //   before: H4 C9 S4 D2 C3
    //   after: D2 C3 H4 S4 C9
    //
    if (l_card.at(1) == r_card.at(1)) {
      auto l_itr = find(origin.begin(), origin.end(), l_card);
      auto r_itr = find(origin.begin(), origin.end(), r_card);

      // ソート後は L->R の順番にカードが並んでいるに関わらず
      // ソート前は R->L の順番にカードが並んでいる場合、安定していないと判断
      if (l_itr > r_itr) {
        stable = false;
        break;
      }
    }
  }
  cout << (stable ? "Stable" : "Not stable") << endl;
}

int main() {
  int N;
  cin >> N;
  vector<string> C(N);
  for (int i = 0; i < N; i++) {
    cin >> C.at(i);
  }

  vector<string> b_sorted = bubble_sort(C, N);
  print_vector(b_sorted, N);
  print_stable_condition(C, b_sorted, N);

  vector<string> s_sorted = selection_sort(C, N);
  print_vector(s_sorted, N);
  print_stable_condition(C, s_sorted, N);
  return 0;
}



Measured memory_bytes: 3228
class UnionFind():
    def __init__(self,size):
        self.table=[-1]*size
    def root(self,x):
        while self.table[x]>=0:
            x=self.table[x]
        return x
    def unite(self,x,y):
        s1=self.root(x)
        s2=self.root(y)
        if s1!=s2:
            if self.table[s1]>self.table[s2]:
                s1,s2=s2,s1
            self.table[s1]+=self.table[s2]
            self.table[s2]=s1
        return
    def same(self,x,y):
        return self.root(x)==self.root(y)
    def size(self,x):
        return -self.table[self.root(x)]
n,m,*t=map(int,open(0).read().split())
u=UnionFind(n+1)
for x,y in zip(t[::3],t[1::3]):
    u.unite(x,y)
print(sum(i<0for i in u.table)-1)

Measured memory_bytes: 32172
X, K, D = map(int, input().split())
if X < 0:
    X = -X
k = X // D
if k >= K:
    X -= K * D
    print(abs(X))
else:
    X -= k * D
    K -= k
    if K % 2 == 0:
        print(abs(X))
    else:
        print(abs(X - D))

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

int main() 
{
 int s , w;
 cin >> s >> w;
 if(s > w){
  cout << "safe" << endl; 
 }else{
  cout << "unsafe" << endl; 
 }
  
  return 0;
}

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

const int INF = (1 << 28) - 1;

int main()
{
        int n, m, s, g1, g2;
        int mdist[105][105];

        while ( cin >> n >> m >> s >> g1 >> g2, n ) {
                --s, --g1, --g2;

                fill_n(*mdist, 105 * 105, INF);

                while ( m-- ) {
                        int a, b, c;
                        cin >> a >> b >> c; --a, --b;
                        mdist[a][b] = c;
                }

                for ( int i = 0; i < n; i++ ) mdist[i][i] = 0;

                for ( int k = 0; k < n; k++ ) {
                        for ( int i = 0; i < n; i++ ) {
                                for ( int j = 0; j < n; j++ ) {
                                        mdist[i][j] = min(mdist[i][j], mdist[i][k] + mdist[k][j]);
                                }
                        }
                }

                int minv = INF;

                for ( int i = 0; i < n; i++ ) {
                        minv = min(minv, mdist[s][i] + mdist[i][g1] + mdist[i][g2]);
                }

                cout << minv << endl;
        }

        return ( 0 );
}



Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,k;cin>>n>>k;
    vector<ll>v;
    for(ll i=0;i<n;i++)
    {
        ll n;cin>>n;
        v.push_back(n);
    }
    sort(v.begin(),v.end());
    ll sum=0;
    for(ll i=0;i<k;i++)
    {
        sum+=v[i];
    }
    cout<<sum;

}


Measured memory_bytes: 3640
import itertools
N=int(input())
A=list(map(int, input().split()))
ans=0
for any_pair in itertools.combinations(A, 3):
    pair=sorted(any_pair)#新しいリストを作成
    #print(type(pair))
    if pair[0]+pair[1]>pair[2] and pair[0]!=pair[1] and pair[1]!=pair[2]:
        ans+=1
        #print(pair)
print(ans)

Measured memory_bytes: 9116
import java.util.*;

class Main{
	
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int K = sc.nextInt();
		int h[] = new int[N];

		for(int n=0;n<N;n++){
			h[n] = sc.nextInt();
		}

		int dp[] = new int[N];
		dp[0] = 0;
		dp[1] = Math.abs(h[1]-h[0]);
		for(int n=2;n<N;n++){
			
			int tmp = -1;
			for(int k=1;k<=K;k++){

				if(n < k) break;

				int val = dp[n-k]+Math.abs(h[n]-h[n-k]);
				
				if(tmp==-1 || tmp > val)
				tmp = val;
			}
			dp[n] = tmp;
		}

		System.out.println(dp[N-1]);
	}
}

Measured memory_bytes: 50992
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s, t;
    cin >> s >> t;
    ll n = sz(s);
    vvi cnt(26);
    rep(i, n) {
        cnt[s[i]-'a'].pb(i);
    }
    ll now = -1;
    ll m = sz(t);
    rep(i, m) {
        int idx = t[i] - 'a';
        if (sz(cnt[idx]) == 0) {
            cout << -1 << endl;
            return 0;
        }
        int x = upper_bound(cnt[idx].begin(), cnt[idx].end(), now%n) - cnt[idx].begin();
        if (x == sz(cnt[idx])) {
            now = (now + n) / n * n + cnt[idx][0];
        } else {
            now = now / n * n + cnt[idx][x];
        }
    }
    cout << now+1 << endl;
}

Measured memory_bytes: 1228
using System;
using System.Linq;
using System.Collections.Generic;
namespace abc087b
{
    class Program
    {
        static void Main(string[] args)
        {
            //        int coin[3] = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
            int coina = int.Parse(Console.ReadLine());
            int coinb = int.Parse(Console.ReadLine());
            int coinc = int.Parse(Console.ReadLine());


            int x = int.Parse(Console.ReadLine());
            int ans = 0;
            for(int a = 0; a <= coina; a++)
            {
                for(int b = 0; b <= coinb; b++)
                {
                    for(int c = 0; c <= coinc; c++)
                    {
                        int sum = a * 500 + b * 100 + c * 50;
                        if (x == sum) ans++;
                    }
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,p ;
cin >> n ;
while(n!=0)
{
  p=n%10;
 if(p==7)
 break;
 else
 
 n=n/10;
}
if(p==7)
cout << "Yes" ;
else
cout << "No" ;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define fi first
#define se second
#define show(x) cerr<<#x<<"="<<x<<"\n"
typedef long long ll;
template<typename T>
void print_to(std::ostream &os,const char *,const char *tail,const T &fst){
  os<<fst<<tail;
}
template<typename Fst,typename... Rst>
void print_to(std::ostream &os,const char *del,const char *tail,const Fst &fst,const Rst &... rst){
  os<<fst<<del;
  print_to(os,del,tail,rst...);
}
template<typename Iter>
void print_to_(std::ostream &os,const char *del,const char *tail,Iter bgn,Iter end){
  for(Iter it=bgn;it!=end;){
    os<<*it;
    if(++it!=end)os<<del;
    else os<<tail;
  }
}
template<typename Fst,typename... Rst>
void println(const Fst &fst,const Rst &... rst){
  print_to(std::cout,"\n","\n",fst,rst...);
}
template<typename Fst,typename... Rst>
void print(const Fst &fst,const Rst &... rst){
  print_to(std::cout," ","\n",fst,rst...);
}
template<typename Iter>
void println_(Iter bgn,Iter end){
  print_to_(std::cout," ","\n",bgn,end);
}
using namespace std;
//const ll MOD=(ll)1e9+7;
//const ll inf=(ll)1e14;
const int dy[]={1,0,-1};
const int dx[]={1,0,-1};
int n,m,h,w;
string s;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
  FILE *stream1;
  //FILE *stream2;
  stream1=freopen("in","r",stdin);
  //stream2=freopen("out","w",stdout);
  if(stream1==NULL)return 0;
  //if(stream2==NULL)return 0;
#endif
  cin>>s;
  n=(int)s.size();
  int g=0,p=0;
  int ans=0;
  for(int i=0;i<n;i++){
    if(s[i]=='g'){
      if(p+1<=g){
        p++;
        ans++;
      }else{
        g++;
      }
    }else{
      if(p+1<=g){
        p++;
      }else{
        g++;
        ans--;
      }
    }
  }
  print(ans);
#ifdef LOCAL_DEFINE
  cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
  fclose(stream1);
  //fclose(stream2);
#endif
  return 0;
}






Measured memory_bytes: 512