akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int IsRightTriangle(int a, int b, int c);

int main(void){
    int n, a, b, c;

    scanf("%d", &n);
    for (int i=0; i<n; i++){
        scanf("%d %d %d", &a, &b, &c);
        if (IsRightTriangle(a,b,c)){
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    }
    return 0;
}

int IsRightTriangle(int a, int b, int c){
    if (a*a == b*b + c*c) return 1;
    if (b*b == c*c + a*a) return 1;
    if (c*c == a*a + b*b) return 1;
    return 0;
}

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

typedef unsigned int U;
#define L 1<<21
char HA[L], T[256];

int main() {
    U n, s, t;
    char c;
    T['A'] = 4;
    T['C'] = 3;
    T['G'] = 2;
    T['T'] = 1;
    scanf("%d", &n);
    getchar();
    while (n--) {
        s = 0;
        t = 1;
        int flag = ( c = getchar() ) == 'i';
        while ( ( c = getchar() ) != ' ' );
        while ( ( c = T[getchar()] ) != 0 ) {
            s += c * t;
            t *= 4;
        }
        if ( flag ) {
            HA[s] = 1;
        } else {
            puts( HA[s] ? "yes" : "no" );
        }
    }
    return 0;
}

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

int f(int n, int m) {
    if (n == 4 || n == 2 || n == 1) return m;

    if (n % 2) return f(3*n + 1, m + 1);
    else return f(n / 2, m + 1);
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    int s;
    cin >> s;

    cout << f(s, 1) + 3 << endl;

    return 0;
}


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

int main(void){
    int n;
    cin >> n;
    set<string> s;
    rep(i,n) {
        string a;
        cin >> a;
        s.insert(a);
    }
    cout << s.size() << endl;
    return 0;
}

Measured memory_bytes: 19156
#include <bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
string dp[70][70],m[70];
int h,w;
string dfs(int y,int x,string s){
  if(dp[y][x].size()>s.size())return dp[y][x];
  if(dp[y][x].size()==s.size()&&dp[y][x]>s)return dp[y][x];
  string p1,p2;
  if(y+1<h&&'0'<=m[y+1][x]&&m[y+1][x]<='9')p1=dfs(y+1,x,"");
  p1=m[y][x]+p1;
  if(x+1<w&&'0'<=m[y][x+1]&&m[y][x+1]<='9')p2=dfs(y,x+1,"");
  p2=m[y][x]+p2;
  if(p1.size()>p2.size())return dp[y][x]=p1;
  else if(p1.size()==p2.size()&&p1>p2)return dp[y][x]=p1;
  else return dp[y][x]=p2;
}
int main(){
  while(cin>>w>>h,w){
    r(i,h)r(j,w)dp[i][j]="";
    string p="";
    r(i,h)cin>>m[i];
    r(i,h)r(j,w)if('1'<=m[i][j]&&m[i][j]<='9'){
      string q="";
      string t=dfs(i,j,q+m[i][j]);
      if(t.size()>p.size())p=t;
      else if(t.size()==p.size())p=max(t,p);
    }
    cout<<p<<endl;
  }
}

Measured memory_bytes: 3212
#include <iostream>

using namespace std;

int main(){
	
	int x,y;

	while(1){
		cin>>x>>y;

		if(x==0&&y==0)break;
		if(x>y){
			swap(x,y);
		}
		cout<<x<<" "<<y<<endl;
	}
	return 0;
}

Measured memory_bytes: 3012
#include<bits/stdc++.h>
#define rep(i, n) for(int (i)=0 ;i <(n); ++(i))
#define REP(i,m,n) for(int (i) = (m); (i) <= (n); ++(i))
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)? "YES":"NO")
typedef long long ll;
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<string> w(n);
  rep(i, n) cin >> w[i];

  bool ans = true;

  unordered_map<string, int> mp;
  rep(i, n) {
    mp[w[i]]++;
  }
  
  for(auto p : mp) {
    if(p.second >= 2) ans = false;
  }

  for(int i = 0; i < n -1; i++) {
    int k = w[i].size();
    if(w[i][k-1] != w[i+1][0]) ans = false;
  }

  yorn(ans);
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#define maxn 55
int n,x,a[maxn],s[maxn];
long long ans,f[maxn][maxn][maxn*maxn];
int main()
{
	scanf("%d%d",&n,&x);
	for(int i=1;i<=n;i++) 
	{
		scanf("%d",&a[i]);
		s[i]=s[i-1]+a[i];
	}
	f[0][0][0]=1ll;
	for(int i=1;i<=n;i++)
		for(int j=0;j<=i;j++)
			for(int k=0;k<=s[i];k++)
			{
				f[i][j][k]=f[i-1][j][k];
				if(j&&k>=a[i]) f[i][j][k]+=1ll*f[i-1][j-1][k-a[i]];
			}
	for(int j=1;j<=n;j++)
		for(int k=0;k<=s[n];k++)
			if(j*x==k) ans+=1ll*f[n][j][k];
	printf("%lld\n",ans);
}

Measured memory_bytes: 65664
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 1000001;

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
} 

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	int n, m;
	set<ll> sol;
	map<ll,ll> p;
	ll numAc = 0;
	ll pen = 0;
	cin >> n >> m;
	for(int i =0; i < m; ++i)
	{
		ll x;
		string res;
		cin >> x >> res;
		if(res == "AC")
		{
			if(sol.count(x) == 0){
				sol.insert(x);
				numAc++;
				pen+=p[x];
			}
		}
		else
		{
			if(sol.count(x) == 0)
			{
				p[x]++;
			}
		}
		
		
		
	}
	cout << numAc << " " << pen;

    return 0;
}

Measured memory_bytes: 11264
package main

import "fmt"

func main() {
	var a, b, ans int
	fmt.Scan(&a, &b)
	
	
	if (a + b) % 2 == 0 {
		ans =  (a + b) / 2 
		fmt.Printf("%d",ans)
	} else {
		fmt.Printf("%s","IMPOSSIBLE")
	}
} 

Measured memory_bytes: 512
import numpy as np
N, K = map(int, input().split())
ans = []
for i in range(N):
	pt = i + 1
	p = 1.
	while pt <= K - 1:
		pt = 2 * pt
		p = p / 2.
	ans.append(p)
ans1 = np.sum(ans) * 1. / N
print(ans1)


Measured memory_bytes: 21628
import java.util.*;

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

	int n = sc.nextInt();
	int[] team = new int[n];

	int num = n*(n-1)/2;
	for(int i=0; i<num; i++){
	    int a = sc.nextInt()-1;
	    int b = sc.nextInt()-1;
	    int scoreA = sc.nextInt();
	    int scoreB = sc.nextInt();

	    if(scoreA>scoreB){
		team[a] += 3;
	    }else if(scoreA<scoreB){
		team[b] += 3;
	    }else {
		team[a]++;
		team[b]++;
	    }
	}
	
	int[] rank = new int[n];
	int max = 0;
	int maxIndex = 0;	
	int ranking = 1;
	int lastmax = 0;
	int count = 0;
	for(int j=0; j<n; j++){
	    count++;
	    lastmax = max;
	    max = 0;
	    for(int i=0; i<n; i++){
		if(max<team[i]){max = team[i]; maxIndex = i;}
	    }
	    if(lastmax!=max)ranking = count;
	    rank[maxIndex] = ranking;
	    team[maxIndex] = -1;
	}
	for(int i=0; i<n; i++){
	    System.out.println(rank[i]);
	}
    }
}

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

int main() {
	ll n;
	cin>>n;
	ll a[n];
	for(ll i=0;i<n;i++)
	{
	    cin>>a[i];
	}
	ll dp[n+1];
	dp[0]=0,dp[1]=0,dp[2]=abs(a[1]-a[0]);
	for(ll i=3;i<=n;i++)
	{
	    dp[i]=min(dp[i-1]+abs(a[i-1]-a[i-2]) , dp[i-2]+abs(a[i-1]-a[i-3]));
	}
	cout<<dp[n];
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(){
  string s,t;
  cin>>s>>t;
  for(int i=0;i<t.size();i++)
    cout<<s[i]<<t[i];
  if(s.size()>t.size())
    cout<<s[s.size()-1];
  cout<<endl;
  return 0;
  }

  

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#include <cassert>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define Cout(x) cout << x << endl;
#define check(v) rep(i,v.size()) cout << v[i] << endl;
#define vint(x) vector<int> x
#define vll(x) vector<long long> x
#define vstr(x) vector<string> x
const long long LLINF = 1LL<<60;
const int INF = 1e9;
const long long MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
#define pint pair<int,int>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

map<int,int> m;
void factorize(int n) {
    for(int i = 2; i*i <= n; ++i) {
        if(n%i) continue;
        int cnt = 0;
        while(n%i == 0) {
            n/=i;
            cnt++;
        }
        m[i] = max(m[i],cnt);
    }
    if(n!=1) m[n] = max(m[n],1);
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    vector<int> v(n);
    rep(i,n) {
        cin >> v[i];
        factorize(v[i]);
    }

    ll lcm = 1;
    for (auto val : m) {
        rep(i,val.second) {
            lcm *= val.first;
            lcm %= MOD;
        }
    }

    ll ans = 0;
    rep(i,n) {
        ans += lcm* modinv(v[i],MOD) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;



    return 0;
}

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

int n;
set<string> s;

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

  cin >> n;
  for(int i = 0; i < n; i++) {
    string a;
    cin >> a;
    s.insert(a);
  }

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

Measured memory_bytes: 19244
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        List<Integer> list = new ArrayList<>();
        scanner.nextLine();
        for (int i = 0; i < n; i++) {
            list.add(scanner.nextInt());
        }
        if (k >= n) {
            System.out.println(0);
        } else {
            List<Integer> subList = list.stream().sorted(Comparator.comparingInt(m -> m)).collect(Collectors.toList()).subList(0, n - k);
            System.out.println(subList.stream().mapToLong(m -> m).sum());
        }
    }
}


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

int main() {
  int N;
  int A[210];
  cin >> N;
  for (int i = 0; i < N; i++) cin >> A[i];
  
  int count = 0;
    
  while (true) {
    bool exist_odd = false;

    for (int i = 0; i < N; i++) {
      if (A[i] % 2 == 1) {
        exist_odd = true;
      }
    }
    
    if (exist_odd) break;

    for (int i = 0; i < N; i++) {
      A[i] /= 2; 
    }
    count++;  
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main(){
  int n, t, a = 0; scanf("%d %d", &n, &t);
  vector<pii> v(n); rep(i, n) scanf("%d %d", &v[i].fi, &v[i].se);
  v2i dp1(n, v1i(t, 0)), dp2(n, v1i(t, 0));
  rep(i, n-1){
    rep(j, t-1){
      if(j < v[i].fi) dp1[i+1][j] = dp1[i][j];
      else dp1[i+1][j] = max(dp1[i][j], dp1[i][j-v[i].fi]+v[i].se);
    }
  }
  rrep(i, n-1){
    rep(j, t-1){
      if(j < v[i+1].fi) dp2[i][j] = dp2[i+1][j];
      else dp2[i][j] = max(dp2[i+1][j], dp2[i+1][j-v[i+1].fi]+v[i+1].se);
    }
  }
  rep(i, n) rep(j, t) a = max(a, dp1[i][j]+dp2[i][t-j-1]+v[i].se);
  printf("%d\n", a);
  return 0;
}

Measured memory_bytes: 70784
#import<bits/stdc++.h>
#define sorted(vector) sort(vector.begin(),vector.end())
#define append(a) push_back(a)
#define int(a) stoi(a)
#define str(a) to_string(a)
using namespace std;

int main(void){
    int n,m;
    string t;
    cin>>n>>m;
    vector<string> a;
    for(int i=0  ;i<n  ;i++){
        cin>>t;
        a.append(t);
    }
    sorted(a);
    for(int i=0  ;i<n  ;i++){
        cout<<a[i];
    }
}

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

int main(){
    string s;
    cin >> s;
    vector<int> L, R;
    vector<int> ans(s.size(), 0);
    rep(i, s.size()-1){
        if(s[i] == 'R' && s[i+1] == 'L'){
            L.push_back(i+1);
            R.push_back(i);
        }
    }

    rep(i, s.size()){
        if(s[i] == 'R'){
            int r = lower_bound(R.begin(), R.end(), i) - R.begin();
            int index = R[r];
            if(r == R.size()) index = R[R.size()-1];
            int dis = index - i;
            if(dis % 2 == 0) ans[index]++;
            else ans[index+1]++;
        } else {
            int l = upper_bound(L.begin(), L.end(), i) - L.begin();
            int index = L[l-1];
            if(l == L.size()) index = L[L.size()-1];
            else if (l == 0) index = L[0];
            int dis = i - index;
            if(dis % 2 == 0) ans[index]++;
            else ans[index-1]++;
        }
    }
    
    rep(i, s.size()-1) cout << ans[i] << " ";
    cout << ans[s.size()-1] << endl;
    return 0;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

//-----------------------------------------------------------------------------

int n,odd,even;

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

	cin>>n;
	REP(i,n) {
		int a;cin>>a;
		if(a&1) odd++;
		else even++;
	}
	if(odd%2==0) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int N;
    while(cin >> N){
        bool win = false;
        for(int i=0;i<N;i++){
            int a; cin >> a;
            if(a%2) win = true;
        }
        cout << (win ? "first" : "second") << endl;
    }
}

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

int main()
{
  int64_t A, B, C, K, sum = 0;
  cin >> A >> B >> C >> K;
  if (K <= A)
  {
    cout << K << endl;
  }
  else if (K <= A + B)
  {
    cout << A << endl;
  }
  else
  {
    cout << A - (K - A - B) << endl;
  }
}

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

using namespace std;

int arr[12][12];

int main() {
    int n, d;
    scanf("%d %d", &n, &d);

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
            scanf("%d", &arr[i][j]);
        }
    }

    int ans = 0;

    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            int hehe = 0;
            for (int k = 0; k < d; k++) {
                hehe += (arr[i][k] - arr[j][k]) * (arr[i][k] - arr[j][k]);
            }
            int akar = sqrt(hehe);

            if (akar * akar == hehe) ans++;
        }
    }

    printf("%d\n", ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MAX 1000004
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
#define fin ios_base::sync_with_stdio(false); cin.tie(NULL);
int main()
{fin;

  ll n,i,W,j,k,s=0;
  cin>>n>>W;
  ll w[n];
  ll c[n];
  for(i=0;i<n;i++)
  {
    cin>>w[i]>>c[i];
    s+=c[i];
  }
  ll dp[s+1][n];
  for(i=0;i<=s;i++)
  {
    for(j=0;j<n;j++)
      dp[i][j]=INT_MAX;
  }
  for(j=0;j<n;j++)
  {
    dp[c[j]][j]=w[j];
  }
  for(i=1;i<=s;i++)
  {
    for(j=0;j<n;j++)
    {
      if(c[j]<i)
      {
        for(k=0;k<j;k++)
        {
          dp[i][j]=min(dp[i][j],dp[i-c[j]][k]);
        }
        dp[i][j]+=w[j];
      }
    }
  }
  ll ans=-1;
  for(i=0;i<=s;i++)
  {
    for(j=0;j<n;j++)
    {
      if(dp[i][j]<=W)
        ans=max(i,ans);
    }
  }
  cout<<ans;
}


Measured memory_bytes: 78336
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int N; std::cin >> N;
  std::vector<int> A(N), B(N);
  for (int i = 0; i <= N; ++i) std::cin >> A[i];
  for (int i = 0; i < N; ++i) std::cin >> B[i];

  LL sum = std::min(A[0], B[0]);
  B[0] -= sum;
  for (int i = 1; i < N; ++i) {
    LL c1 = std::min(A[i], B[i-1]);
    sum += c1;
    A[i] -= c1;

    LL c2 = std::min(A[i], B[i]);
    sum += c2;
    B[i] -= c2;
  }
  sum += std::min(A[N], B[N-1]);
  std::cout << sum << std::endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define RS resize
#define CLR clear
#define PB push_back
#define ALL(x) (x).begin(), (x).end()
#define LLI long long int
using namespace std;

void split(string str, char delim, vector< string > *elem){
  stringstream ss(str);
  string temp;
  while(getline(ss, temp, delim)) (*elem).PB(temp);
}

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

  int n;
  cin >> n;

  vector<LLI> a(n), s(n+1);
  REP(i, n) cin >> a[i];
  FORE(i, 1, n) s[i] = s[i-1] + a[i-1];

  auto aux1 = [&](int m, LLI x){return s[m]<=x-s[m];};
  auto aux2 = [&](int m, LLI x, LLI y){return s[m]-y<=x-s[m];};

  LLI m = 1000000000;

  FORE(b, 2, n-2){

    int l = 1, r = b;
    int a;

    while(1){
      if(l == r){ a = l; break; }
      else if(l+1 == r){ a = aux1(r,s[b]) ? r : l; break; }
      else{
	a = (l+r)/2;
	if(aux1(a,s[b])) l = a;
	else r = a;
      }
    }

    if(a<b-1) if(abs(2*s[a]-s[b]) > abs(2*s[a+1]-s[b])) ++a;

    l = b+1;
    r = n;
    int c;

    while(1){
      if(l == r){ c = l; break; }
      else if(l+1 == r){ c = aux2(r,s[n],s[b]) ? r : l; break; }
      else{
	c = (l+r)/2;
	if(aux2(c,s[n],s[b])) l = c;
	else r = c;
      }
    }

    if(c<n-1) if(abs(2*s[c]-s[b]-s[n]) > abs(2*s[c+1]-s[b]-s[n])) ++c;

    m = min(m, max({s[a], s[b]-s[a], s[c]-s[b], s[n]-s[c]}) - min({s[a], s[b]-s[a], s[c]-s[b], s[n]-s[c]}));    
  }

  cout << m << endl;
	
  return 0;
}


Measured memory_bytes: 3456
input = gets.chomp.split(" ")
K = input[0].to_i
S = input[1].to_i

X = Y = (0..K).to_a
c = 0 

X.each do |tx|
    s1 = S-tx
    if s1 > (2*K) then next end
    Y.each do |ty|
        s2 = s1 - ty
        if (s2 > K || s2 < 0) then next end
        c += 1
    end
end

puts c

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 1000005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

LL dp[SIZE][2];

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

    string t;
    cin >> t;
    string s = "0";
    s += t;

    dp[0][0] = 1;
    for(int i = 1; i < s.size(); ++i) {
        int dig = s[i] - '0';
        dp[i][1] = min(dp[i - 1][1] + dig, dp[i - 1][0] + (10 - dig));
        dp[i][0] = min(dp[i - 1][1] + dig + 1, dp[i - 1][0] + (9 - dig));

    }
    cout << dp[s.size() - 1][1] << endl;
    return 0;
}



Measured memory_bytes: 17948
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
#define all(a) (a).begin(),(a).end()
#define overload4(_1, _2, _3, _4, 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 rep4(i,a,b,c) for(ll i = (a);i < (b);i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i = (n)-1;i >= 0;i--)
#define rrep2(i,n) for(ll i = (n)-1;i >= 0;i--)
#define rrep3(i,a,b) for(ll i = (a)-1;i >= (b);i--)
#define rrep4(i,a,b,c) for(ll i = (a)-1;i >= (b);i -= (c))
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define SHOW(x) cout << #x << ": " << x << endl;
template<class T> ll sumArr(const T& a){ return accumulate(all(a), 0LL);}
template<class T> auto minArr(const T& a){ return *min_element(all(a));}
template<class T> auto maxArr(const T& a){ return *max_element(all(a));}
template<class T> void DEBUG_PRINT(T tmp){cout<<tmp<<endl;}
template<class T1,class... T2> void DEBUG_PRINT(T1 tmp,T2... tmp2){cout<<tmp<<" ";DEBUG_PRINT(tmp2...);}
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;

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

    int a,b,c,d;
    cin>>a>>b>>c>>d;

    while(true){
        c -= b;
        if(c <= 0)break;
        a -= d;
        if(a <= 0)break;
    }
    if(a > 0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;


    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <array>
#include <map>
using namespace std;

int main()
{
    int num;
    cin >> num;
    int sum = 0;

    array<int,110> t;
    for(int i=0;i<num;i++){
        cin >> t[i];
        sum += t[i];
    }

    int drink;
    cin >> drink;

    array<pair<int,int>,110> d;
    for(int i=0;i<drink;i++){
        cin >> d[i].first >> d[i].second;
    }

    for(int i=0;i<drink;i++){
        cout << sum - t[d[i].first-1] + d[i].second << endl;
    }

    return 0;
}

Measured memory_bytes: 256
using System;

namespace ITP_5_D
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            int n = int.Parse(str);

            for (int i = 1; i <= n; ++i)
            {
                int x = i;

                if (x % 3 == 0)
                    Console.Write(" {0}", i);
                else
                {
                    while (x > 0)
                    {
                        if (x % 10 == 3)
                        {
                            Console.Write(" {0}", i);
                            break;
                        }
                        else
                            x /= 10;
                    }
                }
            }
            Console.Write("\n");
        }
    }
}

Measured memory_bytes: 5772
#include <bits/stdc++.h>
#include <time.h>
#define first fi
#define second se


using namespace std;

typedef long long ll;
typedef double db;
int xx[4] = {1,-1,0,0};
int yy[4] = {0,0,1,-1};
const double eps = 1e-9;
typedef pair<int,int>  P;
const int maxn = 2e6 + 5000;
const ll mod = 1e9 + 7;
inline int sign(db a) {
    return a < -eps ? -1 : a > eps;
}
inline int cmp(db a,db b) {
    return sign(a - b);
}
ll mul(ll a,ll b,ll c) {
    ll res = 1;
    while(b) {
        if(b & 1) res *= a,res %= c;
        a *= a,a %= c,b >>= 1;
    }
    return res;
}
ll phi(ll x) {
    ll res = x;
    for(ll i = 2; i * i <= x; i++) {
        if(x % i == 0) res = x / i * (i - 1);
        while(x % i == 0) x /= i;
    }
    if(x > 1) res = res / x  * (x - 1);
    return res;
}
ll c,n,k;
string str;
int main() {
    ios::sync_with_stdio(false);
    ll a,b;
    while(cin >> str) {
        int len = str.size();
        stack<char>s;
        s.push(str[0]);
        int ans = 0;
        for(int i = 1; i < len; i++) {
//            cout << "s" << endl;
            if(!s.empty()) {
                if(s.top() != str[i]) s.pop(),ans++;
                else s.push(str[i]);
            } else s.push(str[i]);
        }
        cout << ans * 2 << endl;
    }
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}



Measured memory_bytes: 512
using System;
 
class program
{
    public static void Main()
    {
        int[] hist = new int[26];
 
        string str;
 
        while (true)
        {
            str = Console.ReadLine();
 
            if (str == null) break;
 
            str = str.ToLower();
 
            foreach (char s in str)
            {
                if (s >= 'a' && s <= 'z')
                {
                    hist[s - 97]++;
                }
            }
        }
 
        for (var i = 0; i <= 25; i++)
        {
            Console.WriteLine("{0} : {1}", (char)(i + 97), hist[i]);
        }
    }
}

Measured memory_bytes: 5624
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

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

int n;
vector<int> h;

ll dp[100100];

int main(){
  cin >> n;
  h.resize(n);
  
  rep(i,n){
    cin >> h[i];
  }
  rep(i,100100){
    dp[i] = 1e9;
  }
  dp[0] = 0;
  
  for(int i=0; i<n; i++){
    chmin(dp[i+1], dp[i] + abs(h[i+1]-h[i]));
    chmin(dp[i+2], dp[i] + abs(h[i+2]-h[i]));
  }
  
  dunk(dp[n-1]);
}

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

using namespace std;
typedef long long ll;

#define LOOP(i, a, n) for (int i = (int)a; i < (int)n; ++i)
#define REP(i, n) LOOP(i, 0, n)
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359
#define MAX_W 50
#define MAX_H 50

int dx[8] = {0, 0, -1, 1, 1, 1, -1, -1}, dy[8] = {-1, 1, 0, 0, -1, 1, -1, 1}, board[MAX_H][MAX_W], w, h;

void dfs(int x, int y) {
  board[y][x] = 0;

  for (int i = 0; i < 8; i++) {
    int nextx = x + dx[i], nexty = y + dy[i];
    if (nextx >= 0 && nextx < w && nexty >= 0 && nexty < h && board[nexty][nextx] == 1) {
      dfs(nextx, nexty);
    }
  }

  return;
}

int main(void) {
  vector<int> ans;

  while (true) {
    cin >> w >> h;
    if (w == 0 && h == 0) {
      break;
    }
    fill(board[0], board[49], 0);
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> board[i][j];
        //cout << "i:" << i << " j:" << j << endl;
      }
    }

    int res = 0;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if (board[i][j] == 1) {
          dfs(j, i);
          res++;
        }
      }
    }

    ans.push_back(res);
  }

  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << endl;
  }
  return 0;
}

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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	ll n, maxw, v, w;
	cin >> n >> maxw;
	vector<pair<ll, ll>> item;
	vector<vector<ll>> dp(n + 1, vector<ll>(maxw + 1, 0));

	for(ll i = 0; i < n; i++)
	{
		cin >> w >> v;
		item.push_back(make_pair(w, v));
	}
//	sort(item.begin(), item.end()); //sort by first element

//	for(ll i = 0; i < n; i++)
//	{
//		cout << item[i].first << " " << item[i].second << "\n";
//	}
	
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j <= maxw; j++)
		{
			if(i == 0 && j == 0)
				continue;
			else if(i == 0)
			{
				if(item[i].first <= j)
					dp[i][j] = item[i].second;
				else
					dp[i][j] = dp[i][j - 1];
				continue;
			}
			
			if(j < item[i].first)
			{
				dp[i][j] = dp[i - 1][j];
				continue;
			}
			dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - item[i].first] + item[i].second);
		}
	}
	
//	for(int i = 0; i < n; i++)
//	{
//		for(int j = 0; j <= maxw; j++)
//		{
//			cout << dp[i][j] << " ";
//		}
//		cout << "\n";
//	}

	cout << dp[n - 1][maxw] << "\n";
	return 0;
}

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

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

    double n, m;
    cin >> n >> m;
    vector<double> A(n);
    double t = 0;
    for(double i = 0; i < n; i++){
        cin >> A[i];
        t += A[i];
    }

    int c = 0;
    for(double i = 0; i < n; i++){
        if(A[i] < t / (4 * m));
        else c++;
    }

    if(c >= (int)m){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<deque>
#include<functional>

using namespace std;

int main(void){
	int hill;

	deque<int> nums;

	for(int i=0; i<10; i++){
		cin >> hill;
		nums.push_back(hill);
	}

	sort(nums.begin(), nums.end(),greater<int>());

	for(int j=0; j<3; j++){
		cout << nums[j] << endl;
	}

	return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)

#define sim template<class n
sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif 

#define I(x) #x " =", (x), " "
#define A(a, i) #a "[" #i " =", i, "] =", a[i], " "

pair<LD, LD> on_circle(LD part)
  {
  assert(part >= 0);
  assert(part <= 1);
  return {cos(part * M_PI * 2), sin(part * M_PI * 2)}; 
  }
LD kwa(LD x)
  {
  return x * x;
  }


int main()
  {
  int a, b, h, m;
  cin >> a >> b >> h >> m;

  int real_hours = 60 * h + m;
  int max_hours = 12 * 60;

  int real_min = m;
  int max_min = 60;

  auto hour = on_circle((LD)real_hours / max_hours);
  auto minut = on_circle((LD)real_min / max_min);

  hour.f *= a;
  hour.s *= a;

  minut.f *= b;
  minut.s *= b;

  printf("%.10Lf\n", sqrt(kwa(hour.f - minut.f) + kwa(hour.s - minut.s)));
  }


Measured memory_bytes: 4156
# 割り切る数は、Aの総和の約数である
# 自分自身を除く約数について大きい順にすべて試して、当てはまるものがあれば答え

# 8,20を7の倍数に近づけるとき、
# 8 -> mod 7が1であり、-1か+6で7の倍数になる
# 20 -> mod 7が6であり、-6か+1で7の倍数になる
# -1と+1をペアにすることが出来て、この操作回数1をK = 3から引くと2となり、これが偶数ならOK

import sys
readline = sys.stdin.readline

N,K = map(int,readline().split())
A = list(map(int,readline().split()))

all = sum(A)
divisors = []
for i in range(1,int(all ** 0.5) + 1):
  if all % i == 0:
    divisors.append(i)
    divisors.append(all // i)

divisors = sorted(divisors,reverse = True)

#print(divisors)

for d in divisors:
  mods = [0] * (N)
  for i in range(len(A)):
    mods[i] = A[i] % d
  mods = sorted(mods)
  #print("d",d,"mods",mods)
  mods_front = [0] * N
  mods_front[0] = mods[0]
  for i in range(1,N):
    mods_front[i] = mods_front[i - 1] + mods[i]
  mods_back = [0] * N
  mods_back[-1] = d - mods[-1]
  #print("mods_front",mods_front)
  for i in range(N - 2,-1,-1):
    mods_back[i] = mods_back[i + 1] + (d - mods[i])
  #print("mods_back",mods_back)
  for i in range(N - 1):
    if mods_front[i] == mods_back[i + 1]:
      if K >= min(mods_front[i],mods_back[i + 1]):
        print(d)
        exit(0)
else:
  print(1)

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

key = 'Hoshino'

for i in range(n):
    line = input()

    while (1):
        key_pos = line.find(key)
        
        if key_pos != -1:
            line = line[:key_pos] + 'Hoshina' + line[key_pos + len('Hoshina'):]
        else:
            break
    
    print(line)



Measured memory_bytes: 5592
n, k = map(int, input().split())
s = input()
ans = ""
for i in range(n):
    if i == k-1:
        if s[i] == "A": ans+="a"
        elif s[i] == "B": ans+="b"
        else: ans+="c"
    else:
        ans += s[i]
print(ans)

Measured memory_bytes: 3060
#include<cstdio>
#include<map>
#include<cstdlib>
using namespace std;
const int n = 500;
int a[512][512];
int main()
{
	int k;
	scanf("%d", &k);
	if (k <= n)
	{
		printf("%d\n", k);
		for (int i = 1; i <= k; i++)
			for (int j = 1; j <= k; j++)
				printf("%d%c", i, j == k ? '\n' : ' ');
	}
	else
	{
		printf("%d\n", n);
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				a[j][(i + j) % n] = i + 1;
		for (int i = 0; i < k - n; i++)
			for (int j = 0; j < n; j += 2)
				a[j][(i + j) % n] += n;
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				printf("%d%c", a[i][j], j == n-1 ? '\n' : ' ');
	}
	return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

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

  ll ans = 0;
  ll tmp = 1;
  for (ll i = 0; i < N; i++)
  {
    if (A.at(i) == tmp)
      tmp++;
    else
      ans++;
  }
  cout << ((ans == N) ? -1 : ans) << endl;
}

Measured memory_bytes: 1792
while True:
    number=int(input())
    if number==0000:
            break
    trial=0
    while True:
        if number==6174:
            print(trial)
            break
        box=[]
        for i in range(4):
            a=number%10
            number=int(number/10)
            box.append(a)
        if box[0]==box[1] and box[2]==box[3] and box[1]==box[2]:
            print("NA")
            break
        box.sort()
        l=0
        
        for i in range(4):
            l+=box[i]*10**i
        box.sort(reverse=True)
        s=0
        for i in range(4):
            s+=box[i]*10**i
        number=l-s
        trial+=1


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

using namespace std;

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

    int n;
    cin >> n;

    if(n % 2 == 0) {
        cout << fixed << setprecision (10) << ((double)(n / 2) / n) << endl;
    } else {
        cout << fixed << setprecision (10) << ((double)((n + 1) / 2 ) / n) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  set<int> s;
  int x;
  cin >> x;
  int ans = 1;
  rep2(i, 2, x+1){
    int add = i * i;
    while(add <= x){
      ans = max(ans, add);
      add *= i;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using namespace std;

int main() {
    int N, K, ans = 1;
    cin >> N>>K;
    for (int i = 0; i < N; i++) {
        if (2 * ans <= ans + K)ans *= 2;
        else ans += K;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
package main
import (
  "fmt"
)
func main() {
  var n int
  fmt.Scan(&n)
  cs := make([]int, n-1)
  ss := make([]int, n-1)
  fs := make([]int, n-1)
  for i := 0; i < n-1; i++ {
    fmt.Scan(&cs[i], &ss[i], &fs[i])
  }
  for i := 0; i < n-1; i++ {
    x := 0
    for j := i; j < n-1; j++ {
      if j == i {
        x += ss[j] + cs[j]
        continue
      }
      var waitingTime int
      if x < ss[j] {
        waitingTime = ss[j] - x
      } else {
        waitingTime = (fs[j] - (x%fs[j]))%fs[j]
      }
      
      x += waitingTime + cs[j]
    }
    fmt.Println(x)
  }
  fmt.Println(0)
}

Measured memory_bytes: 512
import math

A,B,N = map(int,input().split())

if N >= B - 1:
    x = B - 1
else:
    x = N

ans = math.floor(A*x / B) - A * math.floor(x/B)

# ans = int((A*(x%B)-A*(x%B)%B)/B)

print(ans)

Measured memory_bytes: 9168
#include <stdio.h>

int main(){

  int S,h,m,s,w;

  scanf("%d",&S);
  s=S%60;
  m=S/60;
  if(m>=60)
    h=m/60;
    m=m%60;
  printf("%d:%d:%d\n",h,m,s);
  return 0;
}

Measured memory_bytes: 1820
S=input()
flag=False

if S[0]=="A":
  if S[2:-1].count("C")==1:
    pos=S.find("C")
    T=S[1:pos]+S[pos+1:]
    if T.islower():
      print("AC")
      flag=True
      
if flag==False:
  print("WA")

Measured memory_bytes: 3060
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int t = sc.nextInt();
		
		int[] x = new int[n];
		long sum = 0;
		
		for(int i = 0; i<x.length; i++) {
			x[i] =sc.nextInt();
			
			if(i != 0) {
				if(x[i]-x[i-1] > t) {
					sum += t;
				}else{
					sum += x[i] - x[i-1];
				}
			}	
		}
		
		sum += t;
		
		System.out.println(sum);
		
		
		sc.close();

	}

}

Measured memory_bytes: 62656
X=int(input())

#引数nが素数かどうかを判定
def is_prime(n):
    for i in range(2, n + 1):
        if i * i > n:
            break
        if n % i == 0:
            return False
    return n != 1
import sys
for i in range(X,X+10**5):
    if is_prime(i):
        print(i)
        sys.exit()



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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

vector<int> h;

int main() {
    int N, K;
    cin >> N >> K;
    h = vector<int>(N);
    rep(i, N) cin >> h[i];

    // もらうDP
    vector<int> mi(N, INF);
    mi[0] = 0;
    for (int i = 1; i < N; i++) {
        for (int k = 1; k <= K and 0 <= i - k; k++) {
            mi[i] = min(mi[i], mi[i - k] + abs(h[i] - h[i - k]));
        }
    }
    // cout << mi[N - 1] << endl;

    // 配るDP
    vector<int> mii(N + 100, INF);
    mii[0] = 0;
    for (int i = 0; i < N; i++) {
        for (int k = 1; k <= K; k++) {
            mii[i + k] = min(mii[i + k], mii[i] + abs(h[i] - h[i + k]));
        }
    }
    cout << mii[N - 1] << endl;
    // dump(mii);
    return 0;
}

Measured memory_bytes: 4244
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<(b)?(a=b,1):0)
#define chmin(a,b) (a>(b)?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
const int INF = 1<<29;
const double EPS = 1e-8;
const double PI = acos(-1);
typedef pair<int,int> pii;
typedef long long ll;

char a[5][5][5];
char b[5][5][5];

int A[27];
int B[27];
int main() {
  int n;
  while(cin >> n, n) {
    REP(z,5) REP(y,5) REP(x,5)
      cin >> a[z][y][x];
    REP(i,27)A[i]=B[i]=0;
    int m1; cin >> m1;
    REP(i,m1) {
      int x; cin >> x;
      A[x] = 1;
    }
    int m2; cin >> m2;
    REP(i,m2) {
      int x; cin >> x;
      B[x] = 1;
    }
    while(n--) {
      memcpy(b,a,sizeof(a));
      REP(z,5) REP(y,5) REP(x,5) {
        int cnt = 0;
        for (int zz=z-1;zz<=z+1; ++zz) {
          for (int yy=y-1;yy<=y+1; ++yy) {
            for (int xx=x-1;xx<=x+1; ++xx) {
              if (valid(yy,xx,5,5) && valid(zz,yy,5,5)) {
                if (zz==z&&yy==y&&xx==x) continue;
                if (b[zz][yy][xx]=='1') cnt++;
              }
            }
          }
        }
        if (a[z][y][x]=='1') {
          if (!B[cnt]) a[z][y][x] = '0';
        } else {
          if (A[cnt]) a[z][y][x] = '1';
        }
      }
    }
    static int cs = 1;
    if (cs>1) cout << endl;
    printf("Case %d:", cs++);
    REP(z,5) {
      cout << endl;
      REP(y,5) {
        REP(x,5) cout << a[z][y][x];
        cout << endl;
      }
    }
  }
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, deque<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


long long solve() {
    long long N, X, M;
    cin >> N >> X >> M;

    vector<int> ord(M, -1); // かつて来た地点を求める
    vector<long long> rireki, syu;
    long long res = 0;
    for (int n = 0; n < N; ++n) {
        // かつて来た地点に戻ったら
        if (ord[X] != -1) {
            int p = ord[X];
            for (long long i = p; i < n; ++i) syu.push_back(rireki[i]);
            break;
        }
        ord[X] = n;
        rireki.push_back(X);
        res += X;
        X = (X * X) % M;
    }
    N -= rireki.size();

    // 戻る前に N 項目に到達した場合
    if (N == 0) return res;

    // 周期の累積和をとる
    vector<long long> sum(syu.size() + 1, 0);
    for (int i = 0; i < syu.size(); ++i) sum[i+1] = sum[i] + syu[i];

    // 周期を q 週して r あまる
    long long q = N / syu.size();
    long long r = N % syu.size();
    res += sum[syu.size()] * q + sum[r];
    return res;
}

int main() {
    cout << solve() << endl;
}

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

int main() {
    for (;;) {
        string str;
        getline(cin, str);

        if (str == "0") break;

        int tmp = 0;
        for (string::iterator it = str.begin(); it != str.end(); ++it) {
            if (0x30 <= *it && *it <= 0x39) {
                tmp += int(*it) - 0x30;
            } else {
                cout << "?";
            }
        }
        cout << tmp << endl;
    }

    return 0;
}

Measured memory_bytes: 1184
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    int sum=0;
    for(int i=0;i<n-1;i++)sum+=a[i];
    if(a[n-1]<sum)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.*;


public class Main {

	static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		int n;
		while(sc.hasNextInt()) {
			n = sc.nextInt();
			int[][] pair = new int[n][2];
			for(int i = 0; i < n; i++) {
				pair[i][0] = sc.nextInt();
				pair[i][1] = sc.nextInt();
			}
			
			BigInteger lcm1 = new BigInteger("1");
			for(int i= 0; i < n; i++) 
				lcm1 = lcm(lcm1, new BigInteger(Integer.toString(pair[i][1])));
			
			
			BigInteger[] t = new BigInteger[n];
			BigInteger lcm2 = new BigInteger("1");
			for(int i = 0; i < n; i++) {
				t[i] = new BigInteger(Integer.toString(pair[i][0])).multiply(lcm1).divide(new BigInteger(Integer.toString(pair[i][1])));
				lcm2 = lcm(lcm2, t[i]);
			}

			for(int i = 0; i < n; i++) 
				System.out.println(lcm2.divide(t[i]));
		}
	}
	
	static BigInteger lcm(BigInteger x, BigInteger y) {
		if(x.compareTo(y) >= 1) {
			BigInteger tmp = y;
			y = x;
			x = tmp;
		}
		
		return (x.multiply(y)).divide(x.gcd(y));
	}
}

Measured memory_bytes: 13000