akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int X, N;
    cin >> X >> N;
    set<int> S;
    for (int i = 0; i < N; ++i) {
        int p;
        cin >> p;
        S.insert(p);
    }
    for (int d = 0; ; ++d) {
        if (!S.count(X - d)) {
            cout << X - d << '\n';
            return 0;
        }
        if (!S.count(X + d)) {
            cout << X + d << '\n';
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3656
n = int(input())
s = input()
ecnt = [0]*n
wcnt = [0]*n
res = 0
for i in range(1,n):
    #ecnt
    if s[i-1] == 'E':res +=1
    ecnt[i] = res
res = 0
for i in range(n-2,-1,-1):
    if s[i+1] == 'W':res+=1
    wcnt[i] = res
ans = 0
for i in range(n):
    ans = max(ans,ecnt[i]+wcnt[i])
ans = n-1-ans
print(ans)

Measured memory_bytes: 19616
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		Array.Sort(T);
		int ans = 0;
		int l = 0,r = -1,cnt = 0;
		for(;l<N;){
			r = l;
			cnt = 1;
			while(l < N && r < N && cnt < C && (T[r] - T[l]) < K){
				r++;
				cnt++;
			}
			if(r >= N || (T[r] - T[l]) > K || cnt > C) r--;
			//Console.WriteLine("{0} {1}",l,r);
			ans++;
			l = r + 1;
		}
		Console.WriteLine(ans);
	}
	int N,C,K;
	int[] T;
	public Sol(){
		var d = ria();
		N = d[0]; C = d[1]; K = d[2];
		T = new int[N];
		for(int i=0;i<N;i++){
			T[i] = ri();
		}
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


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

using namespace std;
const int N = 1e3+10;
char key[] = {'k','e','y','e','n','c','e'};
char str[N];
int len;
int isJudge(int l,int r)
{
    int pos = 0;
    for(int i = 0;i < l;i++)
        if(str[i] == key[pos])
            pos++;
    for(int j = r + 1;j < len;j++)
        if(str[j] == key[pos])
            pos++;
    return pos == 7;
}
int main()
{

   //   "keyence"
    scanf("%s",str);
    len = strlen(str);
    int k = len - 7;
    int flag = 0;
    if(k == 0)
        flag = (strcmp(key,str) == 0?1:0);
    for(int i = 0;!flag && i < len - k;i++)
    {
        int r = i + k - 1;
        if(r < i)   continue;
        flag = isJudge(i,r);
    }
    printf("%s\n",flag?"YES":"NO");

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N;
    string s, t;
    cin >> N >> s >> t;
    
    reverse(s.begin(), s.end());
    for (int i = N; i >= 0; --i) {
        string str = s.substr(0, i);
        reverse(str.begin(), str.end());
        if (str == t.substr(0, i)) {
            cout << 2 * N - i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main () {
  long int n,k,q;
  cin>>n>>k>>q;
  long int a[n+1]={0},m;
  for (long int i=0;i<q;i++)
  {
    cin>>m;
    a[m]++;
  }
  for (long int i=1;i<n+1;i++) {
      //cout<<a[i]<<endl;
    if (k-(q-a[i])>0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define For(i,a,b) for(ll i=a;i<=b;i++)
#define X first
#define Y second
#define maxn 100202
#define eps 0.0000001
#define inf 1e9
#define pb push_back
#define maxD 15
#define ll long long
using namespace std;
ll x,y,z;
typedef pair<ll,ll> ii;
typedef pair<ll,ii> iii;
iii a[maxn],b[maxn];
ll pref[maxn],suff[maxn];
priority_queue<ll,vector<ll>,greater<ll> > PQ,PQ2;
main(){
	int m,n,p;
	cin >> x >> y >> z;
	ll N = x+y+z;
	ll pl = 0;
	For(i,1,N){		
		scanf("%d%d%d",&m,&n,&p);		
		b[i].X = m-n;
		b[i].Y.X = m-p;
		b[i].Y.Y = n-p;				
		pl += p;
	}
	sort(b+1,b+N+1);
	For(i,1,N) a[i] = b[N-i+1];
	For(i,1,N){
//		cout << a[i].X << " " << a[i].Y.X << " " << a[i].Y.Y << "\n";
	}
	ll tempV = 0;
	For(i,1,x) {
		PQ.push(a[i].Y.X);
		tempV  += a[i].Y.X;
	}
	pref[x] = tempV;
	For(i,x+1,N-y){
		PQ.push(a[i].Y.X);
		tempV+=a[i].Y.X;
		tempV-=PQ.top();
		PQ.pop();
		pref[i] = tempV;
	}
	tempV = 0;
	for(ll i=N;i>N-y;i--) {
		PQ2.push(a[i].Y.Y);
		tempV  += a[i].Y.Y;
	}
	suff[N-y+1] = tempV;
	for(ll i=N-y;i>=x+1;i--){
		PQ2.push(a[i].Y.Y);
		tempV+=a[i].Y.Y;
		tempV-=PQ2.top();
		PQ2.pop();
		suff[i] = tempV;
	}
	ll ans = -1e18;
	For(i,x,N-y){
		ans = max(ans,pref[i]+suff[i+1]);		
//		cout << pref[i] << " " << suff[i+1] << "\n";		
	}	
	cout << ans + pl;
}

Measured memory_bytes: 6428
#include <bits/stdc++.h> 
#include <chrono>
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const LL MOD=(LL)1e9+7;
const LL MAX_N=1e5;
LL fact[MAX_N],ifact[MAX_N],inv[MAX_N];

void _inv(){
    inv[0]=inv[1]=1LL;
    for(LL i = 2LL;i < MAX_N;i++){
        inv[i]= (inv[MOD%i] * (MOD - MOD/i)) % MOD;
    }
}
void calc(){
    _inv();
    fact[0]  =1LL;
    ifact[0] =1LL;
    for(LL i = 1LL;i < MAX_N;i++){
        fact[i] = (fact[i-1LL] * i) % MOD;
        ifact[i]= (inv[i] * ifact[i-1]) % MOD;
    }
}
LL C(LL n, LL r){
    if(n < 0 || r < 0 || r > n)return 0;
    if(r>n/2LL)r = n - r;
    return (fact[n]*ifact[n-r]%MOD)*ifact[r]%MOD;
}
LL H(LL n,LL r){
    return C(n+r-1LL,r);
}

int main(){
    int S;
    cin>>S;
    calc();
    if(S<3){
        cout<<0<<endl;return 0;
    }
    int n=1;
    LL res=0;
    while(S-3*n>=0){
        res+=H(n,S-3*n);
        //cout<<n<<":"<<H(n,S-3*n)<<endl;
        res%=MOD;
        n++;
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 5956
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define prints(x, y) cout<<(x)<<" "<<(y)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back

int main() {
  string s;
  cin >> s;
  vector<int> a(26);

  for(char c: s){
    a[int(c-'a')]++;
  }

  rep(i, 26){
    if(a[i]==0) {
      print(char(i+'a'));
      return 0;
    }
  }
  print("None");
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
#define INF 1000000007
#define maxn 1000000009
signed main()
{
    deque<ll> a;
    int N, K;
    ll ans = 0;
    cin >> N >> K;
    for (int i = 0; i < N; i++)
    {
        int v;
        cin >> v;
        a.push_back(v);
    }
    for (int l = 0; l <= K; ++l)
    {
        for (int r = 0; r <= K - l; ++r)
        {
            if (l + r > N)
                continue;
            int d = K - l - r;
            ll now = 0;
            vector<ll> s;
            for (int i = 0; i < l; ++i)
            {
                now += a[i];
                s.push_back(a[i]);
            }
            for (int i = (N - r); i < N; ++i)
            {
                now += a[i];
                s.push_back(a[i]);
            }
            sort(s.begin(), s.end());
            for (int i = 0; i < d; i++)
            {
                if (i >= s.size())
                    break;
                if (s[i] > 0)
                    break;
                now -= s[i];
            }
            ans = max(now, ans);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdlib>
using namespace std;
struct coo{
	int x;
	int y;
	int h;
}c[110];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>c[i].x;
		cin>>c[i].y;
		cin>>c[i].h;
	}
	int ch;
	int p=0;
	while(c[p].h==0) p++;
	for(int i=0;i<=100;i++)
	{
		for(int j=0;j<=100;j++)
		{
			int ch=c[p].h+abs(i-c[p].x)+abs(j-c[p].y);
			int f=0;
			for(int k=0;k<n;k++)
			{
				int hh=ch-abs(i-c[k].x)-abs(j-c[k].y);
				if(hh<0) hh=0;
				if(hh!=c[k].h)
				{
					f=1;
					break;
				}
			}
			if(!f)
			{
				cout<<i<<' '<<j<<' '<<ch<<endl; return 0;
			} 
		}
	}
} 



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

int main() {
  int N;
  cin >> N;
  vector<int> l(1000);
  vector<int> r(1000);
  for(int i=0;i<N;i++){
    cin >> l[i] >> r[i];
  }
  int ans=0;
  for(int i=0;i<N;i++){
    ans += r[i]-l[i]+1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import std.stdio;
import std.array;
import std.string;
import std.conv;
import std.algorithm;
import std.typecons;
import std.range;
import std.random;
import std.math;
import std.container;
import std.numeric;
import std.bigint;


struct UnionFind {
  int n;
  int[] table;

  this (int N) {
    n = N;
    table = new int[](n);
    foreach (i; 0..n)
      table[i] = -1;
  }

  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (table[x] < table[y]) swap(x, y);
    table[y] += table[x];
    table[x] = y;
  }

  int find(int x) {
    if (table[x] < 0)
      return x;
    return table[x] = find(table[x]);
  }
}

void main() {
  auto s = readln.split.map!(to!int);
  auto N = s[0];
  auto K = s[1];
  auto L = s[2];

  auto uf1 = new UnionFind(N);
  foreach (k; 0..K) {
    s = readln.split.map!(to!int);
    uf1.unite(s[0]-1, s[1]-1);
  }
  auto uf2 = new UnionFind(N);
  foreach (l; 0..L) {
    s = readln.split.map!(to!int);
    uf2.unite(s[0]-1, s[1]-1);
  }

  int[Tuple!(int, int)] cnt;
  foreach (n; 0..N) {
    auto t = tuple(uf1.find(n), uf2.find(n));
    if (t in cnt)
      cnt[t]++;
    else
      cnt[t] = 1;
  }

  iota(N).map!(n => (cnt[tuple(uf1.find(n), uf2.find(n))]).to!string).join(" ").writeln;

}


Measured memory_bytes: 19836
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P  = pair<int,int>;
using v  = vector<int>;
using vv = vector<v>;
//const int MOD = 1000000007;
const int MOD = 998244353;
const int INF = 1001001001;

int main(){
    int n,l;cin >>n>>l;
    
    int before = l*n + n*(n-1)/2;
    int bite;
    
    if(l<=0 && l+n-1>=0)bite = 0;
    else if(l>0)bite = l;
    else bite = l+n-1;
    
    cout << before - bite << endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
    class Main{
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();

            if(n<='Z'&&n>='A'){
                System.out.println(1);
            } else if(n<='z'&&n>='a'){
                System.out.println(2);
            } else {
                System.out.println(0);
            }
        }
    } 


Measured memory_bytes: 26408
#include<stdio.h>

int main(void){
	
	int W,H,x,y,r;
	int ue,sita,migi,hidari;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	
	
	ue = y+r;
	sita = y-r;
	migi = x+r;
	hidari = x-r;
	
	if((ue>H)||(sita<0)||(migi>W)||(hidari<0)){
		printf("No\n");
	}
	else{
		printf("Yes\n");
	}
	
	
	
	
	return 0;
	
}

Measured memory_bytes: 580
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        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();
        }
        
        Arrays.sort(S);
        int ans=1;
        
        for(int i=1;i<N;i++){
            if(S[i].equals(S[i-1])){
                
            }else{
                ans++;
            }
        }
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 69488
#include <iostream>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;

int main(){
  int n;
  cin >> n;
  n = n%10;
  
  if(n==3){cout << "bon";}
  else if(n==0 || n==1 || n==6 || n==8){
    cout << "pon";
  }
  else{cout << "hon";}
  
  return 0;
}


Measured memory_bytes: 3588
import java.util.*;
public class Main {
  	public static int pow1(int a, int b) {
      	long res = a;
      	for( int i = 0; i < b - 1; i++ ) {
          	res = res * a % 1000000007;
        }
      	return (int)res;
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int a = sc.nextInt();
        //if(a > 10) System.exit(1);
      	int i = pow1(10, a);
      	int j = pow1(9, a) * 2 % 1000000007;
      	int k = pow1(8, a);
      	
      	long l = i - j + k;
      	l %= 1000000007;
      	if(l < 0) {
        	l += 1000000007;
        }
        System.out.println(l);
    }
}

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

int main(){

    int K,A,B;
    cin >> K >> A >> B;
    bool ok = false;
    for(int i=A; i<=B;i++){
        if(i%K==0) ok = true;
    }
    if(ok) cout << "OK" << endl;
    else cout << "NG" << endl;
}


Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include<queue>
#include <sstream>
#include <set>
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
using namespace std;
int main(){
    int N,K,ans=0;
    cin >> N>>K;

    REP(i,N){
        int x;
        cin >> x;

        ans += (min(x,(K-x)))*2;
        
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <unordered_map>
using namespace std;
int main()
{
	int n, index, sum = 0;
	cin >> n;
	unordered_map<int, bool> mp;
	while (n--)
	{
		cin >> index;
		if (mp.find(index) != mp.end())
		{
			mp[index] = !mp[index];
			mp[index] ? ++sum : --sum;
		}
		else
		{
			mp[index] = true;
			++sum;
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 4388
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll mod=1e9+7;

int main(){
	int a;
	string s;
	cin >> a;
	cin >> s;

	if(a>=3200){
		cout << s << endl;
	}else{
		cout << "red" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#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 x,y;cin>>x>>y;
    if(2*x<=y && y<=4*x && y%2==0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
   int N,K;
   cin>>N>>K;
   using P=pair<ll,ll>;
   vector<P> v(N);
   for(int i=0;i<N;++i) cin>>v[i].first>>v[i].second;
   sort(v.begin(),v.end());
   
   ll ans=1LL<<62;
   for(int a=0;a<N;++a){
      for(int b=0;b<N;++b){
         ll ly=v[a].second,ry=v[b].second;
         if(ly>ry) continue;
         for(int c=0;c<N;++c){
            if(!(ly<=v[c].second && v[c].second<=ry)) continue;
            ll lx=v[c].first;
            ll rx;
            int cnt=1;
            for(int d=c+1;d<N&&cnt<K;++d){
               if(ly<=v[d].second && v[d].second<=ry){
                  cnt++;
                  rx=v[d].first;
               }
            }
            if(cnt<K) continue;
            
            ans=min(ans,(rx-lx)*(ry-ly));
         }
      }
   }

   cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main() {
	int a, b, c;

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

	int sum = a + b + c;

	if(a == sum - a) printf("Yes\n");
	else if(b == sum - b) printf("Yes\n");
	else if(c == sum - c) printf("Yes\n");
	else printf("No\n");
	
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    string s;
    int ans = 0;
    int slow = 0;
    cin >> s;
    for(int i = 0; i < s.length(); i++) {
        if (s[i] == 'A' || s[i] == 'T' || s[i] == 'C' || s[i] == 'G') {
            ans = max(ans, i - slow + 1);
        } else {
            slow = i+1;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <ctype.h>
#include <algorithm>

int main()
{
  int H, W, dp[50][50];
  while (scanf("%d %d", &H, &W) != EOF) {
    for (int i = 0; i < H; ++i) {
      for (int j = 0; j < W; ++j) {
	char c;
	scanf("%c", &c);
	if (!isdigit(c)) {
	  --j;
	  continue;
	}
	dp[i][j] = c -'0';
      }
    }
    
    dp[0][0] = 0;
    for (int i = 0; i < H; ++i) {
      for (int j = 0; j < W; ++j) {
	if (i > 0 && j > 0)
	  dp[i][j] += std::min(dp[i-1][j], dp[i][j-1]);
	else if (i > 0)
	  dp[i][j] += dp[i-1][j];
	else if (j > 0)
	  dp[i][j] += dp[i][j-1];
      }
    }
    
    printf("%d\n", dp[H-1][W-1]);
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define rep(i,N) for(int i=0;i<(int)N;++i)

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

ll LCM(ll x, ll y) {
    return x / GCD(x, y) * y;
}

ll wazu = 76543217;

ll inv(ll x) {
    if (x == 1) { return 1; }
    if (x == 0) { return 0; }
    else {
        ll a = (wazu - inv(wazu % x) * (wazu / x)) % wazu;
        if (a >= 0) { return a; }
        else { return wazu + a; }
    }
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    string A, B, C="";
    cin >> A;
    cin >> B;

    int m = A.size();
    int n = B.size();


    if (m - n == 0) {
        rep(i, m) { C += A[i]; C += B[i]; }
    }
    else if (m - n == 1) {
        rep(i, n) { C += A[i]; C += B[i]; }
        C += A[m - 1];
    }

    cout << C << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
 
public class Main {
 
	void submit() {
	    
	    String s = nextString();
	    
	    int mogu = 0;
	    for(int i=0; i<4; i++){
    	    if(s.charAt(i) == '+'){
    	        mogu++;
    	    }else{
    	        mogu--;
    	    }
	    }
	    out.println(mogu);
	    
	}

	void preCalc() {
 
	}
 
	void stress() {
 
	}
 
	void test() {
 
	}
 
	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		submit();
		//stress();
		//test();
		out.close();
	}
 
	static final Random rng = new Random();
 
	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}
 
	public static void main(String[] args) throws IOException {
		new Main();
	}
 
	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
 
	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}
 
	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
 
	int nextInt() {
		return Integer.parseInt(nextToken());
	}
 
	long nextLong() {
		return Long.parseLong(nextToken());
	}
 
	double nextDouble() {
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 23252
import math
a,b,h,m = map(int,input().split())
ax = 30*h + 0.5*m
bx = 6*m
y = abs(ax - bx)
if y > 180:
    y = 360 - abs(ax - bx)

print((a**2+b**2-2*a*b*math.cos(math.radians(y)))**0.5)

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

int n, d, s, m;

int main() {
    cin >> n;
    vector<int> d(n);
    for (int i=0;i<d.size();i++) {
      cin >> d.at(i);
    }
    sort(d.begin(), d.end());
    s = d.at(0);
    for (int k=0;k<d.size();k++) {
      if (d.at(k)>s) {
        m++;
        s = d.at(k);
      } 
    }
    cout << m + 1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  int n,m;
  cin>>n>>m;
  
  int ans=0;
  vector<pair<int,int>> p(m);
  rep(i,m){
    cin>>p[i].se>>p[i].fi;
  }
  sort(all(p));

  int x=0;
  rep(i,m){
    if(p[i].se<=x) continue;
    ans++;
    x=p[i].fi-1;
  }

  cout << ans << endl;
}

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

int main(){
  int h,n;
  int k = 0;
  cin >> h >> n;
  int a[n];
  for(int i=0; i<n; i++){
    cin >> a[i];
    k = k+a[i];
  }
  if(k>=h){cout << "Yes" << endl;}
  else{cout << "No" << endl;}
}


Measured memory_bytes: 640
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include <bits/stdc++.h>

using namespace std;

struct Node;

using NodePtr = shared_ptr<Node>;

struct Node {
  NodePtr parent;
  int rank = 0;

  // additional properties
  set<int> friends;
  set<int> blocks;
  int size = 1;
};

struct DisjointSet {
  map<int, NodePtr> nodes;

  void make_set (int i) {
    NodePtr node = make_shared<Node>();
    nodes.insert(make_pair(i, node));
    node->parent = node;
  }

  void unite (int ix, int iy) {
    NodePtr x = nodes.at(ix);
    NodePtr y = nodes.at(iy);
    NodePtr xRoot = find(x);
    NodePtr yRoot = find(y);

    if (xRoot == yRoot) return;

    if (xRoot->rank < yRoot->rank) {
      xRoot->parent = yRoot;
      yRoot->size += xRoot->size;
    } else if (xRoot->rank > yRoot->rank) {
      yRoot->parent = xRoot;
      xRoot->size += yRoot->size;
    } else {
      xRoot->parent = yRoot;
      yRoot->rank++;
      yRoot->size += xRoot->size;
    }
  }

  NodePtr find (NodePtr x) {
    if (x->parent == x) {
      return x;
    } else {
      // with path compression
      NodePtr root = find(x->parent);
      x->parent = root;
      return root;
    }
  }

  bool compare (int ix, int iy) {
    NodePtr x = nodes.at(ix);
    NodePtr y = nodes.at(iy);
    return find(x) == find(y);
  }

  // additional properties
  NodePtr get_node (int i) {
    return nodes.at(i);
  }
};

/**
 * main
 */
int main () {
  DisjointSet djs;

  int N, M, K;

  cin >> N >> M >> K;

  for (size_t i = 1; i <= N; i++) {
    djs.make_set(i);
  }

  // friend
  for (size_t i = 2; i <= 1 + M; i++) {
    int a, b;
    cin >> a >> b;
    djs.unite(a, b);

    djs.get_node(a)->friends.insert(b);
    djs.get_node(b)->friends.insert(a);
  }

  // block
  for (size_t i = 1 + M + 1; i <= 1 + M + K; i++) {
    int c, d;
    cin >> c >> d;

    djs.get_node(c)->blocks.insert(d);
    djs.get_node(d)->blocks.insert(c);
  }

  for (size_t i = 1; i <= N; i++) {
    NodePtr node = djs.get_node(i);
    NodePtr root = djs.find(node);

    int n_friends = 0;
    for (int fred : node->friends) {
      if (djs.compare(i, fred)) n_friends++;
    }

    int n_blocks = 0;
    for (int block : node->blocks) {
      if (djs.compare(i, block)) n_blocks++;
    }

    int n = root->size - n_friends - n_blocks - 1;

    printf("%d%c", n, (i == N) ? '\n' : ' ');
  }
}


Measured memory_bytes: 41472
#include<stdio.h>
int main(void)
{
	int a,b,x=0,i;
	scanf("%d %d",&a,&b);
		for(i=1;i<=2;i++){
				if(a>=b){
						x+=a;
							a--;
				}
				else {
						x+=b;
						b--;
				}
		}

		    printf("%d\n",x);
		    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <limits>

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)

constexpr int MAXN = 100;
constexpr int MAXINT = std::numeric_limits<int>::max();


int G[MAXN][MAXN];
int D[MAXN];
int C[MAXN];
int P[MAXN];
int n;

int main() {
    std::cin >> n;
    FOR(i, 0, n)
    FOR(j, 0, n)
    {
        G[i][j] = MAXINT;
    }

    FOR(i, 0, n){
        int id, e;
        std::cin >> id >> e;
        FOR(i, 0, e) {
            int v, c;
            std::cin >> v >> c;
            G[id][v] = c;
        }
    }

    FOR(i, 0, n) D[i] = MAXINT;

    int r = -1;
    D[0] = 0;
    while (true) {
        int mincost = MAXINT;
        int t;
        for (int i = 0; i < n; i++) {
            if ((C[i] == 0)  && (D[i] < mincost)) {
                mincost = D[i];
                t = i;
            }
        }

        if (mincost == MAXINT) {
            break;
        }

        C[t] = 1;
        P[t] = r;

        for (int i = 0; i < n; i++) {
            if ((C[i] == 0) && (G[t][i] != MAXINT) && ((D[t] + G[t][i]) < D[i])) {
                D[i] = D[t] + G[t][i];
            }
        }
        r = t;
    }
    FOR(i, 0, n) {
        std::cout << i << " " << D[i] << std::endl;
    }
}


Measured memory_bytes: 3156
#include <stdio.h>
#include <string.h>

int main(void) {
    int N, a, x, t[100], i;
    char S[110][100], X[110];
    scanf("%d", &N);
    for (i=0; i<N; i++) scanf("%s%d", S[i], &t[i]);
    scanf("%s", X);
    for (i=0; i<N; i++) {
        if (strcmp(S[i], X)==0) break;
    }
    a=i; x=0;
    for (i=a+1; i<N; i++) x+=t[i];
    printf("%d", x);
    return 0;
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    int n;cin >> n;
    vl a(3*n);
    rep(i,3*n)cin>>a[i];
    sort(rall(a));
    //debug(a);
    ll res = 0;
    for(int i=1;i<2*n+1;i+=2)res+=a[i];
    out(res);
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
int mod = 1000000000+7;

int main(){

	int n;
	cin>>n;
	int ans=0;
	ans+=(n/500)*1000;
	n=n%500;
	ans+=(n/5)*5;

	cout<<ans<<endl;



	return 0;
}


Measured memory_bytes: 256
//ABC126-D
//Reference: 解説放送 (from youtube)
#include<iostream>
#include<queue>
#include<vector>
#define pb push_back
using namespace std;

int main(){
  int N;
  cin >>N;
  vector<vector<int> > to(N),cost(N);
  
  for(int i=0;i<N-1;i++){
    int a, b, w;
    cin >> a>>b>>w;
    a--;//1 start to 0 start
    b--;
    to[a].pb(b);cost[a].pb(w);
    to[b].pb(a);cost[b].pb(w);
  }
  vector<int> ans(N,-1);
  queue<int> q;

  ans[0]=0;//0を0で塗ることにする。
  q.push(0);
  while(!q.empty()){
    int u = q.front();
    q.pop();
    for(int i=0;i<to[u].size();i++){
      int v = to[u][i];
      int w = cost[u][i];
      if(ans[v]!=-1) continue;
      ans[v]=(ans[u]+w)%2;
      q.push(v);
    }
  }
  for(int i=0;i<N;i++){
    cout<<ans[i]<<endl;
  }  
}


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

/* Swap and count its number */
int bubbleSort(int A[], int n) {
  int sw = 0;
  bool flg = 1;
  for (int i=0; i<n-1; i++) {
    for (int j=n-1; j>i; j--) {
      if (A[j-1] > A[j]) {
        swap(A[j-1], A[j]);
        sw ++;
      }
    }  
  }
  return sw;
}

int main() {
  int n, sw;
  cin >> n;
  int A[n];
  for (int i=0; i<n; i++) {
    cin >> A[i];
  }
  sw = bubbleSort(A, n);
  for (int i = 0; i<n; i++) {
    if (i>0) {
      cout << " ";
    }
    cout << A[i];
  }
  cout << endl;
  cout << sw << endl;
  return 0;
}



Measured memory_bytes: 3088
n = gets.to_i
B_arr = gets.split.map(&:to_i)
A_arr = [B_arr[0],B_arr[-1]]

(1..n-2).each do |i|
  if B_arr[i-1] < B_arr[i]
      A_arr << B_arr[i-1]
  else
      A_arr << B_arr[i]
  end
end

p A_arr.inject(&:+)


Measured memory_bytes: 1788
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    vector<bool> db(n, false);
    vector<int> il(n, 1);
    db[0] = true;
    for (int i = 0; i < m; ++i)
    {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        if (db[a])
        {
            if (il[a] >= 2)
                db[b] = true;
            else
            {
                db[a] = false;
                db[b] = true;
            }
        }
        --il[a];
        ++il[b];
    }
    int odp = 0;
    for (int i = 0; i < n; ++i)
        if (db[i])
            ++odp;
    cout << odp;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
template <class T>
void print(const T &value)
{
	std::cout << value << std::endl;
}
int GCD(int x, int y)
{
	return x ? GCD(y % x, x) : y;
}

int main()
{
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	int cnt=1;
	deque<pair<int,int>>zero;
	int znt=0;
	rep(i,n-1){
		if(s[i]==s[i+1]){
			cnt++;
		}else{
			if(s[i]=='0'&&zero.size()==0){
				znt++;
				zero.push_back(make_pair(i+1,0));
			}
			if(s[i]=='1'){
				znt++;
				zero.push_back(make_pair(i+1,i+1-cnt));
			}
			cnt=1;
		}
		//cout<<i<<" "<<cnt<<endl;
	}
	if(s[n-1]=='1'){
		zero.push_back(make_pair(n,n-cnt));
	}else{
		znt++;
		zero.push_back(make_pair(n,n-cnt));
	}
	int ans=0;
	int m=min(znt,k);

	rep(j,zero.size()){
		//cout<<zero[j].F<<" "<<zero[j].S<<endl;
		if(j+m<zero.size()){
		ans=max(ans,zero[j+m].F-zero[j].S);
		}
	}
	if(zero.size()==1){
		ans=max(ans,zero[0].F-zero[0].S);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 768
// AOJ 2738: A-un Breathing
// 2017.10.8 bal4u@uu

#include <stdio.h>

int main()
{
	int n, a, u;
	char s[10];

	scanf("%d", &n);
	a = u = 0;
	while (n-- > 0) {
		scanf("%s", s);
		if (*s == 'A') a++;	else u++;
		if (u > a) goto NO;
	}
	if (u == a) puts("YES");
	else {
NO:		puts("NO");
	}
	return 0;
}

Measured memory_bytes: 1720
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define P pair<int, int>
typedef long long ll;
const ll mod = 1e9+7;

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

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}


int main(){
  int n;
  cin >> n;
  if(n / 10 == 9 || n % 10 == 9) cout << "Yes" << endl;
  else cout << "No" << endl;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
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;}
template <class T> using heap = priority_queue<T,vector<T>,greater<T>>;
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int n,m,k;
    cin>>n>>m>>k;
    REP(i,n+1) {
        REP(j,m+1) {
            if(k==n*j+m*i-i*j*2) {
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}


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

int main(int argc, char const *argv[])
{
	string s; cin >> s;

	bool flag = true;
	rep(i, (int)s.size()) {
		if (i % 2 == 0) {
			if (not (s[i] == 'R' or s[i] == 'U' or s[i] == 'D'))
				flag = false;
		} else {
			if (not (s[i] == 'L' or s[i] == 'U' or s[i] == 'D'))
				flag = false;
		}
	}
	cout << (flag ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define EPS 10e-8
#define MAX_N 300

using namespace std;
typedef pair<llong, llong> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

llong N, A[MAX_N][MAX_N];
bool used[MAX_N][MAX_N];

llong solve() {

    for(int k = 0; k < N; ++k)
        for(int i = 0; i < N; ++i) 
            for(int j = i + 1; j < N; ++j) {
                if(i == k || j == k) continue;

                if(A[i][k] + A[k][j] < A[i][j])
                    return -1;
                else if(A[i][k] + A[k][j] == A[i][j]) {
                    used[i][j] = false;
                }

            }

    llong res = 0;
    for(int i = 0; i < N; ++i) 
        for(int j = i + 1; j < N; ++j)
            if(used[i][j])
                res += A[i][j];
    
    return res;
}

int main(int argc, char **argv) {
    cin >> N;
    for(int i = 0; i < N; ++i) 
        for(int j = 0; j < N; ++j)
            cin >> A[i][j];
            
    for(int i = 0; i < N; ++i) 
        for(int j = 0; j < N; ++j)
            used[i][j] = true;

    cout << solve() << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
using namespace std;

typedef long long ll;

int n;
ll t;

ll gcd(ll x, ll y) { return x? gcd(y % x, x): y; }

int main()
{
	scanf("%d", &n);
	ll cur = 1;
	for (int i = 1; i <= n; i++) {
		cin >> t;
		cur = cur / gcd(cur, t) * t;
	}
	cout << cur << endl;
	return 0;
}

Measured memory_bytes: 256
N = gets.chomp.to_i

results = []

gets.chomp.split.map(&:to_i).each_with_index do |shincho, i|
  if i == 0
    results << { shincho: shincho, dai: 0 }
  else
    maenohitotonosa = (results[i-1][:shincho] + results[i-1][:dai]) - shincho
    if maenohitotonosa > 0
      results << { shincho: shincho, dai: maenohitotonosa }
    else
      results << { shincho: shincho, dai: 0 }
    end
  end
end

puts results.sum { |r| r[:dai] }

Measured memory_bytes: 85720
A, B, K = map(int, input().split())

if A+K-1 >= B-K+1:
  for i in range(A,B+1):
    print(i)
else:
  for i in range(A, A+K):
    print(i)
  for i in range(B-K+1, B+1):
    print(i)
    
    

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

using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define debug(x) cerr << #x << " = " << (x) << endl;
template<typename T>
ostream& operator<<(ostream& o, vector<T>& v) {
    for (auto& x : v) o << x << ' ';
    return o;
}
int n;
double arr[3030];
double memo[3030][3030];
double dp(int i, int heads) {
  double &res = memo[i][heads];
  if (res == res) return res;
  if (i == n)
    return (heads == 0) ? 1.0 : 0.0;
  res = arr[i] * dp(i+1, heads - 1) + (1 - arr[i]) * dp(i+1, heads);
  return res;
}

int main(){
    std::ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) cin >> arr[i];
    memset(memo, -1, sizeof memo);
    double prob = 0.0;
    for (int i = n/2 + 1; i <= n; i++) {
      prob += dp(0, i);
    }
    cout << fixed << setprecision(10) << prob << endl;
}


Measured memory_bytes: 72192
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int first = Integer.parseInt(s.substring(0,2));
        int end = Integer.parseInt(s.substring(2,4));
        if((first >= 1 && first <= 12) && (end >= 1 && end <= 12)){
            System.out.println("AMBIGUOUS");
        }else if((first == 0 || first >= 13) && (end >= 1 && end <= 12)){
            System.out.println("YYMM");
        }else if((first >= 1 && first <= 12) && (end == 0 || end >= 13)){
            System.out.println("MMYY");
        }else{
            System.out.println("NA");
        }
        
    }
}


Measured memory_bytes: 21460
#include <cstdio>
#include <cmath>
#include <algorithm>

static const long long MAX = 100100;
static const long long INF = 1LL << 31;

int main()
{
    int N, K; // N: 足場の数, K: 選択肢の数
    long long h[MAX];
    long long dp[MAX];

    scanf("%d%d", &N, &K);
    for (int i = 0; i < N; i++) scanf("%lld", &h[i]);
    for (int i = 0; i < N; i++) dp[i] = INF;

    dp[0] = 0;
    for (int i = 1; i < N; i++)
    {
        for (int j = 1; j <= K; j++)
        {
            if (i >= j)
            {
                dp[i] = std::min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
            }
        }
    }

    printf("%lld\n", dp[N-1]);

    return 0;
} 

Measured memory_bytes: 1664
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] count = new int[n];
		for(int i=0;i<n;i++) {
			count[i] = 0;
		}
		for(int i=1;i<=n;i++) {
			int nn = i;
			int j = 2;
			while(nn!=1) {
				if(nn%j==0) {
					count[j-1] += 1;
					nn = nn/j;
					j = 2;
				}else {
					j += 1;
				}
			}
		}
	//	System.out.println(Arrays.toString(count));
		long ans = 1;
		for(int i=1;i<n;i++) {
			if(count[i]!=0) {
				ans = (ans*(count[i]+1))%1000000007;
	//			System.out.println(ans);
			}
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
#define mod 1000000007

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

int main(){
    ll r,d,x;
    cin >> r >> d >> x;
    cout << (x/r)*d << 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 way;
        while(true){
            way = 0;
            int n = sc.nextInt();
            int x = sc.nextInt();
            if(n == 0 && x == 0) break;
            for(int i=1;i<=n;i++){
                for(int j=1;j<=n;j++){
                    if(i == j) break;
                    for(int k=1;k<=n;k++){
                        if(i == k) break;
                        if(j == k) break;
                        int sum = i + j + k;
                        if(sum == x ) way++;
                    }
                }
            }
            System.out.printf("%d\n",way);
        }
    }
}


Measured memory_bytes: 26900
#!/usr/bin/env python3
import sys


def solve(N: int, R: int):
    if N >= 10:
        print(R)
    else:
        print(R+100*(10-N))

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    R = int(next(tokens))  # type: int
    solve(N, R)

if __name__ == '__main__':
    main()


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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;
struct Edge{ll from, to, cost;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N;
  set<ll> prime;
  cin >> N;
  rep(i, 101){
    if(is_prime(i+1))prime.insert(i+1);
  }
  map<ll, ll> fact;
  for(auto i: prime){
    ll cnt = 1;
    while(N/pow(i, cnt)>0){
      fact[i]+=N/pow(i, cnt);
      cnt +=1;
    }
  }
  ll ans = 0;
  ll cnt74=0, cnt24=0, cnt14=0, cnt4=0, cnt2=0;
  
  for(auto i:fact){
    //cout << i.first <<" " << i.second << endl;
    if(i.second>=74)cnt74++;
    if(i.second>=24)cnt24++;
    if(i.second>=14)cnt14++;
    if(i.second>=4)cnt4++;
    if(i.second>=2)cnt2++;
  }
  
  ans += cnt74;
  ans += cnt24*(cnt2-1);
  ans += cnt14*(cnt4-1);
  ans += (cnt4-1)*cnt4/2 *(cnt2-2);

  cout << ans;
  return 0;
}


Measured memory_bytes: 512
n, k = map(int, input().split())
A = list(map(lambda x: x-1, map(int, input().split())))
isVisit = [False]*n
visits = []
visit = 0
for i in range(n):
    if isVisit[visit]:
        break
    else:
        isVisit[visit] = True
        visits.append(visit)
        visit = A[visit]

if len(visits)>k:
    print(visits[k]+1)
else:
    k -= visits.index(visit)
    visits = visits[visits.index(visit):]
    print(visits[k%len(visits)]+1)

Measured memory_bytes: 32372
n = gets.to_i
a_arr = gets.chomp.split.map(&:to_i)

min_n = 1_000_000_000
arr_sum = 0
minus_num_count = 0

n.times do |i|
	minus_num_count += 1 if a_arr[i].negative?
	if min_n > a_arr[i].abs
		min_n = a_arr[i].abs
	end
	arr_sum += a_arr[i].abs
end

if minus_num_count % 2 == 0
	puts arr_sum
else
	puts arr_sum - (min_n * 2)
end


Measured memory_bytes: 9732