akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
long long gcd(long long a,long long b){if(a%b==0){return b;}else return gcd(b,a%b);}
long long lcm(long long a,long long b){if(a==0){return b;} return a/gcd(a,b)*b;}
#define MOD 1000000007
#define sym cout<<"---------"<<endl;
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl
#define WHITE 1
#define BLACK 2
#define GRAY 1
#define RE return 0
#define int ll

int n;
P p[105];
int height[105];
bool ok(int i,int j,int h){
  int m=0;
  for(int k=0; k<n; k++){
    if(height[k]!=max(h-abs(p[k].first-i)-abs(p[k].second-j),m)) return false;
  }
  return true;
}

// C
signed main(){
  cin>>n;
  for(int i=0; i<n; i++){
    int a,b,c; cin>>a>>b>>c;
    p[i].first=a; p[i].second=b; height[i]=c;
  }
  
  for(int i=0; i<=100; i++){
    for(int j=0; j<=100; j++){
      set<int> s1,s2;
      for(int k=0; k<n; k++){
        int a=abs(p[k].first-i)+abs(p[k].second-j);
        if(height[k]==0){
          s1.insert(a);
        }else{
          s2.insert(a+height[k]);
        }
      }
      
      if(s2.size()>1) continue;
      if(s1.size()==0){
        if(s2.size()==1&&*s2.begin()>0&&ok(i, j, *s2.begin())){
          cout<<i<<" "<<j<<" "<<*s2.begin()<<en;
          RE;
        }
      }else if(s2.size()==1&&*s2.begin()<=*s1.begin()&&*s2.begin()>0&&ok(i, j, *s2.begin())){
        cout<<i<<" "<<j<<" "<<*s2.begin()<<en;
        RE;
      }
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;
// ------------------------------

int cnt = 0;

int func(int A, int B, int C) {
    if (A % 2 == 1 || B % 2 == 1 || C % 2 == 1) return cnt;
    if (A == B && A == C) return -1;
    cnt += 1;
    return func((A + B)/2, (B + C)/2, (C + A)/2);
}

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    cout << func(A, B, C) << endl;
    return 0;
}

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

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define pb push_back

typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

int main(){
    ll X,Y,A,B,C;
    cin>>X>>Y>>A>>B>>C;
    vl p(A),q(B),r(C);
    F0R(i,A){
        cin>>p[i];
    }
    sort(p.begin(),p.end());
    F0R(i,B){
        cin>>q[i];
    }
    sort(q.begin(),q.end());
    F0R(i,C){
        cin>>r[i];
    }
    sort(r.begin(),r.end());
    priority_queue <ll, vector<ll>, greater<ll>> pq;
    F0R(i,X){
        pq.push(p[A-1-i]);
    }
    F0R(i,Y){
        pq.push(q[B-1-i]);
    }
    ll sum=0;
    F0R(i,min(X+Y,C)){
        ll tp=pq.top();
        ll tpc=r[C-1-i];
        if(tpc>=tp){
            sum+=tpc;
            pq.pop();
        }else{
            break;
        }
    }
    while(!pq.empty()){
        sum+=pq.top();
        pq.pop();
    }
    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 4724
N=int(input())
ans=[0, 1, 2, 3, 4, 5]+[100001]*(N-5)
  
for i in range(N):
  for j in range(1, 7):
    if i+6**j<=N:
      ans[i+6**j]=min(ans[i]+1, ans[i+6**j])
      
  for j in range(1, 6):
    if i+9**j<=N:
      ans[i+9**j]=min(ans[i]+1, ans[i+9**j])
      
print(ans[N])

Measured memory_bytes: 4596
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=100010;
char s[N];
int main() {
    scanf("%s",s);
    int n=strlen(s),ans=n/2;
    for(int i=0;i<n;i++)
	if(s[i]=='p') --ans;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
void vprn(vector<ll> &v){ for(int i=0;i<v.size();i++) cout<<v[i]<<(i<v.size()-1?",\t":"\n"); }

ll solve(int N, vl &A){
	ll ans = 0;
	rp(i,0,N) ans += A[i]-1;
	return ans;
}


int main(){
	int N; cin>>N;
	vl A(N); rp(i,0,N) cin>>A[i];
	ote(solve(N,A));
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int maxn = 1e5 + 10;
int n;
long long a[maxn];
int main()
{
	cin>>n;
	long long ans = 0, mx = -1e18, mn = 1e18;
	int cnt = 0;
	for(int i = 0; i < n; i++)
	{
		cin>>a[i];
		ans += abs(a[i]);
		if(a[i] < 0)
		{
			cnt++;
			mx = max(mx, a[i]);
		}
		else
			mn = min(mn, a[i]);
	}
	cout<<ans - (cnt & 1 ? min(-mx, mn) : 0ll) * 2ll<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define REP(i,x) for(ll i=0;i<x;i++)
#define INF 1e18
typedef long long ll;
using namespace std;
#define MOD 1000000007


int main(){
  int N,M;
  cin>>N>>M;
  vector<int> c(N,-1);
  string ans="1";
  REP(i,N-1)ans+="0";
  if(M==0){
    if(N==1)cout<<0<<endl;
    else cout<<ans<<endl;
    return 0;
  }
  REP(i,M){
    int S,C;cin>>S>>C;
    if(S==1&&C==0&&N!=1){
      cout<<"-1"<<endl;
      return 0;
    }
    if(c[S-1]!=-1&&c[S-1]!=C){
      cout<<"-1"<<endl;
      return 0;
    }
    ans[S-1]='0'+C;
    c[S-1]=C;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
card = {S:(1..13).to_a, H:(1..13).to_a , C:(1..13).to_a , D:(1..13).to_a}
n.times do
    card_case, number = gets.chomp.split
    case card_case
    when "S"
        card[:S] -= [number.to_i]
    when "H"
        card[:H] -= [number.to_i]
    when "C"
        card[:C] -= [number.to_i]
    when "D"
        card[:D] -= [number.to_i]
    end
end
card[:S].each do |i|
    puts "S #{i}"
end
card[:H].each do |i|
    puts "H #{i}"
end
card[:C].each do |i|
    puts "C #{i}"
end
card[:D].each do |i|
    puts "D #{i}"
end

Measured memory_bytes: 8704
#include <iostream>
#include <string>

using std::cin;
using std::cout;
using std::endl;
using std::string;

int main() {
  string s;
  string res;

  cin >> s;
  for (char x : s) {
    if (x == '0') res.push_back('0');
    else if (x == '1') res.push_back('1');
    else if (x == 'B' && res != "") res.pop_back();
  }
  cout << res << endl;

  return 0;

}


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

#define ll long long int

map<ll,ll> mp;

ll check(ll h){
    if(h==1)
        return 1;
    else if(mp[h] != 0)
        return mp[h];
    mp[h] = check(h/2)*2+1;
    return mp[h];
}

void solve(){
    ll h;   cin >> h;
    cout << check(h) << '\n';
}

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

    int test=1;
    // cin >> test;
    while(test--)
        solve();
    
    return 0;
}

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

int main(){
  ll N, K; cin>>N>>K;
  vector<ll> X(K);
  for(ll i=0; i<K; i++) cin>>X[i];
  sort(X.begin(), X.end());
  if(N>=K) cout<<0<<endl;
  else{
    vector<ll> D(K-1);
    for(ll i=0; i<K-1; i++) D[i]=X[i+1]-X[i];
    sort(D.begin(), D.end());
    ll ans=0;
    for(ll i=0; i<K-N; i++) ans+=D[i];
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 4768
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;

int main(){
	while(true){
		int A = 0, B = 0;
		for(int g=0;g<3;g++){
			A = 0; B = 0;
			for(int i=0;;i++){
				char c; scanf("%c",&c);
				if(c=='0') return 0;
				if(i==0) continue;
				if(c=='\n'){
					if(A>B) A++;
					else B++;
					printf("%d %d\n",A,B); break;
				}
				if(c=='A') A++;
				else if(c=='B') B++;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1120
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll N;
  cin>>N;
  vector<ll> A(N);
  for(ll i=0;i<N;i++) {
cin>>A[i];
  }
  
  sort(all(A));
  cout<<A.back()-A[0]<<endl;
}

Measured memory_bytes: 3560
import sys

def input():
    return sys.stdin.readline().strip()


    
a = [[0]*3 for i in range(3)]
for i in range(3):
    a[i] = list(map(int, input().split()))
n = int(input())
b = [0]*n
bingo = "No"
for i in range(n):
    b[i] = int(input())
    for k in range(3):
        if a[k][0] == b[i]:
            a[k][0] = 0
        if a[k][1] == b[i]:
            a[k][1] = 0
        if a[k][2] == b[i]:
            a[k][2] = 0
for i in range(3):
    if a[i][0]+a[i][1]+a[i][2] == 0:
        bingo = "Yes"
for i in range(3):
    if a[0][i]+a[1][i]+a[2][i] == 0:
        bingo = "Yes"
if a[0][0]+a[1][1]+a[2][2] == 0:
    bingo = "Yes"
if a[2][0]+a[1][1]+a[0][2] == 0:
    bingo = "Yes"
 
print(bingo)



Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define pb push_back
#define pii pair<int,int>
#define int long long int
#define vec vector<int>
#define mp map<int,int>
#define inf 1e18
using namespace std;
vector<int> v;
int mod=998244353;
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int tt=1;
  //cin>>tt;
  while(tt--)
  {
    int n,k;
    cin>>n>>k;
    int l[n],r[n],i;
    for(i=0;i<k;i++)
        cin>>l[i]>>r[i];
    int a[n+1]={0};
    for(i=0;i<k;i++)
    {
      for(int j=l[i];j<=r[i];j++)
      if(!a[j])
      {
        a[j]++;
        v.pb(j);
      }
    }
    int x=v.size();
    sort(v.begin(),v.end());
    int dp[n+1]={0};
    dp[1]=1;
    for(i=2;i<=n;i++)
    {
      dp[i] = ((dp[i]%mod) + (dp[i-1]%mod))%mod;
      for(int j=0;j<k;j++)
      {
         dp[i] = ((dp[i]%mod) + ((dp[max(i-l[j],(int)0)]%mod - dp[max(i-r[j]-1,(int)0)]%mod + mod)%mod)%mod)%mod;
      }
    }
    cout<<(dp[n]-dp[n-1]+mod)%mod<<"\n";
  }
}

Measured memory_bytes: 7916
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int n,m,a,b,i,ans;
  ans=0;
  cin>>n>>m;
  pair<long long int,long long int> shop[n]={};
  for(i=0;i<n;i++){cin>>a>>b;shop[i]=make_pair(a,b);}
  sort(shop,shop+n);
  i=0;
  while(m){
    if(m>=shop[i].second){
      ans+=shop[i].first*shop[i].second;
      m-=shop[i].second;
    }else{
      ans+=m*shop[i].first;
      m=0;
    }
    i++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9+5;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,m,k,a[200005]={},b[200005]={},x[200005]={};
  cin >> n >> m >> k;
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  for(int i=0; i<m; i++) {
    cin >> b[i];
  }
  for(int i=1; i<=m; i++) {
    x[i]+=x[i-1]+b[i-1];
  }
  ll cnt=0,ans=0,y;
  y=upper_bound(x,x+m+1,k)-x-1;
  ans=y;
  for(int i=0; i<n; i++) {
    cnt+=a[i];
    if(cnt>k) {
      break;
    }
    y=upper_bound(x,x+m+1,k-cnt)-x-1; 
    ans=max(ans,i+1+y);
  }
  cout << ans << "\n";
}


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

int main(){
int N, X;  cin >> N >> X;
vector<int> m(N);
for (int i = 0; i < N; i++) {
    cin >> m[i]; 
}
int m_sum = 0;
int m_min = 1000;
for (int i = 0; i < N; i++) {
    m_sum += m[i];
    m_min = min(m_min, m[i]);
}

cout << N + (X - m_sum)/m_min << endl; 

}

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

namespace solver{
  void solve(){
    std::string S; std::cin >> S;

    int ans = 0;

    if(S == "RRR") ans = 3;
    else if(S == "RRS" or S == "SRR") ans = 2;
    else if(std::count(S.begin(), S.end(), 'R') >= 1) ans = 1;

    std::cout << ans << "\n";
  }
}

int main(){
  solver::solve();
  return 0;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int main(){
    int n; cin >> n;
    vector<int> a(n);
    int x[20][20], y[20][20];
    rep(i,n){
        cin >> a[i];
        rep(j,a[i]){
            cin >> x[i][j] >> y[i][j];
            x[i][j]--;
        } 
    }

    int ans = 0;
    FOR(i, 1, (1 << n)){
        bool flag = true;
        rep(j,n){
            if(!(i & (1 << j))) continue;
            rep(k, a[j]) if(((i >> x[j][k]) & 1) ^ y[j][k]) flag = false;
        }
        if(flag) ans = max(ans, __builtin_popcount(i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
class B
{
    static void Main(string[] args)
    {
        string[] s = Console.ReadLine().Split(' ');
        long A = long.Parse(s[0]);
        long B = long.Parse(s[1]);
        long K = long.Parse(s[2]);

        long a = ((A - K) >= 0 ) ? (A - K) : 0;
        long b = (a == 0) ? ((A + B) - K) : B;
        if (b < 0) {b = 0;}
        Console.WriteLine(a + " " + b);
    }
}

Measured memory_bytes: 11092
#include <stdio.h>
int main(){
   int n,k;
   scanf("%d%d",&n,&k);
   int h[n];
   for(int a=0;a<n;a++){
       scanf("%d",&h[a]);
   } 
   int count=0;
   for(int b=0;b<n;b++){
       if(h[b]>=k){count++;}
       else{}
   }
   printf("%d\n",count);
   return 0;
}

Measured memory_bytes: 512
N=int(input())
alist=list(map(int,input().split()))
max_a=max(alist)

exclude_set=set()
tlist=[False]*(max_a+1)
for a in alist:
  if tlist[a]:
    exclude_set.add(a)
  else:
    tlist[a]=True
#print(tlist)

for i in range(1,max_a//2+1):
  if not tlist[i]:
    continue
  else:
    for j in range(2*i,len(tlist),i):
      tlist[j]=False
      
#print(tlist)
answer=0
for i in range(len(tlist)):
  if tlist[i] and not i in exclude_set:
    answer+=1
    
print(answer)

Measured memory_bytes: 106356
#include<stdio.h>
int main()
{
  int a,j,v,N,count=0;
  int A[100];

  scanf("%d",&N);
  for(a=0;a<=N-1;a++)scanf("%d ",&A[a]);
  for(a=1 ;a<=N-1 ;a++){
    v = A[a];
    j = a-1;
    while(j >= 0 && A[j] > v){
      A[j+1] = A[j];
      j--;
      A[j+1] = v;
      count++;
    }
  }
  for(a=0 ;a<=N-2 ;a++)printf("%d ",A[a]);
  printf("%d\n",A[a]);
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2100
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<utility>
#include<set>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#define maxn 35
#define INF 0x3f3f3f3f
#define LL long long
#define ULL unsigned long long
#define E 1e-8
#define mod 1000000007
#define P pair<int,int>
using namespace std;

int main()
{
    int a,b,c;
    while(scanf("%d%d%d",&a,&b,&c)!=EOF){
        int sum = a+b+c;
        int MAX = max(max(a,b),max(b,c));
        for(int i=0;;++i){
            if((sum+2*i)%3==0&&(sum+2*i)/3>=MAX){
                printf("%d\n",i);
                break;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
#define ll long long

int main(void) {
  int n;
  cin>>n;
  if(n==5||n==7||n==3)
  printf("YES\n");
  else printf("NO\n");



	return 0;
}


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

typedef long long int ll;
ll n, a[200007];
map<ll, ll> occ;

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

    ll ans = 0;
    for(ll i = 0; i < n; ++i) {
        if(occ[i - a[i]]) ans += occ[i - a[i]];
        occ[i + a[i]]++;
    }

    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main()
{
	string S;
	cin >> S;
	sort(S.begin(), S.end());
	if (S[0] == S[1] && S[2] == S[3] && S[0] != S[2])
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
def judge(a, b):
  if a == 1:
    if b == 2:
      return 3
    else:
      return 2
  elif a == 2:
    if b == 1:
      return 3
    else:
      return 1
  else:
    if b == 1:
      return 2
    else:
      return 1

a = int(input())
b = int(input())

x = judge(a, b)

print(x)



Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int MAXN=100005;

int N;
vector<int> adj[MAXN];
int col[MAXN];

bool dfs(int u,int f)
{
    if(adj[u].size()==1U)
    {
        col[u]=0;
        return false;
    }
    int cnt[2]={0};
    for(int i=0;i<(int)adj[u].size();i++)
    {
        int v=adj[u][i];
        if(v==f)
            continue;
        if(dfs(v,u))
            return true;
        cnt[col[v]]++;
    }
    if(cnt[0]>=2)
        return true;
	if(f==0&&(int)adj[u].size()==cnt[1])
		return true;
    if(cnt[0])
        col[u]=1;
    else
        col[u]=0;
    return false;
}

int main()
{
    scanf("%d",&N);
    for(int i=1;i<N;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    if(N==2)
        puts("Second");
    else
    {
        bool ans;
        for(int i=1;i<=N;i++)
            if(adj[i].size()>1U)
            {
                ans=dfs(i,0);
                break;
            }
        puts(ans?"First":"Second");
    }

    return 0;
}


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

v=list(map(int, input().split())) 
c=list(map(int, input().split())) 
#print(v,c)

a=0
b1=0
b2=0
while a<n:
    if (v[a]-c[a])>0:
        b1+=int(v[a])
        b2+=int(c[a])
    a+=1
#    print(b1,b2)
#print(b1,b2)
print(b1-b2)


Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

template<typename T> using maximum_heap = std::priority_queue<T, std::vector<T>, std::less<T>>;
template<typename T> using minimum_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
std::istream& operator>>(std::istream &is, std::vector<T> &v)
{
  for (typename std::vector<T>::size_type i = 0; i < v.size(); ++i) {
    is >> v[i];
  }
  return is;
}

using namespace std;

const uint64_t M = 26;

// B問題を踏まえて貪欲法で解く。
// 各d日目で最もスコアが最大となるような選択を行う。
int64_t solution1(uint64_t D, const vector<int64_t> &c, const vector<vector<int64_t>> &s)
{
  int64_t S = 0;

  vector<int64_t> last(M, 0);
  N_TIMES(d, D) {
    int64_t max_T = -1e+16, max_t = -1;
    N_TIMES(t, M) {
      int64_t T = s[d][t];
      N_TIMES(m, M) {
        if (m == t) { continue; }
        T -= c[m] * ((d + 1) - last[m]);
      }

      if (max_T < T) {
        max_T = T;
        max_t = t;
      }
    }
    cout << (max_t + 1) << endl;
    last[max_t] = d + 1;
    S += max_T;
  }

  return S;
}

int main()
{
  uint64_t D;
  cin >> D;

  vector<int64_t> c(M);
  cin >> c;

  vector<vector<int64_t>> s(D, vector<int64_t>(M));
  N_TIMES(d, D) {
    cin >> s[d];
  }

  solution1(D, c, s);

  return 0;
}

Measured memory_bytes: 3720
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CStreamline solver = new CStreamline();
        solver.solve(1, in, out);
        out.close();
    }

    static class CStreamline {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // サボれる区間はn-1個

            int n = in.nextInt();
            int m = in.nextInt();
            int[] x = new int[m];
            int[] dif = new int[m - 1];

            for (int i = 0; i < m; i++) {
                x[i] = in.nextInt();
            }
            Arrays.sort(x);
            for (int i = 0; i < m - 1; i++) {
                dif[i] = x[i + 1] - x[i];
            }
            Arrays.sort(dif);

            int think = Math.max(0, m - n);
            long sum = 0;
            for (int i = 0; i < think; i++) {
                sum += dif[i];
            }
            out.println(sum);

        }

    }
}



Measured memory_bytes: 52000
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;


ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
bool root(string s){
    int n=s.length();
    if(n==2){
        if(s[0]==s[1]){
            return true;
        }
        else return false;
    }
    if(n==3){
        if(s[0]==s[2]){
            return true;
        }
        else return false;
    }
 
    return false;
}
 
 
//深さ優先
vector<int> seen;
vector<ll> h;
 
//普通の深さ優先探索seenを返す感じ
void dfs(const Graph &G,int v){
    seen[v] = 0; //v探索済み
 
    P good=make_pair(v,h[v]);
    for(auto next_v :G[v]){
        if(seen[next_v]!=-1) continue;//もう探索していた
        if(h[next_v]>good.second){
            good=make_pair(next_v,h[next_v]);
        }
        dfs(G,next_v);
    }
 
    if(!(h[v]==good.second && v==good.first)){
        seen[good.first]=1;
    }
}
 
signed main(){
    string s;
    cin>>s;

    int a=s[0]-'0';
    int b=s[1]-'0';
    int c=s[2]-'0';
    int d=s[3]-'0';

    for(int i=0;i<=1;i++){
        char op[3];
        int sum=0;
        for(int j=0;j<=1;j++){
            for(int k=0;k<=1;k++){
                if(i%2){
                    op[0]='+';
                    sum=a+b;
                }else{
                    op[0]='-';
                    sum=a-b;
                }
                if(j%2){
                    op[1]='+';
                    sum=sum+c;
                }
                else{
                    op[1]='-';
                    sum=sum-c;
                }
                if(k%2){
                    op[2]='+';
                    sum=sum+d;
                }else{
                    op[2]='-';
                    sum=sum-d;
                }

                if(sum==7){
                    cout<<a<<op[0]<<b<<op[1]<<c<<op[2]<<d<<"=7"<<endl;
                    return 0;
                }
            }
        }
    }
}   

Measured memory_bytes: 256
// AtCoder ABC112: C - Pyramid
// 2020.1.29 bal4u

#include <stdio.h>
#include <stdlib.h>

typedef struct { int x, y, h; } T;
T tbl[105]; int N;

int cmp(const void *u, const void *v) {
	return ((T *)v)->h - ((T *)u)->h;
}

int check(int x, int y, int h) {
	int i, tx, ty, th;
	for (i = 0; i < N; ++i) {
		tx = tbl[i].x - x; if (tx < 0) tx = -tx;
		ty = tbl[i].y - y; if (ty < 0) ty = -ty;
		th = h - tx - ty; if (th < 0) th = 0;
		if (th != tbl[i].h) return 0;
	}
	return 1;
}

int main()
{
	int i, cx, cy, H;
	int tx, ty;
	
	scanf("%d", &N);
	for (i = 0; i < N; ++i)
		scanf("%d%d%d", &tbl[i].x, &tbl[i].y, &tbl[i].h);
	qsort(tbl, N, sizeof(T), cmp);
	//for (i = 0; i < N; ++i) printf("[%d] %d,%d,%d\n", i, tbl[i].x,tbl[i].y,tbl[i].h);
	
	for (cx = 0; cx <= 100; ++cx) for (cy = 0; cy <= 100; ++cy) {
		H = 0;
		for (i = 0; i < N; ++i) {
			tx = tbl[i].x - cx; if (tx < 0) tx = -tx;
			ty = tbl[i].y - cy; if (ty < 0) ty = -ty;
			if (H <= 0) H = tbl[i].h + tx + ty;
			else if (H != tbl[i].h + tx + ty && tbl[i].h > 0) goto next;
		}
		if (H > 0 && check(cx, cy, H)) {
			printf("%d %d %d\n", cx, cy, H);
			return 0;
		}
	next:;
	}
	return 0;
}


Measured memory_bytes: 128
N,M=map(int,input().split())
balls=[1 for _ in range(N)]
answers=[0 for _ in range(N)]
answers[0]=1
for _ in range(M):
    x,y=map(int,input().split())
    balls[x-1]-=1
    balls[y-1]+=1
    if balls[x-1]>=1 and answers[x-1]==1:
        answers[y-1]=1
    elif balls[x-1]==0 and answers[x-1]==1:
        answers[x-1]=0
        answers[y-1]=1
print(sum(answers))


Measured memory_bytes: 79256
#include <iostream>
using namespace std;
int n, f[1100];
int main(void){
    // Your code here!
    cin >> n;
    for (int i = 2; i <= n; i++) {
        int ans = 0;
        for (int j = 2; j < i; j++) {
            if (i % j == 0) ans++;
        }
        if (ans == 0) f[i] = 1;
    }
    long long res = 1;
    for (int i = 1; i <= n; i++) {
        if (f[i] == 1) {
            int num = i, cou = 1;
            while (num <= n) {
                cou += n / num;
                num *= i;
            }
            res = res * cou % 1000000007;
        }
    }
    cout << res << endl;
}


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



int32_t main(){
        int n;cin>>n;
        vector<int>v(n);
        for(auto &i : v) cin>>i;
        vector<int> dp(n);
        dp[n-1]=0;
        dp[n-2]=abs(v[n-1]-v[n-2]);
        for(int i=n-3;i>=0;i--){
            dp[i]=min(abs(v[i+1]-v[i])+dp[i+1],abs(v[i+2]-v[i])+dp[i+2]);
        }
        cout<<dp[0]<<"\n";

    return 0;
}

Measured memory_bytes: 1792
S = input()
original_str = "keyence"
length = 7

for i in range(len(original_str)+1):
  str1 = original_str[:i]
  str2 = original_str[i:]
  if S[:len(str1)] == str1 and (S[::-1])[:len(str2)] == str2[::-1]:
    print("YES")
    exit()
    
print("NO")

Measured memory_bytes: 9116
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

vector<string> field;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int tmp_max = 0;

int main(){
  int h, w;
  cin >> h >> w;

  field.resize(h);
  for(int i = 0; i < h; ++i)cin >> field[i];

  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      if(field[i][j] == '#')continue;

      int sy, sx;
      sy = i;
      sx = j;

      vector<vector<int>> dist(h, vector<int>(w, -1)); // init
      queue<pair<int, int>> que;

      dist[sy][sx] = 0;
      que.push(make_pair(sx, sy));

      while(!que.empty()){
        pair<int, int> v = que.front();
        que.pop();

        for(int i = 0; i < 4; ++i){
          int nx = v.first + dx[i];
          int ny = v.second + dy[i];

          if(ny < 0 || ny >= h || nx < 0 || nx >= w)continue;
          if(field[ny][nx] == '#')continue;

          if(dist[ny][nx] != -1)continue;

          dist[ny][nx] = dist[v.second][v.first] + 1;
          que.push(make_pair(nx, ny));
        }
      }

      for(int k = 0; k < h; ++k){
        for(int l = 0; l < w; ++l){
          tmp_max = max(tmp_max, dist[k][l]);
        }
      }
    }
  }

  cout << tmp_max << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define radrad(a)  180.0 * a / M_PI
#define pow(x) x*x
#define ll long long
static const int MAX = 100010;
static const ll INFTY = 1e12;
static const int NUMMAX = 300;


int main(){

  int N, M;
  ll  A[MAX];
  ll mid, tmp;
  int count;
  ll ans;

  cin >> N >> M;

  REP(i, N){
    cin >> A[i];
  }
  ll left = -1, right = 1e12;

  while( right - left > 1 ){
    mid = (left + right) / 2;
    count = 0;
    
    REP(i, N){
      int j = 0;
      tmp = A[i];
      for(j = 0; tmp > mid; j++){
        tmp /= 2;
        count++;
      }
    }
    if(count > M){
      left = mid;
    } else {
      right = mid;
    }
  }
  //cout << right << endl;
   for(int i=0;i<N;i++){
    tmp=A[i];
    for(int j=0;tmp>right;j++){
      tmp/=2;
      M--;
    }
    
    ans+=tmp;
  }
  ans = ans - (right -(right/2))*M;

  cout << ans << endl;



  return 0;
}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 1024
import math
#d問をwf法で解く奴
INF=1000000000

cs=[[INF for i in range(10)]for j in range(10)]
nums=[0]*10 #各数字の個数

#cost=[[INF for i in range(10)]for j in range(10)] #cost[0][1]→0から1へのコスト


temp=list(map(int,input().split(" ")))
H=temp[0]
W=temp[1]
for i in range(10):
    temp=list(map(int,input().split(" ")))
    for j in range(10):
        cs[i][j]=temp[j] #i→jへのコスト

for i in range(H):
    temp=list(map(int,input().split(" ")))
    for j in range(W):
        if temp[j]!=-1:
            nums[temp[j]]+=1

for i in range(10): #経由するやつ
    for j in range(10): #始点
        for k in range(10): #終点
            cs[j][k]=min(cs[j][k],cs[j][i]+cs[i][k])

result=0
for i in range(10):
    result+=(nums[i]*cs[i][1])
print(result)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k=1000005;
  cin>>n;
  vector<int> a(n);
  vector<int> c(k);
  for(int i=0;i<n;i++){
    cin>>a[i];
    c[a[i]]++;
  }
  bool pairwise=true;
  for(int i=2;i<k;i++){
    int cnt=0;
    for(int j=i;j<k;j+=i){
      cnt+=c[j];
    }
    if(cnt>1) pairwise=false;
  }
  
  if(pairwise){
    cout<<"pairwise coprime"<<endl;
    return 0;
  }
  
  int g=0;
  for(int i=0;i<n;i++) g=gcd(g,a[i]);
  if(g==1){
cout<<"setwise coprime"<<endl;
    return 0;
  }
  cout<<"not coprime"<<endl;
  return 0;
}

Measured memory_bytes: 11184
require 'prime'
include Math
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

a , b ,c = gi
data = 0
jd = false
much = []
loop{
	data += a
	if data % b == c
		jd = true
		break
	else
		break if much.include? data % b
	end
	much << data % b
}

puts jd ? "YES": "NO"

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

int main() {

  int a,b,c,d,e,p,q;
	cin >>  a >> b;	
	p=2*a;
	q=4*a;
	c=b%2;
	if(c==1){
	cout << "No"<< endl;
	}
	else if(p<=b && b<=q ){
	cout << "Yes"<< endl;
	}
	else{
	cout << "No"<< endl;
	}
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

struct Info{
	char name[21];
	int length;
};

void strcpy(char* to,char* str){
	for(int i=0;str[i] != '\0';i++){
		to[i] = str[i];
		to[i+1] = '\0';
	}
}

int main(){

	int N,cost[14][14],limit,count,tmp,ans,next_state,num_town;
	int*** dp = new int**[15];
	for(int i = 1; i <= 14; i++){
		dp[i] = new int*[14];
		for(int k = 0; k < 14; k++){
			dp[i][k] = new int[16384];
		}
	}

	Info first_info[14],info[14];
	bool FLG,part_sentence[14];

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		for(int i = 0; i < N; i++){
			scanf("%s",first_info[i].name);
			for(first_info[i].length = 0; first_info[i].name[first_info[i].length] != '\0';first_info[i].length++);
		}

		for(int i = 0; i < 14;i++)part_sentence[i] = false;

		for(int i = 0; i < N; i++){
			for(int k = 0; k < N; k++){
				if(i != k && first_info[i].length <= first_info[k].length){
					for(int left = 0; first_info[k].length-left >= first_info[i].length;left++){
						FLG = true;

						for(int a = 0; a < first_info[i].length; a++){
							if(first_info[i].name[a] != first_info[k].name[left+a]){
								FLG = false;
								break;
							}
						}

						if(FLG){
							part_sentence[i] = true;
							break;
						}
					}

				}
			}
		}

		num_town = 0;

		for(int i = 0; i < N; i++){
			if(part_sentence[i] == false){
				strcpy(info[num_town].name,first_info[i].name);
				info[num_town].length = first_info[i].length;
				num_town++;
			}
		}

		N = num_town;

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

				count = 0;

				for(int left = 0; left < info[i].length;left++){
					FLG = true;
					for(int a = left; a < info[i].length && (a-left) < info[k].length;a++){
						if(info[i].name[a] != info[k].name[a-left]){
							FLG = false;
							break;
						}
					}
					if(FLG){
						count = info[i].length-left;
						break;
					}
				}

				cost[i][k] = count;
			}
		}

		limit = pow(2,N);

		for(int i = 1; i <= N;i++){
			for(int k = 0; k < N; k++){
				for(int p = 0; p < limit; p++){
					dp[i][k][p] = BIG_NUM;
				}
			}
		}

		for(int i = 0; i < N; i++){
			tmp = pow(2,i);
			dp[1][i][tmp] = info[i].length;
		}

		for(int i = 2; i <= N; i++){
			for(int k = 0; k < N; k++){
				for(int state = 0; state < limit; state++){
					if(dp[i-1][k][state] == BIG_NUM)continue;
					for(int a = 0; a < N; a++){
						if(state & (1 << a)){
							//Do nothing
						}else{
							next_state = state + pow(2,a);

							if(dp[i][a][next_state] > dp[i-1][k][state] + info[a].length - cost[k][a]){
								dp[i][a][next_state] = dp[i-1][k][state] + info[a].length - cost[k][a];
							}
						}
					}
				}
			}
		}

		ans = BIG_NUM;
		for(int i = 0; i < N; i++){
			ans = min(ans,dp[N][i][limit-1]);
		}

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

	return 0;
}

Measured memory_bytes: 15268
#include <stdio.h>

main(){
  int i,j,n=0,name[3][8],n1st[4],n2nd[4],nother[18];
  double time[3][8],t1st[4],t2nd[4],tother[18];

  for(i=0;i<3;i++){
    for(j=0;j<8;j++){
      scanf("%d%lf",&name[i][j],&time[i][j]);
    }
  }

  for(i=0;i<3;i++){
    t1st[i] = 0.0;
    t2nd[i] = 0.0;
    for(j=0;j<8;j++){
      if(t1st[i] > time[i][j] || t1st[i] == 0.0){
	if(t2nd[i] != 0.0){
	  tother[n] = t2nd[i];
	  nother[n++] = n2nd[i];
	}
	t2nd[i] = t1st[i];
	n2nd[i] = n1st[i];
	t1st[i] = time[i][j];
	n1st[i] = name[i][j];
      }
      else if(t2nd[i] > time[i][j] || t2nd[i] == 0.0){
	if(t2nd[i] != 0.0){
	  tother[n] = t2nd[i];
	  nother[n++] = n2nd[i];
	}
	t2nd[i] = time[i][j];
	n2nd[i] = name[i][j];
      }
      else{
	tother[n] = time[i][j];
	nother[n++] = name[i][j];
      }
    }
  }

  t1st[3] = 0.0;
  t2nd[3] = 0.0;
  for(i=0;i<n;i++){
    if(t1st[3] > tother[i] || t1st[3] == 0.0){
      t2nd[3] = t1st[3];
      n2nd[3] = n1st[3];
      t1st[3] = tother[i];
      n1st[3] = nother[i];
    }
    else if(t2nd[3] > tother[i] || t2nd[3] == 0.0){
      t2nd[3] = tother[i];
      n2nd[3] = nother[i];
    }
  }

  for(i=0;i<4;i++){
    printf("%d %.2f\n",n1st[i],t1st[i]);
    printf("%d %.2f\n",n2nd[i],t2nd[i]);
  }
  return 0;
}

Measured memory_bytes: 348
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template<class T> bool INRANGE(T x,T a,T b) { return a<=x&&x<=b; }
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;
}

#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>=0;--i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;


typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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


    int N, M;
    cin >> N >> M;

    vi P(M) ,Y(M);
    vi yd[100001];

    REP(i,M) {
        cin >> P[i] >> Y[i];
        yd[P[i]].emplace_back(Y[i]);
    }
    REP(i,N)sort(ALL(yd[i+1]));

    REP(i,M) {
        ll ans = ll(P[i])*1000000+int(lower_bound(ALL(yd[P[i]]), Y[i]) - yd[P[i]].begin())+1;
        string s = to_string(ans);
        while (s.length() != 12){
            if (s.length() > 12) {
                cerr << "TOO LONG ANS" << endl;
                break;
            }
            s = '0'+s;
        }

        cout << s << endl;
    }

    return 0;
}


Measured memory_bytes: 7808
program sample
    implicit none
  
    integer(8) :: i,j,m,n
    real(8)::a,b
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) n,i,j
    if (j>=n)then
        if (j<=i)then
            write(*,*)'Yes'
            stop
end if
    


end if
    write(*,*) 'No'
  
    stop
end program sample
  



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define R cin>>
#define C cout<<
const int INF = 1000000007;
typedef long long ll;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  ll k,a,b;
  cin >> k >> a >> b;
  ll now = k;
  if(a >= b){
    cout << 1 + k << endl;
  }
  else{
    if(a <= k - 1 && (b - a) >= 2){
      now -= a - 1;
      if(now % 2 == 0)cout << a + (b - a) * (now / 2);
      else cout << a + (b - a) * ((now - 1) / 2) + 1 << endl;
    }
    else{
      cout << 1 + k << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
using System;
namespace ITP1_4_C
{
    class Program
    {
        static void Main(string[] args)
        {
            while(true)
            {
                string[] S = Console.ReadLine().Split();
                var a = int.Parse(S[0]);
                var b = int.Parse(S[2]);
                if(S[1] == "+")
                {
                    Console.WriteLine(a + b);
                }
                else if(S[1] == "-")
                {
                    Console.WriteLine(a - b);
                }
                else if(S[1] == "*")
                {
                    Console.WriteLine(a * b);
                }
                else if(S[1] == "/")
                {
                    Console.WriteLine(a / b);
                }
                else
                {
                    break;
                }
            }
        }
    }
}


Measured memory_bytes: 15944
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
using namespace std;

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

int N, M;
vector<vector<int> > fi;
typedef pair<int,int> pint;
typedef pair<pint,bool> state;

int dp[65][35][2]; // 0: 左足、1: 右足

int main() {
  while (cin >> M >> N) {
	if (N == 0) break;
	fi.clear(); fi.resize(N);
	vector<pint> starts;
	set<pint> goals;
	for (int i = 0; i < N; ++i) {
	  for (int j = 0; j < M; ++j) {
		char c; cin >> c;
		int time = 0;
		if (c == 'X') time = -1;
		else if (c == 'S') starts.push_back(pint(i, j)), time = 0;
		else if (c == 'T') goals.insert(pint(i, j)), time = 0;
		else time = (int)(c - '0');
		fi[i].push_back(time);
	  }
	}
	int res = INF;
	priority_queue<pair<int,state>, vector<pair<int,state> >, greater<pair<int,state> > > que;
	for (int i = 0; i < 65; ++i) for (int j = 0; j < 35; ++j) {
		for (int it = 0; it < 2; ++it)
		  dp[i][j][it] = INF;
	  }
	for (auto p : starts) {
	  for (int it = 0; it < 2; ++it) {
		dp[p.first][p.second][it] = 0;
		que.push(make_pair(0, state(p,it)));
	  }
	}
	while (!que.empty()) {
	  auto cur = que.top(); que.pop();
	  int curdist = cur.first;
	  pint p = cur.second.first;
	  int lr = cur.second.second;
	  if (goals.count(p)) chmin(res, curdist);
	  if (curdist > dp[p.first][p.second][lr]) continue;
	  for (int i = 0; i < N; ++i) {
		for (int j = 0; j < M; ++j) {
		  if (lr == 0 && j <= p.second) continue;
		  if (lr == 1 && j >= p.second) continue;
		  if (abs(i - p.first) + abs(j - p.second) > 3) continue;
		  if (fi[i][j] == -1) continue;
		  if (chmin(dp[i][j][1-lr], curdist + fi[i][j])) {
			que.push(make_pair(dp[i][j][1-lr], state(pint(i,j), 1-lr)));
		  }
		}
	  }
	}
	if (res < INF) cout << res << endl;
	else cout << -1 << endl;
  }
}



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

using namespace std;

int main() {
    string s;
    cin >> s;
    int t = 753;
    vector<int> v = vector<int>(s.length() - 2);
    for (int i = 0; i <= s.length() - 2; i++) {
        string ss = s.substr(i, 3);
        v[i] = abs(753 - stoi(ss));
    }
    sort(v.begin(), v.end());
    cout << v[0] << "\n";
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール
bool is_square(ll n) {
    ll le = 0;
    ll gt = (ll)(sqrtl(n) + 1.0L);
    while (gt - le > 1) {
        ll mid = (le + gt) / 2;
        (mid * mid <= n ? le : gt) = mid;
    }
    return le * le == n;
}

// 処理内容
int main() {
    
    ll s; cin >> s;

    ll x3 = 0, y3 = 0; // fixed
    
    ll x1, y2;
    if (is_square(s)) {
        x1 = y2 = (ll)(sqrtl(s));
    } else {
        x1 = (ll)(sqrtl(s) + 1);
        y2 = min((s + x1-1) / x1, 1000000000LL);
    }

    ll x2 = x1*y2 - s;
    ll y1 = 1;
    
    vector<ll> ans = {x1, y1, x2, y2, x3, y3};
    REP(i, ans.size()) cout << ans[i] << " \n"[i==i_len-1];
    // DUMP(abs(x1*y2-x2*y1));
    
}

Measured memory_bytes: 256
package main

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

var h, w int
var s [][]byte
var wall byte = '#'
var visited map[int]struct{}

type pos struct {
	x int
	y int
	d int
}

var direction = []pos{
	pos{-1, 0, 0},
	pos{0, 1, 0},
	pos{1, 0, 0},
	pos{0, -1, 0},
}

func bfs(i, j int) int {
	move := 0
	q := []pos{pos{i, j, 0}}
	visited[i*w+j] = struct{}{}

	for len(q) > 0 {
		p := q[0]
		q = q[1:]

		for _, d := range direction {
			nx := p.x + d.x
			ny := p.y + d.y
			nd := p.d + 1
			if _, ok := visited[nx*w+ny]; ok {
				continue
			}
			if nx < 0 || nx >= h || ny < 0 || ny >= w || s[nx][ny] == wall {
				continue
			}
			q = append(q, pos{nx, ny, nd})
			move = max(move, nd)
			visited[nx*w+ny] = struct{}{}
		}
	}

	return move
}

func main() {
	h, w = readInt(), readInt()
	s = make([][]byte, h)
	for i := range s {
		s[i] = readBytes()
	}

	ans := 0
	for i := range s {
		for j := range s[i] {
			if s[i][j] == wall {
				continue
			}
			visited = make(map[int]struct{})
			ans = max(ans, bfs(i, j))
		}
	}

	fmt.Println(ans)
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

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

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

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

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 5504
#include <iostream>
#include <string>
#include <string.h>
using namespace std;

int main()
{
    string S;
    cin >> S;

    for (int i = 0; i < 3; i++) {
        if (S[i] == S[i + 1]) {
            cout << "Bad" << endl;
            return 0;
        }
    }

    cout << "Good" << endl;
    return 0;
}

Measured memory_bytes: 256