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

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  string s; cin >>s;
  vector<int> left(n+1, 0);
  for(int i=1; i<n; ++i){
     if(s[i-1] == 'A' && s[i] == 'C' )
        left[i] = left[i-1] + 1;
     else
        left[i] = left[i-1];
  } 
  for(int i=0; i<m; ++i){
    int l, r; cin >> l >> r;
		--l, --r;
    cout << left[r] - left[l] << "\n"; 
  }
  return 0;
}


Measured memory_bytes: 1488
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define MOD2 100000000
#define ll long long
#define cnl(d) cout<<d<<'\n'
#define cns(d) cout<<d<<' '
#define endl '\n'
#define cno cout<<"NO\n"
#define cyes cout<<"YES\n"
#define vl vector<ll>
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define pl pair<ll,ll>
#define vll vector<pl>
#define sl set<ll>
#define sll set<pl>
#define msl map<string,ll>
#define mll map<ll,ll>
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(a);i<=(b);i++)
#define rdp(i,a,b) for(i=(a);i>=(b);i--)
#define lb(v,z) lower_bound(all(v),z)
#define ub(v,z) upper_bound(all(v),z)
#define trvl(c,it) for(vl::iterator it=(c).begin();it!=(c).end();it++)
#define trvll(c,it) for(vll::iterator it=(c).begin();it!=(c).end();it++)
#define trsll(c,it) for(sll::iterator it=(c).begin();it!=(c).end();it++)
#define trmsl(c,it) for(msl::iterator it=(c).begin();it!=(c).end();it++)
#define trmll(c,it) for(mll::iterator it=(c).begin();it!=(c).end();it++)
#define trsl(c,it) for(sl::iterator it=(c).begin();it!=(c).end();it++)
ll mod=MOD;
using namespace std;
long long int fast_exp(long long int base,long long int ex) {
    long long int res=1;
    while(ex>0) {
       if(ex%2==1) res=(res*base)%mod;
       base=(base*base)%mod;
       ex/=2;
    }
    return res%mod;
}
long long int gcd(long long int a, long long int b)
{
    if(b==0)return a;
     long long int re= gcd(b,a%b);return re;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   ll n,k;
   cin>>n>>k;
   ll ar[n]={0};
    ll ans;cin>>ans;
    ans=abs(ans-k);
   for(ll i=1;i<n;i++)
   {
      ll a;cin>>a;
      a=abs(a-k);
      ans=gcd(ans,a);
   }
  cout<<ans<<"\n";
    return 0;

}


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

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

  string s;
  cin >> s;

  string ans = "";
  for (int i = 0; i < s.size(); i++) {
    if (i % 2 == 0) ans += s.at(i);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 592
N=int(input())
P=10**9+7
Q=[1 for i in range(1001)]
Q[0]=0
Q[1]=0
for i in range(2,32):
    if Q[i]==1:
        k=2
        while(k*i<=1000):
            Q[k*i]=0
            k+=1
Prime=[]
for i in range(1001):
    if Q[i]==1:
        Prime.append(i)
L=len(Prime)
def PrimeFact(X):
    result=[0 for i in range(L)]
    for i in range(L):
        while(True):
            if X%Prime[i]==0:
                result[i]+=1
                X=X//Prime[i]
            else:
                break
        if X==1:
            break
    return result
FactFact=[0 for i in range(L)]
for i in range(1,N+1):
    O=PrimeFact(i)
    for j in range(L):
        FactFact[j]+=O[j]
#print(FactFact)
ans=1
for i in range(L):
    ans=(ans*(FactFact[i]+1))%P
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int sx,sy,tx,ty;cin >> sx >> sy >> tx >> ty;
	string s="";
	int dx=tx-sx,dy=ty-sy;
	rep(i,dy) s+='U';
	rep(i,dx) s+='R';
	rep(i,dy) s+='D';
	rep(i,dx) s+='L';
	s+='L';
	rep(i,dy+1) s+='U';
	rep(i,dx+1) s+='R';
	s+='D';
	s+='R';
	rep(i,dy+1) s+='D';
	rep(i,dx+1) s+='L';
	s+='U';
	cout << s << endl;
}

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

using namespace std;

typedef long long ll;

#define pf(n) cout << n << endl
#define ps() cout <<" ";
#define sf(n) cin >> n
#define in(i,n) for (int i = 0; i < n; i++)
#define vi vector<int>
#define vp vector<pair<int, int>>
#define graph vector< vector<int> >
#define vs vector<string>

int x;
int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b,c;
  sf(a);sf(b);sf(c);
  if(a*b<c)pf(a*b);
  else pf(c);
}


Measured memory_bytes: 256
import java.awt.*;
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        FastReader sc = new FastReader();
        double r=sc.nextInt();
        System.out.println(Math.PI*2*r);
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 33372
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int r = scanner.nextInt(), c = scanner.nextInt();
		int[][] a = new int[r + 1][c + 1];
		for (int i = 0; i < r; ++i) {
			for (int j = 0; j < c; ++j) {
				a[i][j] = scanner.nextInt();
				a[r][j] += a[i][j];
				a[i][c] += a[i][j];
				a[r][c] += a[i][j];
			}
		}
		for (int i = 0; i <= r; ++i) {
			for (int j = 0; j <= c; ++j) {
				if (j != 0) System.out.print(' ');
				System.out.print(a[i][j]);
			}
			System.out.println();
		}
	}
}


Measured memory_bytes: 42564
import bisect
n=int(input())
l=list(map(int,input().split()))
l=sorted(l)
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    idx=bisect.bisect_right(l,l[i]+l[j]-1,j+1)
    ans+=idx-(j+1)
print(ans)

Measured memory_bytes: 3316
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl

//ここから編集する


int main() {
    int N,L;
    cin >> N >> L;
    vector<int>  v(N),w;
    rep(i,0,N){
        cin >> v[i];
    }
    int las = -1;
    rep(i,0,N-1){
        if(v[i]+v[i+1] >= L){
            las = i;
        }
    }
    if(las == -1){
        cout << "Impossible" << endl;
        return 0;

    }

    for(int i = las; i >= 0; i--){
        w.push_back(i);
    }
    for(int i = las+1; i < N - 1;i++){
        w.push_back(i);
    }

    cout << "Possible" << endl;
    for(int i = (w.size() - 1); i >= 0; i--){
        cout << w[i] + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 1784
import java.util.Arrays;
import java.util.Scanner;
class Player implements Comparable<Player>{
	int party;
	int num;
	String time;
	Player(int p,int n,String t){
		this.party = p;
		this.num = n;
		this.time = t;
	}
	/*@Override
	public int compareTo(Player p) {
		return this.time.compareTo(p.num);
	}
	*/
	@Override
	public int compareTo(Player o) {
		// TODO Auto-generated method stub
		return this.time.compareTo(o.time);
	}
	
}

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Player[] person = new Player[24];
		int[][] rank = new int[3][8];
		int[] cnt = new int[3]; 
		int cnt1 = 0;
		int cnt2 = 0;
		int cnt3 = 0;
		for(int i = 0;i < 3;i++){
			for(int j = 0;j < 8;j++){
				person[i*8+j] = new Player(i,sc.nextInt(),sc.next());
			}
		}
		Arrays.sort(person);
		for(int i = 0;i < 24;i++){
			rank[person[i].party][cnt[person[i].party]] = i;
			cnt[person[i].party]++;
		}
		for(int i = 0;i < 3;i++){
			for(int j = 0;j < 2;j++){
				System.out.println(person[rank[i][j]].num+" "+person[rank[i][j]].time);
				person[rank[i][j]].time = "999";
			}
		}
		Arrays.sort(person);
		for(int j = 0;j < 2;j++){
			System.out.println(person[j].num+" "+person[j].time);
		}
		
	}
}

Measured memory_bytes: 26220
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <cmath>
#include <cstring>
#include <cstdio>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;

int main() {
    int K, X;
    cin >> K >> X;
    int m = max(X - K + 1, -1000000);
    int M = min(X + K - 1, +1000000);
    for (int i = m; i <= M; i ++) {
        cout << i << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
 
ll now,n,k;

int main(){
  ll ans=0LL;
  cin >> n >> k;
  vector<ll> a(n);
  vector<ll> bits(62);
  REP(i,n){
    cin>>a[i];
    ans+=k^a[i];
    REP(j,62){
      bits[j]+=a[i]%2;
      a[i]/=2;
    }
  }
  
  for(int i=0;i<62;i++){
    if ((k>>i)%2==1){//i桁目を0にしたときの最大sum
      ll score=0LL;
      REP(j,i){
        score+=max(bits[j],n-bits[j])*(1LL<<j);
      }
      score+=bits[i]*(1LL<<i);
      for(int j=i+1;j<62;j++){
        int b=(k>>j)%2;
        if (b==0){
          score+=bits[j]*(1LL<<j);
        }
        if (b==1){
          score+=(n-bits[j])*(1LL<<j);
        }
      }
      ans=max(ans,score);
    }
  }
  
  
  //vector<vector<ll>> b = vector<vector<ll>>(50, vector<ll>(2, 0));  

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

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    cout << n / 3 << endl;
}

Measured memory_bytes: 256
#include <numeric>
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
using namespace std;
#define int long long
#define ll long long
#define mod  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
double pi = 3.141592653589793;
//使う奴はここから
const int h=4e6+5;
bitset<h> f;
signed main() {
    int n,a[2555];cin>>n;
    int sum=0;
    f[0]=1;
    rep(i,0,n){
        cin>>a[i];
        f|=(f<<a[i]);
        sum+=a[i];
    }
    rep(i,(sum+1)/2,sum+1){
        if(f[i]){
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}

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

const int inf = 1e9 + 9;
typedef pair<int, int> P;

struct edge
{
	edge() {} 
	edge(int a, int b) { to = a, cost = b; }

	int to, cost;
};

int n, m, c;
vector<edge> G[100000];
P d[100000];
bool f[100000];

void dijkstra(int s=0)
{
	for (int i = 0; i < n; i++){
		d[i] = P(inf, i);
	}
	priority_queue<P, vector< P >, greater< P > > q;
	d[s].first = 0;
	q.push(P(0, s));

	while (!q.empty()){
		P p = q.top(); q.pop();
		int v = p.second;

		if (d[v].first < p.first) continue;

		for (int i = 0; i < G[v].size(); i++){
			edge e = G[v][i];
			if (d[e.to].first > d[v].first + e.cost){
				d[e.to].first = d[v].first + e.cost;
				q.push(P(d[e.to].first, e.to));
			}
		}
	}
}

int main()
{
	long long sum = 0;
	priority_queue<P, vector< P >, greater< P > > q;
	
	cin >> n >> m >> c;
	for (int i = 0; i < m; i++){
		int a, b, d;
		cin >> a >> b >> d;
		a--; b--;
		sum += d;
		G[a].push_back(edge(b, d));
		G[b].push_back(edge(a, d));
	}

	dijkstra();
	sort(d, d + n);

	vector<int> num(n);
	for (int i = 0; i < n; i++){
		num[i] = d[i].first;
	}
	num.erase(unique(num.begin(), num.end()), num.end());

	long long ans = (1ll << 62);
	int j = 0;
	for (int i = 0; i < num.size(); i++){
		for (; j < n && num[i] == d[j].first; j++){
			int v = d[j].second;
			f[v] = true;
			for (int k = 0; k < G[v].size(); k++){
				if (f[G[v][k].to]) sum -= G[v][k].cost;
			}
		}
		ans = min(ans, sum + (long long)c * num[i]);
	}

	cout << ans << endl;
}
	

Measured memory_bytes: 12888
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>

using namespace std;
typedef long long int ll;
void sayYes() { cout << "Yes" << endl; };
void sayNo() { cout << "No" << endl; };
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }                   // 最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); };                      // 最小公倍数
ll getDigit(ll num) { return log10(num) + 1; }                         // 桁数
ll digitSum(ll n) { return (n < 10) ? n : digitSum(n / 10) + n % 10; } // 各桁の和
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repn(i, n) for (ll i = 1; i <= n; i++)

void Main()
{
    int a, b, h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2 << endl;

    return;
}

signed main(void)
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
import sys
from itertools import accumulate
 
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines

import bisect

n,m=map(int,input().split())
A=list(map(int,input().split()))
A.sort()

def hand(x):
  cnt=0
  for i in range(n):
    p=x-A[-i-1]
    k=n-bisect.bisect_left(A,p)
    if k==0:
      break
    cnt+=k
    if cnt>=m:
      break
  return cnt

def main():
  l=0
  h=2*10**5+1
  mid=(l+h)//2
  
  while l+1<h:
    mid=(l+h)//2
    if hand(mid)<m:
      h=mid
    else:
      l=mid
  
  B = list(accumulate(A[::-1]))[::-1]

  ans=0
  cnt=0
  
  
  for i in range(n):
    y=l-A[i]+1
    index=bisect.bisect_left(A,y)
    if n==index:
      continue
    else:
      ans+=(n-index)*A[i]+B[index]
      cnt+=(n-index)
  
  ans+=(m-cnt)*l
  print(ans)

if __name__ == "__main__":
	main()
  

  
  

Measured memory_bytes: 55216
#include <iostream>
using namespace std;
int main(){
	int n,i,sum=0;
	cin>>n;
	int a[n+1];
	for(i=1;i<=n;i++)cin>>a[i];
	for(i=1;i<=n;i++)
	if(a[i]!=i)sum++;
	if(sum<=2)cout<<"YES";
	else
	cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int mod=1e9+7;
ll dp[100010][3],ways[100010];
char str[100010];
int main(){
	scanf("%s",str+1);
	int len=strlen(str+1);
	ways[0]=1;
	for(int i=1;i<=len;i++){
		if(str[i]=='A' || str[i]=='?'){
			dp[i][0]=(dp[i-1][0]+ways[i-1])%mod;
			dp[i][1]=dp[i-1][1];
			dp[i][2]=dp[i-1][2];
		}
		if(str[i]=='B' || str[i]=='?'){
			dp[i][0]=(dp[i][0]+dp[i-1][0])%mod;
			dp[i][1]=(dp[i][1]+dp[i-1][1]+dp[i-1][0])%mod;
			dp[i][2]=(dp[i][2]+dp[i-1][2])%mod;
		}
		if(str[i]=='C' || str[i]=='?'){
			dp[i][0]=(dp[i][0]+dp[i-1][0])%mod;
			dp[i][1]=(dp[i][1]+dp[i-1][1])%mod;
			dp[i][2]=(dp[i][2]+dp[i-1][2]+dp[i-1][1])%mod;
		}
		if(str[i]=='?') ways[i]=ways[i-1]*3%mod;
		else ways[i]=ways[i-1];
	}
	printf("%lld\n",dp[len][2]);
	return 0;
}

Measured memory_bytes: 3456
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		vector<pair<int, int>>ps(N);
		for (int i = 0; i < N; ++i) {
			int a, b; cin >> a >> b;
			ps[i] = make_pair(a, b);
		}
		sort(ps.begin(), ps.end(), [](const pair<int,int>&l, const pair<int,int> &r) {
			return l.second < r.second;
		});
		int sum = 0;
		bool ok = true;
		for (int i = 0; i < N; ++i) {
			sum += ps[i].first;
			if (sum > ps[i].second)ok = false;
		}
		if (ok)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 2976
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define endl "\n"

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
    oreno_initializer() {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }
} oreno_initializer;



int y, m, ym, my;

signed main() {
    scanf("%2d%2d", &y, &m);
    if (1<=m && m<=12) ym = 1;
    if (1<=y && y<=12) my = 1;
    if (!ym && !my) cout << "NA";
    else if (ym && my) cout << "AMBIGUOUS";
    else if (ym) cout << "YYMM";
    else cout << "MMYY";
}


Measured memory_bytes: 256
import java.io.*;
import java.util.ArrayList;

class Main{
    static String[] s;
    static int H,W;

    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        String[] sl = str.split(" ");
        H = Integer.parseInt(sl[0]);
        W = Integer.parseInt(sl[1]);
        s = new String[H];
        for (int i=0;i<H;i++){
            s[i] = br.readLine();
        }
        String ans = "Yes";
        for (int i=0;i<H;i++){
            for (int j=0;j<W;j++){
                if (String.valueOf(s[i].charAt(j)).equals("#")){
                    if (!adjacent(i, j)){
                        ans = "No";
                        break;
                    }
                }
            }
            if (ans.equals("No")){
                break;
            }
        }
        System.out.println(ans);
    }

    public static boolean adjacent(int h,int w){
        String now = String.valueOf(s[h].charAt(w));
        String up = ".";
        String down = ".";
        String left = ".";
        String right = ".";
        if (h!=H-1 && h!=0 && w!=W-1 && w!=0){
            up = String.valueOf(s[h-1].charAt(w));
            down = String.valueOf(s[h+1].charAt(w));
            left = String.valueOf(s[h].charAt(w-1));
            right = String.valueOf(s[h].charAt(w+1));
        } else if (h==0){
            if (w==0){
                down = String.valueOf(s[h+1].charAt(w));
                right = String.valueOf(s[h].charAt(w+1));
            } else if (w==W-1){
                down = String.valueOf(s[h+1].charAt(w));
                left = String.valueOf(s[h].charAt(w-1));
            } else {
                down = String.valueOf(s[h+1].charAt(w));
                left = String.valueOf(s[h].charAt(w-1));
                right = String.valueOf(s[h].charAt(w+1));
            }
        } else if (h==H-1){
            if (w==0){
                up = String.valueOf(s[h-1].charAt(w));
                right = String.valueOf(s[h].charAt(w+1));
            } else if (w==W-1){
                up = String.valueOf(s[h-1].charAt(w));
                left = String.valueOf(s[h].charAt(w-1));
            } else {
                up = String.valueOf(s[h-1].charAt(w));
                left = String.valueOf(s[h].charAt(w-1));
                right = String.valueOf(s[h].charAt(w+1));
            }
        } else {
            if (w==0){
                up = String.valueOf(s[h-1].charAt(w));
                down = String.valueOf(s[h+1].charAt(w));
                right = String.valueOf(s[h].charAt(w+1));
            } else if (w==W-1){
                up = String.valueOf(s[h-1].charAt(w));
                down = String.valueOf(s[h+1].charAt(w));
                left = String.valueOf(s[h].charAt(w-1));
            }
        }
        if (now.equals(up) || now.equals(down) || now.equals(left) || now.equals(right)){
            return true;
        } else {
            return false;
        }
    }
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll n,L,sum=0;
vl a,b;

ll f(int I){
	vl c;
	for(int i=0;i<n;i++) if(i!=I&&b[i]<2) c.push_back(b[i]);
	ll N=c.size(),M=0;
	vl dpl,DPL,dpr,DPR;
	dpl=DPL=dpr=DPR=vl(n+1);
	for(int i=1;i<=N;i++){
		ll t=(c[i-1]>=0?1:-1);
		dpl[i]=max(dpl[i-1]+t,0ll);
		DPL[i]=DPL[i-1]+(dpl[i-1]>0&&t<0?1:0);
	}
	for(int i=N-1;i>=0;i--){
		ll t=(c[i]<=0?1:-1);
		dpr[i]=max(dpr[i+1]+t,0ll);
		DPR[i]=DPR[i+1]+(dpr[i+1]>0&&t<0?1:0);
	}
	for(int i=1;i<=N;i++) M=max(M,DPL[i]+DPR[i]+min(dpl[i],dpr[i]));
	return L*(N-M+1+(I<n-1?1:0));
}

int main(){
	cin>>n>>L;
	a=b=vl(n);
	L*=2;
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n;i++){
		ll t;
		cin>>t;
		sum+=t/L*L;
		t%=L;
		bool l=(t<=2*a[i]),r=(t<=L-2*a[i]);
		if(!t) b[i]=2;
		else if(l&&r) b[i]=0;
		else if(l) b[i]=1;
		else if(r) b[i]=-1;
		else b[i]=2,sum+=L;
	}
	ll res=f(n);
	for(int i=n-1;i>=0;i--) if(b[i]<=0){
		res=min(res,f(i));
		break;
	}
	cout<<res+sum<<endl;
}

Measured memory_bytes: 20208
#include <fstream>
#include <cstring>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <climits>

using namespace std;

//ifstream cin("tema.in");
//ofstream cout("tema.out");

const int BUFFSIZE = 1 << 17;

char buffer[BUFFSIZE];
int pointer = BUFFSIZE;

char Advance() {
    if (pointer == BUFFSIZE) {
        fread(buffer, 1, BUFFSIZE, stdin);
        pointer = 0;
    }
    return buffer[pointer++];
}

int Read() {
    int answer = 0;
    char ch = Advance();
    while (!isdigit(ch))
        ch = Advance();
    while (isdigit(ch)) {
        answer = answer * 10 + ch - '0';
        ch = Advance();
    }
    return answer;
}

bool Check(int n, int m, int k, int a) {
    if ((a * m == k && n == 2 * a) || (n != 2 * a && (k - a * m) % (n - 2 * a) == 0 && (k - a * m) / (n - 2 * a) <= m && (k - a * m) / (n - 2 * a) >= 0))
        return true;
    return false;
}

int main() {
    //freopen("tema.in", "r", stdin);
    //freopen("tema.out", "w", stdout);
    int n, m, k;
    scanf("%d%d%d", &n, &m, &k);
    for (int i = 0; i <= n; i++)
        if (Check(n, m, k, i)) {
            printf("Yes\n");
            return 0;
        }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 128
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <bitset>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <chrono>
#include <random>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

template<typename T> T gcd(T a, T b) {
    if (a < b) return gcd(b, a);
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

template<typename T> T lcm(const T a, const T b) {
    return a / gcd(a, b) * b;
}

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

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

// End of template.

int main() {
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // cin.read(buf, sizeof buf); // 注意: ./a.out < in か pbp | ./a.out で入力すること

    int m, n, a[110];
    cin >> n >> m;
    rep(i, n) cin >> a[i];
    int total = 0;
    rep(i, n) total += a[i];
    int cnt = 0;
    rep(i, n) if (4*m*a[i] >= total) cnt += 1;
    if (cnt >= m)
        print("Yes");
    else
        print("No");

    return 0;
}



Measured memory_bytes: 256
def move(move_count, current, flag):
    for i in range(move_count):
        n_lis.append(num_lis[current+i])
        if flag == n:
            calculate()
            del n_lis[-1]
        else:
            move(move_count, current+i+1, flag+1)
            move_count -= 1
            del n_lis[-1]
            
def calculate():
    global count
    if sum(n_lis) == s:
        count += 1

while True:
    n, s = map(int, raw_input().split())
    if n == 0 and s == 0:
        break
    num_lis = [0,1,2,3,4,5,6,7,8,9]
    n_lis = []
    count = 0
    move(10-n+1,0,1)
    print count

Measured memory_bytes: 4232
let quick_sort a n cmp =
  let swap i j = let tmp = a.(i) in a.(i) <- a.(j); a.(j) <- tmp in
  let partition p r =
    let i = ref p in
    for j = p to r - 1 do
      if cmp a.(j) a.(r) <= 0 then (swap !i j; incr i)
    done;
    swap !i r;
    !i in
  let rec doit p r =
    if p >= r then () else
    let q = partition p r in
    doit p (q - 1);
    doit (q + 1) r in
  doit 0 (n - 1)

let calc_cost a n =
  let b = Array.copy a in
  quick_sort b n compare;
  let t = Array.make (b.(n-1) + 1) 0 in
  Array.iteri (fun i e -> t.(e) <- i) b;
  let p = Array.make n false in
  let rec duduwa i acc =
    p.(i) <- true;
    if p.(t.(a.(i))) then a.(i) :: acc
    else duduwa t.(a.(i)) (a.(i) :: acc) in
  let rec doit i acc =
    if i = n then acc
    else if p.(i) then doit (i + 1) acc
    else
      let ws = duduwa i [] in
      let m = List.length ws in
      let s = List.fold_left (+) 0 ws in
      let z = List.fold_left min max_int ws in
      doit (i + 1) (acc + (min (s + (m - 2)*z) (s + z + (m + 1)*b.(0)))) in
  doit 0 0

let () =
  let n = read_int () in
  let a = Array.init n (fun _ -> Scanf.scanf "%d " (fun e -> e)) in
  calc_cost a n |> Printf.printf "%d\n"

Measured memory_bytes: 2836
n,m=map(int,input().split())
dic={}
doll=0
AB=[list(map(int,input().split())) for _ in range(n)]

AB.sort()

for k,v in AB:
  if v<m:
    doll+=k*v
    m-=v
  else:
    doll+=k*m
    break
print(doll)

Measured memory_bytes: 27416
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(V, v) for (auto &&V : v)
#define all(x) (x).begin(), (x).end()
const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
using lint = long long;

using namespace std;

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int q;
  cin >> q;
  vector<int> t(q), a(q), b(q);
  rep(i, q) {
    cin >> t[i];
    if (t[i] == 1) cin >> a[i] >> b[i];
  }
  multiset<int, greater<int>> l;
  multiset<int> r;
  int lmax = -INF, rmin = INF;
  lint lsum = 0, rsum = 0, bsum = 0;
  int mid;
  bool mid_ava = false;
  rep(i, q) {
    if (t[i] == 1) {
      if (mid_ava) {
        if (a[i] < mid) {
          r.insert(mid);
          rmin = mid;
          rsum += mid;
          l.insert(a[i]);
          lmax = max(lmax, a[i]);
          lsum += a[i];
        } else {
          l.insert(mid);
          lmax = mid;
          lsum += mid;
          r.insert(a[i]);
          rmin = min(rmin, a[i]);
          rsum += a[i];
        }
      } else {
        if (a[i] < lmax) {
          l.erase(l.begin());
          mid = lmax;
          l.insert(a[i]);
          lmax = *l.begin();
          lsum += a[i] - mid;
        } else if (a[i] > rmin) {
          r.erase(r.begin());
          mid = rmin;
          r.insert(a[i]);
          rmin = *r.begin();
          rsum += a[i] - mid;
        } else {
          mid = a[i];
        }
      }
      mid_ava = !mid_ava;
      bsum += b[i];
    } else {
      cout << (mid_ava ? mid : lmax) << " " << rsum - lsum + bsum << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 12032
import java.util.* ;
public class Main{
       public static void main( String args[] ){
             Scanner cin = new Scanner( System.in ) ;
             int n = cin.nextInt() ;
             String s[] = new String[110] ;
             for( int i = 1 ; i <= n ; i++ )
                 s[i] = cin.next() ;
             Boolean flag = true ;
             for( int i = 1 ; i <= n - 1 ; i++ )
                 for( int j = i + 1 ; j <= n ; j++ )
                     if ( s[i].compareTo( s[j] ) == 0 ) flag = false ;
             for( int i = 1 ; i <= n - 1 ; i++ ){
                 int len = s[i].length() ;
                 if ( s[i].charAt( len - 1 ) != s[i + 1].charAt( 0 ) ) flag = false ;
             }
             if ( flag ) System.out.println( "Yes" ) ;
             else System.out.println( "No" ) ;
       }
} 

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  long long int a,b,c,d=0,f,g,h;
  cin>>a>>b;
  if(a%2==0||b%2==0)cout<<"No";
  else cout<<"Yes";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;
using plli=pair<ll,int>;
using vplli=vector<pair<ll,int>>;
using pllll=pair<ll,ll>;
using vpllll=vector<pair<ll,ll>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
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;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    ll N;
    cin>>N;
    vi a(N);
    rep(i,0,N)cin>>a[i];
    sort(a.rbegin(),a.rend());
    ll ans=0;
    priority_queue<int> q;
    int max=a[0],second=a[0];
    q.push(a[0]);
    rep(i,1,N){
        q.push(min(a[i],max));
        q.push(min(a[i],second));
        ans+=q.top();q.pop();
        max=second;
        second=a[i];
    }
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 5032
#include<bits/stdc++.h>
using namespace std;
#define L long long
L grid[101][101],c[101][101],r=0,mx;
L n,w,h,x,y,s,t;
void solve(L s,L t){
    mx=-999999;
    for(L i=1;i<=h;i++){
            r=0;
        for(L j=1;j<=w;j++){
            if(j>s){
                r-=grid[i][j-s];
                r+=grid[i][j];
                c[i][j]=r;
            }
            else{
                r+=grid[i][j];
                c[i][j]=r;
            }
        }
    }
    //cout<<endl;
    //for(L i=1;i<=h;i++){
     //  for(L j=1;j<=w;j++){
     //       cout<<c[i][j]<<" ";
      // }cout<<endl;
   // }cout<<endl;
    for(L i=s;i<=w;i++){
        r=0;
        for(L j=1;j<=h;j++){
            if(j>=t){
                r-=c[j-t][i];
                r+=c[j][i];
                if(mx<r){
                    mx=r;
                }
            }
            else{
                r+=c[j][i];
            }
        }
    }
}
int main()
{
    while(scanf("%lld",&n)&&n){
        scanf("%lld %lld",&w,&h);
        memset(grid,0,sizeof(grid));
        for(L i=1;i<=n;i++){
            scanf("%lld %lld",&x,&y);
            grid[y][x]=1;
        }
        scanf("%lld %lld",&s,&t);
        solve(s,t);
        printf("%lld\n",mx);
    }
    return 0;
}



Measured memory_bytes: 3388
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int>a(n+1);
    vector<int>b(n);
    for(int i=0;i<n+1;i++){
        cin >> b[i];
    }
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    long long int count=0;
    for(int i=0;i<n;i++){//braver i kill monster
        if(a[i]>b[i]){//braver i hp > i town monster
            a[i] = a[i]-b[i];
            count += b[i];
            b[i] = 0;
            if(a[i]>b[i+1]){
                a[i] = a[i]-b[i+1];
                count += b[i+1];
                b[i+1] = 0;
            }
            else{
                b[i+1] = b[i+1]-a[i];
                count += a[i];
                a[i] = 0;
            }
        }
        else{//braver i hp < i town monster
            b[i] = b[i]-a[i];
            count += a[i];
            a[i] = 0;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

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

int A, B;
char op;

int main() {
  cin >> A >> op >> B;
  if (op == '+') {
    cout << A + B;
  } else {
    cout << A - B;
  }
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double 
#define fo(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
int gcd(ll a,ll b){
    if(a==0)
    return b;
    return gcd(b%a,a);
}
int gcd1(ll a,ll b,ll c){
    return gcd(a,gcd(b,c));
}
int main() {
	int k;
	cin>>k;
	ll sum=0;
	fo(i,1,k+1){
	    fo(j,1,k+1){
	        fo(z,1,k+1){
	            sum+=gcd1(i,j,z);
	        }
	    }
	}
	cout<<sum;
	
	return 0;
}


Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

			StringBuilder Sa = new StringBuilder(br.readLine());
			StringBuilder Sb = new StringBuilder(br.readLine());
			StringBuilder Sc = new StringBuilder(br.readLine());

			//aのターン

			a(Sa,Sb,Sc);




			System.out.println();
		} catch (Exception e) {
			System.err.println("Error:" + e.getMessage());
		}
	}

	static void a(StringBuilder Sa, StringBuilder Sb, StringBuilder Sc){

		if(Sa.length() == 0){
			System.out.println("A");
			return;
		}

		String SaHead = Sa.substring(0, 1);
		Sa.deleteCharAt(0);

		if(SaHead.equals("a")){
			a(Sa,Sb,Sc);
		}else if(SaHead.equals("b")){

			b(Sa,Sb,Sc);
		}else{

			c(Sa,Sb,Sc);
		}

	}

	static void b(StringBuilder Sa, StringBuilder Sb, StringBuilder Sc){

		if(Sb.length() == 0){
			System.out.println("B");
			return;
		}

		String SaHead = Sb.substring(0, 1);
		Sb.deleteCharAt(0);

		if(SaHead.equals("a")){
			a(Sa,Sb,Sc);
		}else if(SaHead.equals("b")){

			b(Sa,Sb,Sc);
		}else{

			c(Sa,Sb,Sc);
		}
	}

	static void c(StringBuilder Sa, StringBuilder Sb, StringBuilder Sc){

		if(Sc.length() == 0){
			System.out.println("C");
			return;
		}

		String SaHead = Sc.substring(0, 1);
		Sc.deleteCharAt(0);

		if(SaHead.equals("a")){
			a(Sa,Sb,Sc);
		}else if(SaHead.equals("b")){

			b(Sa,Sb,Sc);
		}else{

			c(Sa,Sb,Sc);
		}
	}
}


Measured memory_bytes: 8020
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] X = new int[N];
    for (int i = 0; i < N; i++) X[i] = sc.nextInt();
    int ans = 1000000000;
    for (int i = 1; i <= 100; i++) {
      int tmp = 0;
      for (int j = 0; j < N; j++) {
        tmp += (X[j] - i) * (X[j] - i);
      }
      ans = Math.min(ans, tmp);
    }
    System.out.println(ans);
  }
}

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

void solve(string s){
	int n = s.size();

	if(n % 2 == 0 && s[0] != s[n-1] || n % 2 == 1 && s[0] == s[n - 1]) {
		cout << "Second" << endl;
	} else {
		cout << "First" << endl;
	}
}

int main(){	
	string s;
	cin >> s;
	solve(s);
	return 0;
}



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

int main(){
  int n,m;
  cin>>n>>m;
  int a[m];
  int b[m];
  for(int i=0;i<m;i++){
    cin>>a[i]>>b[i];
  }
  int num[60]={0};
  for(int i=0;i<m;i++){
    num[a[i]]++;
    num[b[i]]++;
  }
  for(int i=1;i<n+1;i++){
    cout<<num[i]<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  string S, T; cin >> S >> T;
  cout << (S[0] == T[0]) + (S[1] == T[1]) + (S[2] == T[2]) << endl;
}

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

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = false;

vector<int> makePrimeTable(ll x){
    vector<int> primeTable(x + 1);
    for(ll i = 0; i <= x; i++){
        primeTable[i] = 0;
    }


    for(ll i = 2; i * i <= x; i++){
        if(primeTable[i] == 0){
            for(ll j = i; j <= x; j *= i){
                primeTable[j] = 1;
            }
            for(ll j = i + i; j <= x; j += i){
                if(primeTable[j] == 0) primeTable[j] = -1;
            }
        }
    }
    return primeTable;
}


// xを素因数分解
map <ll, ll> primeFactorization(ll x){
    map <ll, ll> ret;
    for(ll i = 2; i * i <= x; i++){
        while(x % i == 0){
            ret[i] ++;
            x /= i;
        }
    }
    if(x != 1) ret[x] = 1;

    return ret;
}



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

    map<ll, ll> m = primeFactorization(n);

    ll ans = 0;
    for (auto it = m.begin(); it != m.end(); it++){
        ll tmp = 1;
        while ( it->second >= tmp )
        {
            it->second -= tmp;
            ans ++;
            tmp ++;
        }
    }
    

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

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

int main(){
  ll n;
  cin >> n;
  
  vector<ll> d(n);
  for( ll i = 0; i < n; i++ )
    cin >> d[i];
  
  sort(d.begin(), d.end());
  cout << d[n/2] - d[n/2-1] << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long int
#define dbg(x) cout<<"( "<<#x<<" -> "<<x<<" )"<<endl;
using namespace std;
/*
int BS(int arr[],int len,int ele)
{
    int low=0,high=len;
    while (low<high)
    {
        int mid=low+(high-low)/2;
        if (arr[mid]>ele)
        high=mid;
        else
        low=mid+1;
    }
    return low;
}
*/
int main()
{
    int n;
    scanf("%d",&n);
    int a[n+1];
    a[n]=INT_MAX;
    for (int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+(n+1));
    ll sum1=0;
    for (int i=0;i<n-2;i++)
    {
        for (int j=i+1;j<n-1;j++)
        {
            for (int k=j+1;k<n;k++)
            {
                if (a[i]<(a[j]+a[k]) && a[j]<(a[i]+a[k]) && a[k]<(a[i]+a[j]))
                sum1++;
            }
        }
    }
    printf("%lld\n",sum1);
    return 0;
}

Measured memory_bytes: 3796
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1001001001;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
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; }

int main(){
    string A,B,C; cin >> A >> B >> C;
    int a=0;
    int b=0;
    int c=0;
    
    char t=A[0];
    while(1){
        if (t=='a'){
            if (a==A.size()){
                cout << "A" << endl;
                return 0;
            }
            t=A[a];
            a++;
        }
        if (t=='b'){
            if (b==B.size()){
                cout << "B" << endl;
                return 0;
            }
            t=B[b];
            b++;
        }
        if (t=='c'){
            if (c==C.size()){
                cout << "C" << endl;
                return 0;
            }
            t=C[c];
            c++;
        }
    }
    return 0;
}

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

#define ll long long
#define endl "\n" 
#define FOR(n) for(int i=0 ; i<n ; i++)
#define FORa(a, n) for(ll i=a ; i<=n ; i++)
ll mod=1000000007;
ll inf=1e9;
vector<ll> dp;
void solve()
{
  int x , y ,z;
  cin >> x >> y >> z;
  if(x%y!=0) x=x/y+1;
  else x=x/y;
  cout << x*z << endl;
}   

  


int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t=1;
  //cin >> t;
  while(t--)
    solve();
    return 0 ;
}
  

Measured memory_bytes: 3644
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <tuple>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(perm),end(perm)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int digit_sum(int n){
    int ans = 0;
    while(n!=0){ans+=n%10; n /= 10;}
    return ans;
}

int main(){
    int n,a,b; cin>>n>>a>>b;
    int ans = 0;
    REP(i,n){
        int tp = digit_sum(i);
        if(a<=tp && tp<=b)ans+=i;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main (){
    int n;
    scanf("%d",&n);
    char s[n];
    scanf("%s",s);
    int ans = n;
    for (int i = 1;i<n;i++){
        if(s[i]==s[i-1]){
            ans --;

        }
   
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 256