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

using namespace std;

int rang[510][510],f[510][510];
int main()
{
    int n,m,q;
    scanf("%d%d%d",&n,&m,&q);
        
    int l,r;
    for(int i=0;i<m;i++){
        scanf("%d%d",&l,&r);
        rang[l][r]++;
    }
            
    for(int i=n; i>=1; i--) {
        for(int j=1; j<=n; j++) {
            f[i][j] =rang[i][j]+f[i+1][j]+f[i][j-1]-f[i+1][j-1];
        }
    }

    while(q--){
        scanf("%d%d",&l,&r);
        printf("%d\n",f[l][r]);
    }


    return 0;
}

Measured memory_bytes: 2944
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

vector<LL> vs;

int main(){
	LL n,m;
	int i,j,k;
	LL a,b,c;
	cin>>n;
	n++;
	b=85;
	for(i=0;i<40;i++){
		a=(LL)1<<i;
		if(n<a*2)break;
		if(n&a)vs.push_back(b--);
		vs.push_back(i+1);
	}
	for(i=0;i<85;i++){
		vs.push_back(i+1);
	}
	cout<<vs.size()<<endl;
	array_show(vs);
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val s = sc.next()
    println(problem037a(s))
}

fun problem037a(s: String): Int {
    var count = 1
    var prev = s[0].toString()
    var current = ""
    for (i in 1 until s.length) {
        current += s[i]
        if (prev != current) {
            prev = current
            current = ""
            count++
            continue
        }
    }
    return count
}

Measured memory_bytes: 39840
#include<bits/stdc++.h>
using namespace std;
struct SegmentTree
{
  vector< set< pair< int, int > > > seg, add;
  int sz;
  SegmentTree(int n)
  {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz - 1, set< pair< int, int > >());
    add.assign(2 * sz - 1, set< pair< int, int > >());
  }
  bool Check(set< pair< int, int > >& seg, int x, int y)
  {
    if(!seg.empty()) {
      auto pos = seg.lower_bound({x, y});
      if(pos != seg.begin()) {
        --pos;
        if(pos -> second > x) return(true);
        ++pos;
      }
      if(pos != seg.end()) {
        if(pos -> first < y) return(true);
      }
    }
    return(false);
  }
  bool Query(const int a, const int b, const int x, const int y, int k, int l, int r)
  {
    if(a >= r || b <= l) return(false);
    if(a <= l && r <= b) return(Check(seg[k], x, y) || Check(add[k], x, y));
    return(Check(add[k], x, y) || Query(a, b, x, y, 2 * k + 1, l, (l + r) >> 1) || Query(a, b, x, y, 2 * k + 2, (l + r) >> 1, r));
  }
  bool Query(int a, int x, int b, int y)
  {
    return(Query(a, b, x, y, 0, 0, sz));
  }
  inline void Insert(set< pair< int, int > >& seg, const int x, const int y)
  {
    if(seg.empty()) {
      seg.insert({x, y});
    } else {
      bool flag = true;
      pair< int, int > range(x, y);
      while(!seg.empty() && flag) {
        auto pos = seg.lower_bound(range);
        flag = false;
        if(pos != seg.begin()) {
          --pos;
          if(pos -> second > x) {
            range = {min(pos -> first, range.first), max(pos -> second, range.second)};
            flag = true;
            pos = seg.erase(pos);
          } else {
            ++pos;
          }
        }
        if(pos != seg.end()) {
          if(pos -> first < y) {
            range = {min(pos -> first, range.first), max(pos -> second, range.second)};
            flag = true;
            seg.erase(pos);
          }
        }
      }
      seg.insert(range);
    }
  }
 
  void Add(const int a, const int b, const int x, const int y, int k, int l, int r)
  {
    if(a >= r || b <= l) return;
    if(a <= l && r <= b) {
      Insert(add[k], x, y);
      return;
    }
    Add(a, b, x, y, 2 * k + 1, l, (l + r) >> 1);
    Add(a, b, x, y, 2 * k + 2, (l + r) >> 1, r);
    Insert(seg[k], x, y);
  }
  void Add(int a, int x, int b, int y)
  {
    Add(a, b, x, y, 0, 0, sz);
  }
};
 
 
int main()
{
  int W, H, N;
  scanf("%d %d", &W, &H);
  SegmentTree tree(100000);
  scanf("%d", &N);
  long long sum = 0;
  while(N--) {
    int x1, y1, x2, y2;
    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
    --x1, --y1;
    if(!tree.Query(x1, y1, x2, y2)) {
      sum += 1LL * (x2 - x1) * (y2 - y1);
      tree.Add(x1, y1, x2, y2);
    }
    printf("%lld\n", sum);
  }
}

Measured memory_bytes: 189492
object Main {

  def main(args: Array[String]): Unit = {
    import scala.io.StdIn._
    val Array(n, l) = readLine().split(" ").map(_.toInt)
    val S: Array[String] = (0 until n).map(_ => readLine()).toArray
    println(S.sorted.mkString)
  }

}


Measured memory_bytes: 25544
<?php
$in = trim(fgets(STDIN));  
$a=["R","U","D"];$b=["L","U","D"];
$ans = "Yes";
for($i=0; $i < strlen($in); $i++) {
  if(($i%2==0) && !in_array($in[$i], $a, true)) {$ans="No"; break;}
  if(($i%2==1) && !in_array($in[$i], $b, true)) {$ans="No"; break;}
}
echo $ans;

Measured memory_bytes: 4728
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#define maxn 200005
using namespace std;
int n, b[maxn], arr[maxn], s[maxn], real[maxn];
map <int, int> mp;
int C[maxn];
void add(int x){
	for (; x <= 2 * n + 1; x += x & -x)
		C[x] ++;
}
int sum(int x){
	int ans = 0;
	for (; x; x -= x & -x)
		ans += C[x];
	return ans;
}
int main(){
	cin >> n;
	long long ok = (1LL * (n + 1) * n / 2 + 1) / 2;
	for (int i = 1; i <= n; ++ i){
		scanf("%d", &b[i]);
		arr[i] = b[i];
	}
	sort(arr + 1, arr + 1 + n);
	int M = 0;
	for (int i = 1; i <= n; ++ i)
		if (arr[i] != arr[i - 1]){
			mp[arr[i]] = ++ M;
			real[M] = arr[i];
		}
	for (int i = 1; i <= n; ++ i)
		b[i] = mp[b[i]];
	int l = 1, r = M, ans;
	while (l <= r){
		int m = l + r >> 1;
		for (int i = 1; i <= n; ++ i)
			s[i] = s[i - 1] + (b[i] >= m ? 1 : -1);
		for (int i = 1; i <= 2 * n + 1; ++ i)
			C[i] = 0;
		long long cnt = 0;
		add(n + 1);
		for (int i = 1; i <= n; ++ i){
			cnt += sum(s[i] + n + 1);
			add(s[i] + n + 1);
		}
		if (cnt >= ok){
			ans = m;
			l = m + 1;
		}
		else
			r = m - 1;
	}
	cout << real[ans] << endl;
}


Measured memory_bytes: 7296
#include<iostream>
#include<cstring>
using namespace std;
main(){
  int now,k,i=0,n;
  char c[1024];
  cin>>c;
  k=-3;
  n=strlen(c);
  while(i<n){
    now=k;
    now-=('Z'-c[i]);
    c[i]+=('Z'-c[i]);
    now=now%('Z'-'A'+1);
    c[i]+=now;
    i++;
  }
  cout<<c<<endl;
  return 0;
}

Measured memory_bytes: 1140
#include<bits/stdc++.h>
// Useful constants
#define INF  (int)1e9
#define EPS   1e-9
#define MOD 1000000007ll
#define PI 3.14159
// for input-output
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
// iteration macros: have advantage of auto-casting and not recomputing arguments
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
// input macro
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}
//output macro
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
// shortcut for data type
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define uset unordered_set
#define umap unordered_map
//--namespace
using namespace std;
//--useful function
ll gcd(ll a, ll b){ll temp;while (b > 0){temp = a%b;a = b;b = temp;} return a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}
// --clock funtion
clock_t time_p=clock();
void TimeTaken()
{
    time_p=clock()-time_p;
    cerr<<"Completion time : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
// --solve function
void solve() {

}
//--main function
int main(){
	int n,m,a,b;
	cin>>n>>m;
	int arr[n+1]={0};
	REP(i,1,m)
	{
		cin>>a>>b;
		arr[a]++;
		arr[b]++;
	}
	REP(i,1,n)
	{
		cout<<arr[i]<<"\n";
	}
	return 0;

//   TimeTaken();
}


Measured memory_bytes: 384
def main():
	N = int(input())
	A= list(map(int, input().split()))
	pos = []
	neg = []
	ans = 0
	min_neg = 10**9
	min_pos = 10**9
	for i in range(N):
		if A[i] > 0:
			pos.append(A[i])
			min_pos = min(min_pos, A[i])
		else:
			neg.append(-A[i])
			min_neg = min(min_neg, -A[i])
	ans = sum(neg)+sum(pos)
	if len(neg)%2 == 1:
		ans -= 2*min(min_pos, min_neg) 
	print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 14412
#include <bits/stdc++.h>
#define forn(i,n) for(int i=0;i<int(n);i++)
#define rforn(i,n) for(int i = int(n) - 1; i >= 0; --i)

using namespace std;
typedef long long ll;

int N;
ll A;
ll B;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> A >> B;

    ll C = A * B;
    C /= __gcd(A, B);
    cout << C << endl;

}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <vector>
#include <cassert>
#include <fstream>
#include <algorithm>
#include <list>
#include <random>
#include <ctime>
#include <cmath>
#include <random>
#include <bitset>
#include <complex>
#pragma unroll
#pragma loop count N
#pragma ivdep
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
//#define int ll
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ld, ld> pld;
typedef complex<double> base;

#define mmin(a, b) a = min(a, (b))
#define mmax(a, b) a = max(a, (b))
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define ALL(a) a.begin(),a.end()
#define sqr(x) (x) * (x)
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define cint const int &
#define SZ(a) ((int)(a.size()))
#define f(cnt) (((cnt) + 1) * (cnt) / 2)
#define watch(x) cout << (#x) << " = " << x << endl;

const double PI = 2 * acos(0.0);

template<class T>
void show(const set<T> &a) {
    for (T x : a)
        cout << x << " ";
    cout << endl;
}

template<class T>
void show(const vector<T> &a) {
    for (T x : a)
        cout << x << " ";
    cout << endl;
}

int n;
const int N = 37;
string s;
string a, inv;

int ans;
typedef pair<string, int>  psi;

map<psi, int> get(string s, bool sec) {
    map<psi, int> ret;
    for (int mask = 0; mask < (1 << n); ++mask) {
        string a = "";
        string b = "";
        for (int i = 0; i < n; ++i) {
            if ((mask >> i) & 1) {
                a += s[i];
            } else {
                b += s[i];
            }
        }
        reverse(ALL(b));
        psi key;
        if (!sec)
            key = mp(a + b, SZ(a));
        else
            key = mp(b + a, n - SZ(a));
        ret[key]++;
    }
    return ret;
};


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


    cin >> n;
    fori (i, n) {
        a += char(0);
        inv += char(0);
    }
    cin >> s;
    map<psi, int> cnt1, cnt2;
    cnt1 = get(s.substr(0, n), 0);
    cnt2 = get(s.substr(n, n), 1);
    ll ans = 0;
    for (auto x : cnt1) {
        ans += 1LL * x.second * cnt2[x.first];
    }
    cout << ans;
}


Measured memory_bytes: 84608
N, M = map(int, input().split())
s = input()
ans = []
cur = N
while cur != 0:
    for step in range(M, 0, -1):
        if cur - step < 0:
            continue
        if s[cur-step] == '1':
            continue
        ans.append(step)
        cur -= step
        break
    else:
        print(-1)
        exit()
print(*ans[::-1])


Measured memory_bytes: 11372
"use strict";

function Main(input) {
    input=input.replace("\n","");
    parseInt(input);
    console.log(input*input*Math.PI+" "+input*2*Math.PI);
}
    
function debug(){
	var input = document.getElementById("input").value;
	Main(input);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

using LL = long long;
const LL M = 1e9+7;

string L;

map<pair<int,bool>, LL> memo;
LL dp(int i, bool eq) {
  if(i == L.size()) return 1;
  auto p = make_pair(i, eq);
  if(memo.count(p)) return memo[p];
  LL res = 0;
  if(eq) {
    if(L[i] == '1') res += 2 * dp(i+1, true) + dp(i+1, false);
    else            res += dp(i+1, true);
    res %= M;
  } else {
    res += 3 * dp(i+1, false);
    res %= M;
  }
  return memo[p] = res;
}

int main() {
  cin >> L;
  cout << dp(0, true) << endl;
}


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

int main(){
	int N;
	long long x,ans=0;
	cin >> N >> x;
	vector<long long> a(N);
	for(auto &i:a)cin >> i;
	for(int i=0;i<N;i++){
		if(a[i]>x){
			ans+=a[i]-x;
			a[i]=x;
		}
		if(i>0 && a[i]+a[i-1]>x){
			ans+=a[i]+a[i-1]-x;
			a[i]=x-a[i-1];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
/*
    Washief Hossain Mugdho
    17 September 2020
    Educational DP LCS
*/

#ifndef DEBUG
#pragma GCC optimize("O3")
#endif

#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define fastio ios_base::sync_with_stdio(0)
#define untie cin.tie(0)
#define ms(a, b) memset(a, b, sizeof a)
using namespace std;
string s, t;

int main()
{
#ifdef LOCAL_OUTPUT
    freopen(LOCAL_OUTPUT, "w", stdout);
#endif
#ifdef LOCAL_INPUT
    freopen(LOCAL_INPUT, "r", stdin);
#endif
    cin >> s >> t;
    int memo[s.size() + 1][t.size() + 1];
    ms(memo, 0);
    for (int i = s.size() - 1; i >= 0; i--)
        for (int j = t.size() - 1; j >= 0; j--)
        {
            if (s[i] == t[j])
                memo[i][j] = memo[i + 1][j + 1] + 1;
            else
                memo[i][j] = max(memo[i + 1][j], memo[i][j + 1]);
        }
    int a = 0, b = 0;
    while (a < s.size() && b < t.size())
    {
        if (s[a] == t[b])
        {
            cout << s[a];
            a++;
            b++;
        }
        else if (memo[a + 1][b] > memo[a][b + 1])
            a++;
        else
            b++;
    }
    cout << endl;
}


Measured memory_bytes: 38676
## coding: UTF-8
##区間スケジューリング問題

N,M = map(int,input().split())

graph = []
for i in range(M):
    graph.append(list(map(int, input().split())))
#print(graph)

itv = []
for i in range(M):
    itv.append([graph[i][1] - 1, graph[i][0]])

itv = sorted(itv)
#print(itv)

tt = 0 #終点を保持
ans = 0
for i in range(M):
    #print('i:{},tt:{}, itv[i]:{}'.format(i, tt, itv[i]))
    #起点が現状の終点よりも後ろだったらその区間は満たしてやらないといけない
    #満たすのはその区間の終点でいい。なぜなら終点でソートしているので、その区間の終点を満たしてやったとしてもでこれから先に出てくる区間を抜かしてしまうことはないし、最大効率で他の区間も充たせるから
    if(itv[i][1] > tt):
        tt = itv[i][0]
        ans += 1
        #print('ans:{}, tt:{}'.format(ans, tt))
print(ans)



Measured memory_bytes: 39068
import sys
input = sys.stdin.readline

N, M = map(int,input().split())
a = []
c = []
for i in range(M):
    a_,b=map(int,input().split())
    a.append(a_)
    c_tmp = list(map(int, input().split()))
    tmp=0
    for j in range(len(c_tmp)):
        tmp+=2**(c_tmp[j]-1)
    c.append(tmp)
INF = N*1e+6
dp = [INF]*2**N
dp[0]=0

for i in range(2**N):
    for j in range(M):
        dp[i|c[j]]=min(dp[i|c[j]], dp[i]+a[j])
if dp[2**N-1]==INF:
    print(-1)
    sys.exit()
print(dp[2**N-1])



Measured memory_bytes: 42716
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};

//全二点間の距離
//ヨ i,d[i][i]<0なら負の閉路
int MAX_dist=1e9+7;
int V=0;
vector<vector<int>> d(0,vector<int>(0,MAX_dist));//d[x][y]:=x->yのcost,枝が無ければMAX_dist,d[i][i]=0

void init(int n){
    d=vector<vector<int>>(n,vector<int>(n,MAX_dist));
    rep(i,n) d[i][i]=0;
    V=n;
}

void warshall(){
    rep(k,V){
        rep(i,V){
            if(d[i][k]==MAX_dist) continue;
            rep(j,V){
                if(d[k][j]==MAX_dist) continue;
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
}

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int h,w;
    cin>>h>>w;
    init(10);
    rep(i,10)rep(j,10) cin>>d[i][j];
    map<int,int> a;
    int x;
    rep(i,h)rep(j,w){
        cin>>x;
        a[x] ++;
    }
    warshall();
    int ans=0;
    rep(i,10) ans +=a[i]*d[i][1];
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }
template<class T>
ostream &operator<<(ostream &os,const vector<T> &v){
	for(int i = 0;i < v.size();i++) os << (i ? "," : "[") << v[i];
	os << "]";
	return os;
}

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }

const int INF=1e+18;
const double EPS=1e-9;
const int MOD=998244353;

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

template<long long mod = 1000000007>
struct modint{
	long long a;

	modint() : a(0){}
	modint(long long t){
		a = t % mod;
		if(a < 0) a += mod;
	}

	operator long long() const{ return a; }

	bool operator==(const modint &x) const{ return a == x.a; }
	bool operator!=(const modint &x) const{ return a != x.a; }

	modint operator-() const{ return modint(a ? (mod - a) : 0); }
	modint operator~() const{ return pow(mod - 2); }

	modint operator+(const modint &x) const{ return modint(*this) += x; }
	modint operator-(const modint &x) const{ return modint(*this) -= x; }
	modint operator*(const modint &x) const{ return modint(*this) *= x; }
	modint operator/(const modint &x) const{ return modint(*this) /= x; }

	modint &operator+=(const modint &x){
		a += x.a;
		if(a >= mod) a -= mod;
		return *this;
	}
	modint &operator-=(const modint &x){
		a -= x.a;
		if(a < 0) a += mod;
		return *this;
	}
	modint &operator*=(const modint &x){
		a = a * x.a % mod;
		return *this;
	}
	modint &operator/=(const modint &x){
		a = a * (~x).a % mod; 
		return *this;
	}

	friend ostream &operator<<(ostream &os,const modint &x){
		return os << x.a;
	}
	friend istream &operator>>(istream &is,modint &x){
		long long t;
		is >> t;
		x = modint(t);
		return is;
	}

	modint pow(long long x) const{
		modint ret = 1,tmp = a;
		for(;x;tmp *= tmp,x >>= 1){
			if(x & 1) ret *= tmp;
		}
		return ret;
	}
};

signed main(){
	int n,s,a[3010];
	modint<MOD> dp[3010][3010][3],ans = 0;
	cin >> n >> s;
	for(int i = 0;i < n;i++) cin >> a[i];
	dp[0][0][0] = 1;
	for(int i = 0;i < n;i++){
		for(int j = 0;j <= s;j++){
			for(int k = 0;k < 3;k++){
				dp[i + 1][j][k] += dp[i][j][k];
				if(k == 1 && j + a[i] <= s) dp[i + 1][j + a[i]][k] += dp[i][j][k];
				if(k != 2){
					dp[i + 1][j][k + 1] += dp[i][j][k];
					if(j + a[i] <= s) dp[i + 1][j + a[i]][k + 1] += dp[i][j][k];
				}
				if(k == 0){
					dp[i + 1][j][2] += dp[i][j][k];
					if(j + a[i] <= s) dp[i + 1][j + a[i]][2] += dp[i][j][k];
				}
			}
		}
	}
	cout << dp[n][s][2] << endl;
}


Measured memory_bytes: 212608
K, S = list(map(int, input().split()))
#Kは上限、S=X+Y+Z 0<=X,Y,Z<=K
x, y = 0, 0
ans = 0
#z = S - x - y
for i in range(0, K+1):
    x = i
    for j in range(0, K+1):
        y = j
        z = S - x - y
        if 0 <= z <= K:
            ans += 1
        else:
            pass
print(ans)

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

int main() {
  int n;
  cin >> n;
  int length = 1;
  int ans = 0;
  vector<int> slime(n);
  for(int i=0;i<n;i++) cin >> slime[i];

  for(int i=0;i<n-1;i++) {
    if(slime[i] == slime[i+1]) length++;
    else {
      ans += length /2;
      length = 1;
    }

    if(i == n - 2) ans += length / 2;
  }

  cout << ans << endl;
}

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

int main(){
	string s;
	cin >> s;
	int rcount = 0;
	rep(i,3) if(s[i] == 'R') rcount++;
	if(s == "RSR") cout << 1 << endl;
	else cout << rcount << endl;
    return 0;
}

Measured memory_bytes: 3572
import java.util.*;

public class Main {	
	public static void main(String[] args) {
		ArrayList<Integer> L = new ArrayList<>();
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		for(int i=0;i<N;i++)
			L.add(sc.nextInt());
		sc.close();
		Collections.sort(L);
		int count=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(judgeTriangle(L.get(i),L.get(j),L.get(k))==true)
					count++;
				}
			}
		}
		System.out.println(count);
	}
	
	static public boolean judgeTriangle(int a,int b,int c){
		if(a<b&&b<c&&(a+b>c)) {
			return true;
		}
		else
			return false;
	}
}


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

int main(void) {
  int N;
  unsigned long long D;
  long long X[300000], Y[300000];
  int cnt=0;
  
  scanf("%d%llu", &N, &D);
  for(int i = 0; i < N; i++)
    scanf("%lld%lld", X+i, Y+i);
  
  D *= D;
  for(int i = 0; i < N; i++)
    if(X[i]*X[i] + Y[i]*Y[i] <= D)
      cnt++;
  
  printf("%d\n", cnt);
  
  return 0;
}

Measured memory_bytes: 4856
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, X):
    if N % 2 == 0 and X == N//2:
        return 3*X
    ans = 0
    if X > N//2:
        X = N-X

    ans = X

    def f(n, x):
        # print(n, x)
        ans = 0
        ans += n
        n_x = n // x
        ans += 2*n_x*x - x
        if n % x != 0:
            ans += f(x, n - n_x*x)

        # print(n, x, n_x, 2*n_x*x - x, ans)
        return ans

    return ans + f(N-X, X)


def main():
    N, X = read_int_n()
    print(slv(N, X))

  

if __name__ == '__main__':
    main()


Measured memory_bytes: 5448
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <deque>
#include <vector>
using namespace std;

#define FILL(a, n, x) memset((a), (x), sizeof ((a)[0]) * (n))
#define FILLA(a, x) memset((a), (x), sizeof (a))
#define COPY(a, n, b) memcpy((b), (a), sizeof ((a)[0]) * (n))
#define COPYA(a, b) memcpy((b), (a), sizeof (a))

typedef unsigned long long lu;
const int mod = 1e9 + 7;

inline int Add(int x) { return x >= mod ? x - mod : x; }
inline void Add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
inline int Sub(int x) { return x < 0 ? x + mod : x; }
inline void Sub(int &x, int y) { x = Sub(x - y); }
inline int Mul(int x, int y) { return (int)((lu)x * y % mod); }
inline int Mul(int x, int y, int z) { return (int)((lu)x * y % mod * z % mod); }

int Pow(int x, int y) {
  int z = 1;
  for (; y; y >>= 1) {
    if (y & 1) z = Mul(z, x);
    x = Mul(x, x);
  }
  return z;
}

int Inv(int x) { return Pow(x, mod - 2); }

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

const int maxn = 50;

int n;
int ans[maxn + 1] = {0,1,2,12,84,770,8340,106400,1546888,25343766,461133960,232367169,627905865,632459808,928262728,919805769,382796331,887217496,639768068,869694124,205875097,205589953,487772376,239955313,998339621,31622834,902930073,146839084,449786840,982224660,865803735,21834818,721531716,26008837,471774471,69010090,700009308,776938882,645550477,526939604,142728157,654489641,128201240,185493259,789721045,977049419,589149550,700648836,25087729,874433491,352791804};

int main(void) {
  scanf("%d", &n);
  printf("%d\n", ans[n]);
  return 0;
}


Measured memory_bytes: 128
N = int(input())
#maze = [[0] * (N + 10) for _ in range(2)]
maze = [list(map(int, input().split())) for _ in range(2)]

dp = [[0] * N for _ in range(2)]

dp[0][0] = maze[0][0]
for j in range(1, N):
    dp[0][j] = dp[0][j - 1] + maze[0][j]

dp[1][0] = dp[0][0] + maze[1][0]

for i in range(1, N):
    dp[1][i] = max(dp[0][i] + maze[1][i], dp[1][i - 1] + maze[1][i])

print(dp[1][N - 1])

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))
#define BUF_SIZE 30

// size: specify sizeof(str)
int get_str(char *str, int size) {
    if(!fgets(str, size, stdin)) return -1;
    return 0;
}

int get_int(void) {
  int num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%d", &num);
#else
#error
#endif
  return num;
}

int get_int2(int *a1, int *a2) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d", a1, a2);
#else
#error
#endif
  return 0;
}

int get_int3(int *a1, int *a2, int *a3) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d %d", a1, a2, a3);
#else
#error
#endif
  return 0;
}
#define VERTEX_MAX 100000

struct list {
    int dst;
    int length;
    struct list *next;
};

struct list *create_graph(int vs) {
    static struct list graph[VERTEX_MAX];
    int i;
    for(i = 0; i < vs; i++) {
        graph[i].next = &graph[i];
    }
    return graph;
}

void add_list(struct list *head, int dst, int len) {
    struct list *elem = malloc(sizeof(struct list));
    elem->next = head->next;
    head->next = elem;
    elem->dst = dst;
    elem->length = len;
}

enum {
    ENUM_NONE,
    ENUM_WHITE,
    ENUM_BLACK,
};

int next_color(int color) {
    if(color == ENUM_WHITE) return ENUM_BLACK;
    if(color == ENUM_BLACK) return ENUM_WHITE;
    return ENUM_NONE;
}

static char check[VERTEX_MAX];
void dfs(struct list *graph, int this, int parent, int color) {
    struct list *head = &graph[this];
    check[this] = color;
    struct list *elem;
    for(elem = head->next; elem != head; elem = elem->next) {
        int dst = elem->dst;
        if(dst == parent) continue;
        dfs(graph, dst, this, elem->length%2 ? next_color(color) : color);
    }
    return;
}

int main(void) {
    int vs = get_int();
    int es = vs - 1;
    int i;
    struct list *graph = create_graph(vs);
    for(i = 0; i < es; i++) {
        int v1, v2, len;
        get_int3(&v1, &v2, &len);
        v1--; v2--;
        add_list(&graph[v1], v2, len);
        add_list(&graph[v2], v1, len);
    }

    dfs(graph, 0, -1, ENUM_WHITE);
    for(i = 0; i < vs; i++) {
        printf("%d\n", check[i]-1);
    }
    return 0;
}

Measured memory_bytes: 10752
#coding:utf-8
from collections import deque
K=int(input())
L=deque([1,2,3,4,5,6,7,8,9])
cnt=0
x=0
for _ in range(K):
	cnt+=1
	x=L.popleft()
	if x%10 !=0:
		L.append(10*x+x%10-1)
	L.append(10*x+x%10)
	if x%10!=9:
		L.append(10*x+x%10+1)

print(x)


Measured memory_bytes: 11908
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
using namespace std;
const int maxn=100000+10;
int a[maxn*2],b[maxn*2];
bool bz[maxn*2];
int i,j,k,l,r,mid,t,n,m;
bool check(int ans){
	int i,j,k,t;
	fo(i,1,2*n-1) b[i]=(a[i]>ans);
	fo(i,1,2*n-1) bz[i]=0;
	fo(i,1,2*n-2)
		if (b[i]==b[i+1]) bz[i]=bz[i+1]=1;
	if (b[n]==0&&bz[n]) return 1;//case 1,0 in middle
	fd(j,n,0)
		if (!j||bz[j]) break;
	fo(k,n,2*n)
		if (k>2*n-1||bz[k]) break;
	if (j&&k<=2*n-1){
		if (b[j]==0&&b[k]==0) return 1;//case 2,left and right are both 0
		if (b[j]==1&&b[k]==0&&k-n<n-j) return 1;
		if (b[j]==0&&b[k]==1&&n-j<k-n) return 1;//case 3,one side is 1 and another side is 0,0 nearer
	}
	else{
		if (j&&b[j]==0) return 1;
		if (k<=2*n-1&&b[k]==0) return 1;//case 4,only one side have 0
		t=0;
		fo(i,1,2*n-1)
			if (!b[i]) t++;else t--;
		if (t>0) return 1;//case 5,have no
	}
	return 0;
}
int main(){
	scanf("%d",&n);
	fo(i,1,2*n-1) scanf("%d",&a[i]);
	l=1;r=2*n-1;
	while (l<r){
		mid=(l+r)/2;
		if (check(mid)) r=mid;else l=mid+1;
	}
	printf("%d\n",l);
}

Measured memory_bytes: 1920
#include <stdio.h>

void insertionSort(int *, int, int);

int cnt;

int main(void)
{
	int i, n, m, h, A[1000000], G[100];
	
	scanf("%d",&n);
	for (i=0; i<n; i++) {
		scanf("%d",&A[i]);
	}
	
	cnt = 0;
	h = 1;
	for (m=1; h<=n/9; m++) {
		h = 3*h + 1;
	}
	for (i=0; i<m; i++) {
		G[i] = h;
		h /= 3;
	}
	for (i=0; i<m; i++) {
		insertionSort(A, n, G[i]);
	}
	
	printf("%d\n",m);
	for (i=0; i<m-1; i++) {
		printf("%d ",G[i]);
	}
	printf("%d\n",G[m-1]);
	printf("%d\n",cnt);
	for (i=0; i<n; i++) {
		printf("%d\n",A[i]);
	}
	
	return 0;
}

void insertionSort(int *A, int n, int g)
{
	int i, j, v;
	
	for (i=g; i<n; i++) {
		v = A[i];
		j = i - g;
		while ( j >= 0 && A[j] > v ) {
			A[j+g] = A[j];
			j = j - g;
			cnt++;
		}
		A[j+g] = v;
	}
}

Measured memory_bytes: 4504
#include <bits/stdc++.h>
using namespace std;
// ----------------------R00TDADA------------------------------
#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (a); i > (b); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada ios_base::sync_with_stdio(false)
#define int long long
#define M 1000000007
#define MAX 100005
int A[MAX], tree[4 * MAX];
int power(int x, int p)
{
    if (p == 0)
        return 1;
    int y = power(x, p / 2);
    y *= y;
    y %= M;
    if (p % 2 == 0)
        return y;
    y *= x;
    y %= M;
    return y;
}
void build(int node, int start, int end)
{
    if (start == end)
        //Leaf node will have a single element
        tree[node] = start;
    else
    {
        int mid = (start + end) / 2;
        //Recurse on the left child
        build(2 * node, start, mid);
        //Recurse on the right child
        build(2 * node + 1, mid + 1, end);
        // Internal node will have the sum of both of its children
        tree[node] = tree[2 * node] + tree[2 * node + 1];
    }
}
void update(int node, int start, int end, int idx, int val)
{
    if (start == end)
    {
        //Leaf Node
        A[idx] = val;
        tree[node] += val;
    }
    else
    {
        int mid = (start - end) / 2 + end;
        if (start <= idx && idx <= mid)
        {
            // If idx is in the left child, recurse on the left child
            update(2 * node, start, mid, idx, val);
        }
        else
        {
            // if idx is in the right child, recurse on the right child
            update(2 * node + 1, mid + 1, end, idx, val);
        }
        // Internal node will have the sum of both of its children
        tree[node] = tree[2 * node] + tree[2 * node + 1];
    }
}
int query(int node, int start, int end, int l, int r)
{
    if (r < start || l > end)
    {
        // range represented by a node is completely outside the given range
        return 0;
    }
    if (l <= start && end <= r)
    {
        // range represented by a node is completely inside the given range
        return tree[node];
    }
    // range represented by a node is partially inside and partially outside the given range
    int mid = (start + end) / 2;
    int p1 = query(2 * node, start, mid, l, r);
    int p2 = query(2 * node + 1, mid + 1, end, l, r);
    return p1 + p2;
}

signed main()
{

    rootdada;
    int n;
    cin >> n;
    int start = sqrt(n);
    int flag = 0;
    int ans = 0;
    int b;
    for (int i = start; i >= 0; i--)
    {
        if (n % i == 0)
        {
            flag = 1;
            ans = n / i;
            b = i;
            break;
        }
    }
    cout << b + ans - 2 << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	class P{
		int s;
		int c;
		P(int s, int c){
			this.s=s;
			this.c=c;
		}
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();

		ArrayList<P> p = new ArrayList<P>();
		for(int i=0; i<m; i++) {
			p.add(new P(sc.nextInt(),sc.nextInt()));
		}

		for(int i=0; i<1000; i++) {
			ArrayList<Integer> d = new ArrayList<Integer>();
			d.add(i%10);
			int ni = i/10;
			int keta=1;
			while(ni>0) {
				d.add(0,ni%10);
				ni /= 10;
				keta++;
			}
			if(keta != n) continue;

			boolean ok = true;
			for(int j=0 ;j<p.size(); j++) {
				int s = p.get(j).s;
				int c = p.get(j).c;
				if(d.get(s-1) != c) {
					ok = false;
				}
			}
			if(ok) {
				System.out.println(i);
				sc.close();
				return;
			}
		}
		System.out.println(-1);
		sc.close();
	}
}


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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;
const int INF = 2147483647;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//myfuncs
//素数判定
template<class T> inline T isPrime(T x) {
    bool ret = true;
    if (x < 2) {
        ret = false;
    }
    for (LL i = 2; i <= sqrt(x); i++) {
        if (x%i == 0) {
            ret = false;
        }
    }
    return ret;
}

//Union FInd
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

//main code

int main(int argc, char const* argv[])
{
    int n;
    cin >> n;
    int f[n][10];
    int p[n][11];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> f[i][j];
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 11; j++) {
            cin >> p[i][j];
        }
    }

    LL ans = INT64_MIN;
    for (int i = 1; i < (1 << 10); i++) {
        LL kouho = 0;
        for (int store = 0; store < n; store++) {
            int count = 0;
            for (int j = 0; j < 10; j++) {
                if (i & (f[store][j] << j)) {
                    count++;
                }
            }
            kouho += p[store][count];
        }
        ans = max(ans,kouho);
    }

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


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

int main() {
  int n;
  cin >> n;
  int a = 1;
  while (a * 2 <= n) {
    a *= 2;
  }
  cout << a << endl;
  return 0;
}

Measured memory_bytes: 3576
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

void makePrimeNumber(int N, vector<bool>& prime) // 0ツ暗按湘」Nツ暗按可コツづ個青ョツ青板つゥツづァツ素ツ青板づーツ探ツつキ
{
    prime.assign(N+1, true);
    prime [0] = prime[1] = false;
    for(int i=2; i*i<=N; i++){
        if(prime[i]){
            for(int j=i; i*j<=N; j++){
                prime[i*j] = false;
            }
        }
    }
}

int main()
{
    vector<bool> prime;
    makePrimeNumber(50000, prime);

    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        int ret = 0;
        for(int i=0; i<=n/2; ++i){
            if(prime[i] && prime[n-i])
                ++ ret;
        }
        cout << ret << endl;
    }
}

Measured memory_bytes: 916
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())

total = 0

for i in range(n):
    if i < k:
        if t[i] == "r":
            total += p
        elif t[i] == "s":
            total += r
        else:
            total += s
    else: # i >= k
        if t[i-k] == t[i]:
            t[i] = "."
        else:
            if t[i] == "r":
                total += p
            elif t[i] == "s":
                total += r
            else:
                total += s

print(total)

Measured memory_bytes: 4084
using System;
using System.IO;

namespace ABC122A
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                Console.SetIn(new StreamReader(args[0]));
            }

            new Program().Solve();
        }

        void Solve()
        {
            var b = Console.ReadLine();
            var ans = "";

            if (b == "A")
            {
                ans = "T";
            }
            else if (b == "C")
            {
                ans = "G";
            }
            else if (b == "G")
            {
                ans = "C";
            }
            else if (b == "T")
            {
                ans = "A";
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll
#define INF 1e16
#define mod 1000000007
int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>21) cout<<"bust"<<endl;
    else cout<<"win"<<endl;
return 0;}

Measured memory_bytes: 256
# -*- coding:utf-8 -*-

S = input()
t = len(S)-1
ans = 0

for i in range(2**t):
    p = bin(i)[2:]
    p = "0"*(t-len(p))+p
    x = ""

    for j, k in enumerate(S):
        x += k
        if j != t and p[j] == "1":
            x += "+"
    # print(x)
    ans += eval(x)
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <algorithm>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define rep(i,n)	for(int i=0;i<n;i++)
#define srep(i,a,n)	for(int i=a;i<n;i++)
#define REP(i,n)	for(int i=0;i<=n;i++)
#define SREP(i,a,n)	for(int i=a;i<=n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define fst	first
#define scn second
#define bucnt(x)	__buildin__popcount(x)
#define debug(x)	cout<<"debug: "<<x<<endl;

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;
const ld eps = 1e-9;
const int dx[] = { 0,1,0,-1 };
const int dy[] = { 1,0,-1,0 };

int dp[60][30][2];

int main() {
	while (true) {
		int w, h;	cin >> w >> h;
		if (w == 0)	break;
		vector<string> s(h);
		rep(i, h) {
			rep(j, w) {
				char a;	cin >> a;
				s[i] = s[i] + a;
			}
		}
		rep(i, h)	rep(j, w)	dp[i][j][0] = dp[i][j][1] = mod;
		priority_queue<tuple<int, int, int, int>> pq;
		rep(i, w) {
			if (s[h - 1][i] == 'S') {
				dp[h - 1][i][0] = dp[h - 1][i][1] = 0;
				pq.push(mt(0, h - 1, i, 0));
				pq.push(mt(0, h - 1, i, 1));
			}
		}
		int ret = mod;
		while (!pq.empty()) {
			int cost, y, x, use;
			tie(cost, y, x, use) = pq.top();	pq.pop();
			cost *= -1;
			if (cost != dp[y][x][use])	continue;
			SREP(i, 1, 3) {
				SREP(j, i - 3, 3 - i) {
					int ny = y + j;
					int nx = x + (use == 0 ? i : -i);
					if (ny < 0 || h <= ny)	continue;
					if (nx < 0 || w <= nx)	continue;
					if (s[ny][nx] == 'S' || s[ny][nx] == 'X')	continue;
					if (s[ny][nx] == 'T') {
						dp[ny][nx][use ^ 1] = min(dp[ny][nx][use ^ 1], cost);
						ret = min(ret, dp[ny][nx][use ^ 1]);
					}
					if (dp[ny][nx][use ^ 1] > cost + (s[ny][nx] - '0')) {
						dp[ny][nx][use ^ 1] = cost + (s[ny][nx] - '0');
						pq.push(mt(-dp[ny][nx][use ^ 1], ny, nx, use ^ 1));
					}
				}
			}
		}
		ret = (ret == mod ? -1 : ret);
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
int n,a[1000002][3],dp1[1000006],dp2[1000006],dp3[1000006];
int main(){
	cin>>n;
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
			cin>>a[i][j];
	dp1[0]=a[0][0];
	dp2[0]=a[0][1];
	dp3[0]=a[0][2];
	for(int i=1;i<n;i++){
		dp1[i]=max(dp2[i-1],dp3[i-1])+a[i][0];
		dp2[i]=max(dp1[i-1],dp3[i-1])+a[i][1];
		dp3[i]=max(dp1[i-1],dp2[i-1])+a[i][2];
	}
	int ans=max(dp1[n-1],max(dp2[n-1],dp3[n-1]));
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 12928
#include<bits/stdc++.h>
using namespace std;
int main(){
  while(1){
      string a;
      cin >> a;
      if(a == "0") break;
      int x = 0;
      for(int i = 0; i< a.size(); i++){
          x += a[i] - '0';
      } 
      cout << x << endl;
  }
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 998244353;
string s;
int k;
int n;
int l[305];
ll mem[305][305][305][2];
ll dp(int id, int rem, int ex, int f){
	if (id == 0) return (ex == 0);
	if (mem[id][rem][ex][f] != -1) return mem[id][rem][ex][f];
	ll res = 0;
	if (s[id-1] == '1'){
		if (rem >= 1) res += dp(id-1,rem-1,ex+1,0);
		if (f == 0) res += dp(l[id],rem,ex,0);
	}
	else if (id == 1 || s[id-2] == '0'){
		res += dp(id-1,rem,ex,0);
		if (ex >= 1) res += dp(id,rem,ex-1,0);
	}
	else {
	    if (f == 0){
            res += dp(id-1,rem,ex,1);
	    }
		if (ex >= 1) res += dp(id,rem,ex-1,1);
		res += dp(l[id],rem,ex,0);
	}
	res %= mod;
	//printf("%d %d %d %lld\n",id,rem,ex,res);
	return mem[id][rem][ex][f] = res;
}
int main(){
	cin >> s >> k;
	n = (int)s.size();
	k = min(k,n);
	memset(mem,-1,sizeof(mem));
	int L = 0;
	for (int i = 1; i <= n; i++){
        l[i] = L;
        if (s[i-1] == '0') L = i;
	}
	printf("%lld",dp(n,k,0,0));

}


Measured memory_bytes: 447072
using System;

class Program
{
	static void Main(string[] args)
	{
		var inputValues = Console.ReadLine().Split(' ');
    var A = int.Parse(inputValues[0]);
    var B = int.Parse(inputValues[1]);
		var coins = 0;
		for(int i = 0; i <=1; i++)
		{
			if(A >= B)
			{
				coins += A;
				A += -1;
			}else{
				coins += B;
				B += -1;
			}
		}
		Console.WriteLine(coins);
	}
}

Measured memory_bytes: 13140
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int a,b,c;
inline int read(){
	int x=0,t=1,c;
	while(!isdigit(c=getchar())) if(c=='-') t=-1;
	while(isdigit(c)) x=x*10+c-'0',c=getchar();
	return x*t;
}
int main(){
	a=read(),b=read(),c=read();
	if(c>a && c<b || c>b && c<a) printf("Yes\n");else printf("No\n");
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		String t = sc.next();
		
		s = s + s;
		
		System.out.println((s.indexOf(t) > -1) ? "Yes" : "No");
		
	}

}


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

using namespace std;
using ll = long long;
using ld = long double;

const int MAX = 5100000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k;
    string s;
    cin >> k >> s;

    COMinit();

    ll ts[k+1];
    ll tf[k+1];
    ts[0]=1;
    tf[0]=1;
    for(int i = 0; i < k; i++) {
        ts[i+1]=(ts[i]*26)%MOD;
        tf[i+1]=(tf[i]*25)%MOD;
    }

    ll ans=0;
    int n=s.size()+k;


    for(int i = 0; i <= k; i++) {
        ll add=((ts[i]*tf[k-i])%MOD)*COM(n-i-1,n-k-1);
        ans+=(add%MOD);
    }
    cout << ans%MOD << "\n";
    return 0;
}

Measured memory_bytes: 139396