akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int x;
  cin>>x;
  ll ans=0;
  ans+=(x/500)*1000;
  x-=(x/500)*500;
  ans+=(x/5)*5;
  cout<<ans;
  return(0);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
using namespace  std;

#define int long long int



signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;

    map<int, int, greater<int>> m;
    for (int i = 0; i < N; i++) {
        int A; cin >> A;
        m[A]++;
    }

    while (M--) {
        int B, C; cin >> B >> C;
        m[C] += B;
    }

    int ans = 0;
    for (auto &p : m) {
        if (p.second <= N) {
            ans += p.first * p.second;
            N -= p.second;
        } else {
            ans += p.first * N;
            break;
        }
    }

    cout << ans << endl;
}

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

using namespace std;
int main(){
    int n,t,a;
    cin>>n>>t>>a;
    int ans=-1;
    double best=99999.0;
    rep(i,n) {
        int h;
        cin>>h;
        if (best>abs((double)a-((double)t-0.006*h))){
            best=abs((double)a-((double)t-0.006*h));
            ans=i;
        }
    }
    cout<<(ans+1)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;
const LL MOD = 1e9 + 7;

template<class T> inline bool chmin(T &a, T b){if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){if (a < b) {a = b; return true;} return false;}

int digit_sum(int a)
{
  string sa = to_string(a);
  int res = 0;
  REPx(x, sa) res += x - '0';
  return res;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int ans = INF;
  REP2(i, 1, n/2+1)
  {
    int a = i, b = n-i;
    chmin(ans, digit_sum(a) + digit_sum(b));
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char c; cin>>c;

    if(c == 'A') cout<<"T"<<endl;
    else if( c == 'T') cout<<"A"<<endl;
    else if(c == 'C') cout<<"G"<<endl;
    else cout<<"C"<<endl;

    return 0;
}

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

int main() {
  double A, B;
  cin >> A >> B;
  
  double mi, ma;
  mi = max(A / 0.08, B / 0.1);
  ma = min(A / 0.08 + 12, B / 0.1 + 9);
  if(mi != int(mi)) mi = int(mi) + 1;
  if(mi <= ma) cout << mi << endl;
  else cout << -1 << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
 	ll x;
 	cin>>x;
 	ll a  = x/500;
 	x%=500;
 	ll b = x/5;
 	x%=5;
 	cout<<b*5 + a*1000<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int N, K, Q, A[100005], B[100005], i;
    scanf("%d%d%d", &N, &K, &Q);
    for (i=1; i<=N; i++) {
        B[i]=0;
    }
    for (i=1; i<=Q; i++) {
        scanf("%d", &A[i]);
        B[A[i]]++;
    }
    for (i=1; i<=N; i++) {
        if (B[i]>=Q-K+1) printf("Yes");
        else printf("No");
        if (i<=N-1) printf("\n");
    }
    return 0;
}


Measured memory_bytes: 1280
#include <stdio.h>

int main()
{
  int a, b, c, d, e, max;

  scanf("%d %d\n", &a, &b);

  c = a+b;
  d = a-b;
  e = a*b;

  max = c;

  if(max<d){
    max = d;
  }

  if(max<e){
    max = e;
  }

  printf("%d\n", max);

  return 0;
}


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

char a[10], b[10];
 
int main(void) { 
	scanf("%s", a);
	scanf("%s", b);
	int len = strlen(a);
	int cnt = 0;
	for(int i=0;i<len;i++) {
	    if(a[i] == b[i])cnt ++;
	}
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #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 VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
    #define Vl vector<ll>
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
     
const ll MOD = 1e9 + 7;
const ll ZER = 0;

ll dp[200100];
int main(){
   int n;
   cin >> n;
   vector<ll> a(n);
   rep(i, n)cin >> a[i];

   ll sum = 0;
   rep(i, n){
       if(i == 0)continue;
       sum = (sum + a[i - 1]) % MOD;
       dp[i + 1] = (dp[i] + sum * a[i] % MOD) % MOD;
   }
   dp[n] %= MOD;
   cout << dp[n] << endl;
}


Measured memory_bytes: 5952
#len(s)//2-s.count("p")

iG = 0
iP = 0
iR = 0
for s in input().rstrip():
    if s == "g":
        if iP < iG:
            iR += 1
            iP += 1
        else:
            iG += 1
    else:
        if iP < iG:
            iP += 1
        else:
            iR -= 1
            iG += 1

print(iR)


Measured memory_bytes: 3188
import sys
sys.setrecursionlimit(10000)

h, w = list(map(int, input().split(" ")))
s = []
for i in range(h):
    s.append(input())

flag = 1
for i in range(h):
    for j in range(w):
        if(s[i][j] == "#"):
            if(i != 0 and s[i-1][j] == "#"):
                flag = 1
            elif(j != w-1 and s[i][j+1] == "#"):
                flag = 1
            elif(i != h-1 and s[i+1][j] == "#"):
                flag = 1
            elif(j != 0 and s[i][j-1] == "#"):
                flag = 1
            else:
                flag = 0
        if(flag == 0):
            print("No")
            exit()

print("Yes")

Measured memory_bytes: 3064
/*
          , -- 、
        /;;;;;;', 　　　
        i二二二i
      , ' 　    ヽ ???
     i　ﾉﾉﾉﾉﾉﾍ .', 　　
     〉ﾘi' ﾟ ヮﾟﾉﾚく　 WAyon..........
  ○⊂}〈lﾄ--ｲl〉{つ● 　　
      ,ｒ/ー i-ヽヽ 　　　
     ｀｀i_ﾗi_ﾗ
*/


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
const int INF=(long long)1e12;
const int mod=(int)1e9+7;
#define all(a) (a).begin(),(a).end()
typedef vector<vector<int>> graph;
int sz=262144;complex<double> y[262160],A[262160],B[262160];

void dft(complex<double> *x,bool inv);
#define P pair<int,int>



//始点、終点の設定は適宜やる
//(そのままだとqueueにはなにもないよ)
//int h,w;

signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
  /*  cin >>h>>w;
    vector<vector<int>> a(h,vector<int>(w));
    rep(i,h)rep(j,w)cin >>a[i][j];*/

  int n;cin >>n;
  vector<int> a(n);
  rep(i,n)cin >>a[i];
  vector<int> b(n+1);int cnt=0;
  rep(i,n){
      b[a[i]]++;
  }
  rep(i,n){
      cnt+=b[i+1]*(b[i+1]-1)/2;
  }
  rep(i,n){
      int ncnt=cnt-b[a[i]]*(b[a[i]]-1)/2;
      cout <<ncnt+(b[a[i]]-1)*(b[a[i]]-2)/2<<endl;
  }

}

void dft(complex<double> *x,bool inv){
    for(int i=sz>>1;i>=1;i>>=1){
        complex<double> zeta=polar(1.0,2.0*acos(-1)*i/sz*(inv?-1.0:1.0)),now=1;
        for(int j=0;2*j<sz;j+=i){//i飛ばし
            rep(k,i) {
                y[k+j]=x[2*j+k]+now*x[2*j+i+k];
                y[j+k+(sz/2)]=x[2*j+k]-now*x[2*j+i+k];//sz/2以上のやつ。原点対称を利用
            }
            now*=zeta;
        }
        rep(i,sz)x[i]=y[i];//探索の区間の幅を狭める前にこぴー
    }

    if(inv)rep(i,sz)x[i]/=sz;

}

Measured memory_bytes: 5760
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>

#define FOR(i, b, e) for(int i = (int)(b); i < (int)(e); ++i)
#define RFOR(i, b, e) for(int i = (int)(e-1); i >= 0; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VI vector<int>
#define VVI vector<vector<int>>
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define PAIR pair<int,int>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;

using namespace std;

ll conb(ll n, ll r) {
	if (n - r < r) { return conb(n, n - r); }
	ll tmp = 1;
	FOR(i, n - r + 1, n + 1) {
		tmp *= i;
	}
	FOR(i, 1, r + 1) {
		tmp /= i;
	}
	return tmp;
}

ll mod(ll n, ll r) {
	ll q = n % r;
	return (q < 0) ? q + r : q;
}

int main() {
	ll a, b, c;
	cin >> a;
	if (a == 1) {
		cout << "Hello World" << endl;
	} else {
		cin >> b >> c;
		cout << c + b << endl;

	}
}

Measured memory_bytes: 256
import sys
import copy
a = [int(c) for c in input().split()]
N=a[0]
x=a[1]
a = [int(c) for c in input().split()]
a.sort()
for i in range(N):
    x-=a[i]
    if x<0:
        print(i)
        sys.exit(0)
    elif x==0:
        print(i+1)
        sys.exit(0)

print(N-1)

Measured memory_bytes: 9300
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    MAX = A[-1]
    dp = [1] * (MAX + 5)
    ANS = 0
    for i in range(N):
        if dp[A[i]] == 0:
            continue
        for j in range(MAX+1):
            if A[i]*j > MAX:
                break
            dp[A[i]*j] = 0
        dp[A[i]] = 0
        if i < N-1 and A[i] == A[i+1]:
            continue
        ANS += 1
    print(ANS)

if __name__ == '__main__':
    main()

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

struct UnionFind{
    int num;

    vector<int> rs,ps;

    UnionFind(){}

    UnionFind(int n) : num(n),rs(n,1),ps(n,0){iota(ps.begin(),ps.end(),0);}

    int find(int x){
        return ( x==ps[x] ? x: ps[x] = find(ps[x]));
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }

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

    int size(int x){
        return rs[find(x)];
    }

    int count() const{
        return num;
    }

};

int main(){
    int N,M;
    cin>>N>>M;
    vector<int> p(N);
    UnionFind U(N);
    for(int i=0; i<N; i++){
        cin>>p[i];
        p[i]--;
    }

    for(int i=0; i<M; i++){
        int x,y;
        cin>>x>>y;
        x--,y--;
        U.unite(x,y);
    }

    int cnt = 0;

    for(int i=0; i<N; i++){
        if(U.same(p[i],i)) cnt++;
    }

    cout<<cnt<<endl;

    return 0;
}

Measured memory_bytes: 1408
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  vector<ll> a(N);
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    if (a[i] % 2 == 1 && (i + 1) % 2 == 1) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

  int main()
  {
int n, m; cin >> n >>m;
 int x[m];

  for(int i=0; i<m; i++)
        cin >> x[i], n-=x[i];


   if(n>=0)
     cout << n;
      else
        cout <<"-1";









  }


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

struct StNumCnt
{
  StNumCnt() : m_nNum(0), m_nCnt(0) { }

  int m_nNum;
  int m_nCnt;
};

class CGreater_nCnt
{
  public:
    bool operator()(const StNumCnt& lhs, const StNumCnt& rhs)
    {
      return lhs.m_nCnt > rhs.m_nCnt;
    }
};

void fnInput(vector<int>& rvnNum)
{
  int nNumSiz;
  cin >> nNumSiz;
  rvnNum.resize(nNumSiz);

  for (int& rnNum : rvnNum)
    cin >> rnNum;
}

int fnMinChangeCnt(const vector<int>& cnrvnNum)
{
  map<int, int> mpNumCntEvn, mpNumCntOdd;

  for (int i = 0; i < cnrvnNum.size(); ++i)
    if ( i % 2 == 0 )
      mpNumCntEvn[ cnrvnNum[i] ]++;
    else
      mpNumCntOdd[ cnrvnNum[i] ]++;

  vector<StNumCnt> voNumCntEvn( mpNumCntEvn.size() ),
                   voNumCntOdd( mpNumCntOdd.size() );

  int n = 0;
  for (pair<int, int> PNumCnt : mpNumCntEvn)
  {
    voNumCntEvn[n].m_nNum   = PNumCnt.first;
    voNumCntEvn[n++].m_nCnt = PNumCnt.second;
  }

  n = 0;
  for (pair<int, int> PNumCnt : mpNumCntOdd)
  {
    voNumCntOdd[n].m_nNum   = PNumCnt.first;
    voNumCntOdd[n++].m_nCnt = PNumCnt.second;
  }

  sort(begin(voNumCntEvn), end(voNumCntEvn), CGreater_nCnt() );
  sort(begin(voNumCntOdd), end(voNumCntOdd), CGreater_nCnt() );

  int nMinChangeCnt = INT_MAX;

  for (int i = 0; i < 2; ++i)
    for (int j = 0; j < 2; ++j)
      if (voNumCntEvn[i].m_nNum != voNumCntOdd[j].m_nNum)
        nMinChangeCnt = 
          min( nMinChangeCnt, 
               (int)cnrvnNum.size() - voNumCntEvn[i].m_nCnt - voNumCntOdd[j].m_nCnt );

  return nMinChangeCnt;
}
  
int main()
{
  vector<int> vnNum;
  
  fnInput(vnNum);
  cout << fnMinChangeCnt(vnNum) << endl;

  return 0;
}

Measured memory_bytes: 9004
#include <iostream>

using namespace std;

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

    int a, b, c;
    bool can = false;
    cin >> a >> b >> c;

    for (int i = 0; i < b; i++)
    {
        if ((i + 1) * a % b == c)
        {
            can = true;
            break;
        }
    }

    if (can)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
n=int(input())
s_t_list=[list(map(str,input().split())) for _ in range(n)]
x=input()

count = 0
ans = 0
for i in range(n):
    if count == 1:
         ans += int(s_t_list[i][1])
    if s_t_list[i][0] == x:
        count += 1
print(ans)

Measured memory_bytes: 3064
n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

tmp = 0
li = []
for i in range(n - 1, 0, -1):
    tmp += a[i]
    li.append(tmp * a[i - 1])

print(sum(li) % mod)


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

using namespace std;

const int MAXN = 3e3 + 3;
const int MOD = 1e9 + 7;

int n, m, d[MAXN+5][MAXN+5], dd[MAXN+5], c[MAXN+5][MAXN+5], cc[MAXN+5], e[MAXN+5][MAXN+5], ee[MAXN+5]
, f[MAXN + 5][MAXN + 5], ff[MAXN + 5];

void add(int &x, int y){
	x += y;
	while (x >= MOD) x -= MOD;
}

int main(){
	cin >> n >> m;
	d[0][0] = 1;
	for (int i = 0; i + 1 < MAXN; i++)
		for (int j = 0; j < MAXN; j++){
			if (j + 1 <= n){
				add(d[i + 1][j], d[i][j]);
				add(d[i + 1][j + 1], d[i][j]);
			}
			if (j - 1 >= 0){
				add(d[i + 1][j], d[i][j]);
				add(d[i + 1][j - 1], d[i][j]);
			}
		}

	e[0][1] = 1;
	for (int i = 0; i + 1 < MAXN; i++)
		for (int j = 0; j < MAXN; j++){
			if (j + 1 <= n){
				add(e[i + 1][j], e[i][j]);
				add(e[i + 1][j + 1], e[i][j]);
			}
			if (j - 1 >= 0){
				add(e[i + 1][j], e[i][j]);
				add(e[i + 1][j - 1], e[i][j]);
			}
		}
	

	c[0][0] = 1;
	for (int i = 1; i < MAXN; i++)
		for (int j = 1; j <= n; j++){
			if (j + 1 <= n){
				add(c[i][j], c[i - 1][j]);
				add(c[i][j], c[i - 1][j + 1]);
			}
			if (j - 1 > 0)
				add(c[i][j], c[i - 1][j]);
			if (j - 1 >= 0)
				add(c[i][j], c[i - 1][j - 1]);
		}

	f[0][1] = 1;
	for (int i = 1; i < MAXN; i++)
		for (int j = 1; j <= n; j++){
			if (j + 1 <= n){
				add(f[i][j], f[i - 1][j]);
				add(f[i][j], f[i - 1][j + 1]);
			}
			if (j - 1 > 0){
				add(f[i][j], f[i - 1][j]);
				add(f[i][j], f[i - 1][j - 1]);
			}
		}
	
	for (int i = 0; i < MAXN; i++)
		for (int j = 0; j < MAXN; j++)
			add(cc[i], c[i][j]), add(dd[i], d[i][j]), add(ee[i], e[i][j]), add(ff[i], f[i][j]);

	int ans = 0;
	for (int i = 0; i <= m; i++){
		ans = (ans + 1ll*cc[i]*dd[m-i]) % MOD;
		if (i < m)
			ans = (ans + 1ll*ff[i]*ee[m-i-1]) % MOD;
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 141568
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1000000007;

ll r(ll x, ll y) {
  if (y == 0) return 1;
  else if (y % 2 == 0) return r(x, y/2) * r(x, y/2) % mod;
  else return x * r(x, (y-1)/2) % mod * r(x, (y-1)/2) % mod;
}
  
int main() {
  string S;
  cin >> S;
  int n = S.size();
  vector<int> s(n);
  for (int i = 0; i < n; i++) {
    s[i] = S[i] - '0';
  }
  ll c = 0;
  vector<int> k(2019);
  vector<int> a(n+1, 0);
  k[0]++;
  int p10 = 1;
  for (int i = n-1; i >= 0; i--) {
    a[i] = (p10 * s[i] + a[i+1]) % 2019;
    p10 *= 10;
    p10 %= 2019;
    k[a[i]]++;
  }
  for (int i = 0; i < 2019; i++) {
    if (k[i] > 1) {
      c += (k[i] * (k[i] - 1) / 2);
    }
  }
  cout << c <<endl;
} 



Measured memory_bytes: 5136
#include <stdio.h>

int main(void) {
    int n, v, ary[4][13] = {};
    char s;
    for(scanf("%d", &n); n--; ) {
        scanf("%1s%d", &s, &v);
        ary[s == 'S' ? 0 : s == 'H' ? 1 : s == 'C' ? 2 : 3][~-v]++;
    }
    for(v = 0; v < 52; v++) {
        if(!ary[v / 13][v % 13]) {
            printf("%c %d\n", v / 13 == 0 ? 'S' : v / 13 == 1 ? 'H' : v / 13 == 2 ? 'C' : 'D', v % 13 + 1);
        }
    }
    return 0;
}

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

// helper function to find minimum cost to reach end
int minCost(int* arr, int n, int k)
{
	int *dp = new int[n];

	// fills dp array with 0
    memset(dp, 0, sizeof(dp));

	for(int i = 1; i < n; i++)
    {
    	int ans = INT_MAX, temp = INT_MAX;
    	for(int j = i - 1, count = 1; j >= 0 && count <= k; j--, count++)
    	{
            temp = dp[j] + abs(arr[i] - arr[j]);
            if(temp < ans)
            	ans = temp;
    	}

        dp[i] = ans;
    }

    return dp[n-1];
}


// function to handle input and output
int main()
{
  int n, k;
  cin >> n >> k;

  int a[n];

  for(int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  
  cout << minCost(a, n, k);

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


using Matrix = vector<vector<int>>;
Matrix M;
//グラフの距離を格納した２次元配列(隣接行列)
//M[u][v]はe=(u,v)のコスト

void warshall_floyd(int n){
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            for(int k=0;k<n;k++)
                M[j][k] = min(M[j][k],M[j][i]+M[i][k]);
}


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

    M = Matrix(10,vector<int>(10,0));
    for(int i=0;i<10;i++)
        for(int j=0;j<10;j++)
            cin >> M[i][j];
    

    warshall_floyd(10);

    ll ans = 0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            int a; cin >> a;
            if(a == -1) continue;
            ans += M[a][1];
            //cout << M[i][j] << " ";
        }
        //cout << endl;
    }


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



Measured memory_bytes: 384
N,M=map(int,raw_input().split())
xs=[]
cs=[]
for i in xrange(N):
  x=map(int,raw_input().split())
  xs.append(x)
for i in xrange(M):
  c=map(int,raw_input().split())
  cs.append(c)
for x in xs:
  cp = -1
  cd = 1e9
  for j,c in enumerate(cs):
    md = abs(c[0]-x[0]) + abs(c[1]-x[1])
    if md < cd:
      cd = md
      cp = j
  print 1+cp


Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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=1001001001;
vector<pair<int64_t,int64_t>>pppp(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}
 
int main() {
 int w,h,x,y;
 cin>>w>>h>>x>>y;
 int ans=0;
 if(2*x==w&&2*y==h){ans=1;}
 cout<<fixed<<setprecision(10)<<(double)w*h/2<<" "<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
using namespace std;

int main(){
  long long int N, H, count = 0, ans = 0;
  cin >> N >> H ;
  if((N == 1) || (H == 1)){
    ans = 1 ;
  }
  else if((N%2==0) || (H%2==0)){
    ans = (N * H) / 2 ;
  }
  else{
    ans = ( (N * H) / 2 ) + 1 ;
  }
  cout << ans << endl ;
  return 0 ;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define msp multiset < pair < long long , long long > > S;
#define pll pair<lli, lli>
#define mll map<lli, lli>            //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x) // also valid for set and multiset
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
int main()
{
 //	ios::sync_with_stdio(0);
 //   cin.tie(0);
    lli n;
    string s;
    cin>>n>>s;
    lli r=0,b=0;
    for(lli i=0;i<n;i++){
    	if(s[i]=='R')r++;
    	if(s[i]=='B')b++;
	}
    if(r>b)cout<<"Yes";else cout<<"No";
    
    return 0;
}


Measured memory_bytes: 256
# N = int(input())

import numpy as np

N,K = list(map(int, input().split()))
As = list(map(int, input().split()))

visited = set()
from2to = {}
for i,a in enumerate(As):
    from2to[i+1] = a

id2n_warp = {}
current = 1
loop_anchor = -1
n_warp = 0
visited.add(1)
id2n_warp[1] = 0
while True:
    n_warp += 1
    next_ = from2to[current]
    if n_warp == K:
        print(next_)
        exit()
    if next_ in visited:
        loop_anchor = next_
        break
    else:
        id2n_warp[next_] = n_warp
        visited.add(next_)
    current = next_

K -= id2n_warp[loop_anchor]
# print(n_warp)
# print(K)
# print(id2n_warp[loop_anchor])
K = K % (n_warp - id2n_warp[loop_anchor])
# K = K % (n_warp - id2n_warp[loop_anchor]) if n_warp - id2n_warp[loop_anchor] > 0 else K

current = loop_anchor
for i in range(K):
    next_ = from2to[current]
    current = next_

print(next_)


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

int main(){
  int N;
  long long K;
  cin >> N >> K;
  vector<pair<long long,long long>> A(N);
  for(int i=0; i<N; i++){
    cin >> A[i].first >> A[i].second;
  }
  sort(A.begin(),A.end());
  for(int i=1;i<N; i++){
    A[i].second+=A[i-1].second;
  }
  long long ans=0;
  for(int i=0; i<N; i++){
    if(A[i].second>=K){
      ans=A[i].first;
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;
int main(){
    double a,b,p,q,r;
    cin>>a>>b>>p>>q>>r;
    cout<<setprecision(10)<<(b*p+b*r+a*q)/(r+q)<<"\n";
}


Measured memory_bytes: 3280
#include <stdio.h>

int main(void)
{
	int temp, sum, max;
	int i;
	
	sum = 0;
	for (i = 0; i < 4; i++){
		scanf("%d", &temp);
		sum += temp;
	}
	max = sum;
	sum = 0;
	for (i = 0; i < 4; i++){
		scanf("%d", &temp);
		sum += temp;
	}
	if (max > sum){
		printf("%d\n", max);
	}
	else {
		printf("%d\n", sum);
	}
	return (0);
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<functional>

using namespace std;

int main() {
	int t;
	cin >> t;
	for (int l = 0; l < t; l++) {
		int n, k;
		cin >> n >> k;
		if (k < n) {
			int sum = 0;
			int home[100001];
			for (int j = 1; j <= n; j++) {
				cin >> home[j];
			}
			sum = home[n] - home[1];
			int dis[100000];
			for (int i = 1; i <= n - 1; i++) {
				dis[i] = home[i + 1] - home[i];
			}
			std::sort(dis + 1, dis + n, greater<int>());
			for (int i = 1; i <= k - 1; i++) {
				sum -= dis[i];
			}
			cout << sum << endl;
		}
		else {
			for (int i = 0; i < n; i++) {
				int a;
				cin >> a;
			}
			cout << "0" << endl;
		}
	}
	return 0;
}

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

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

graph = [[] for _ in range(N + 1)]
for _ in range(M):
    L, R, D = map(int, input().split())
    graph[L].append((R, D))
    graph[R].append((L, -D))

d = ['a'] * (N + 1)

def calc(start): #startからの連結成分をチェックする
    d[start] = 0
    stack = [start]
    while len(stack) != 0:
        tmp = stack.pop()
        for next_, diff in graph[tmp]:
            if d[next_] == 'a':
                d[next_] = d[tmp] + diff
                stack.append(next_)
            else:
                if d[next_] == d[tmp] + diff:
                    pass
                else:
                    print ('No')
                    exit()
    return 

# for i in graph:
#     print (i)

for i in range(1, N):
    if d[i] == 'a':
        calc(i)
print ('Yes')


Measured memory_bytes: 65940
n = int(input())
if n < 9:
  print(0)
  
else:
  # 素数のリスト作成
  primes = [2]
  for i in range(3, n+1):
    for prime in primes:
      if i % prime == 0:
        break
    else:
      primes.append(i)

  # 素因数の個数のディクショナリ
  fracs = {}
  for prime in primes:
    fracs[prime] = n // prime
  for i in [4, 8, 16, 32, 64]:
    fracs[2] += n // i
  for i in [9, 27, 81]:
    fracs[3] += n // i
  fracs[5] += n // 25
  fracs[7] += n // 49

  ans = 0
  # 個数が2, 4, 14, 24, 74以上の素因数の個数
  n2, n4, n14, n24, n74 = 0, 0, 0, 0, 0

  for i in fracs.keys():
    if fracs[i] >= 2:
      n2 += 1
      if fracs[i] >= 4:
        n4 += 1
        if fracs[i] >= 14:
          n14 += 1
          if fracs[i] >= 24:
            n24 += 1
            if fracs[i] >= 74:
              n74 += 1
            
  ans += n74 + n24 * (n2 - 1) + n14 * (n4 - 1) + n4 * (n4 - 1) * (n2 - 2) // 2

  print(ans)

Measured memory_bytes: 3064
# coding=utf-8


def partial_rotate(origin, begin, middle, end):
    list1 = origin[:begin]
    list2 = origin[begin:end]
    list3 = origin[end:]

    list2_sub1 = list2[middle-begin:]
    list2_sub2 = list2[:middle-begin]

    return list1 + list2_sub1 + list2_sub2 + list3


if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())

    for i in range(Q):
        b, m, e = map(int, input().split())
        A = partial_rotate(A, b, m, e)

    print(' '.join(map(str, A)))



Measured memory_bytes: 5652
MOD = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))
sumA = 0
for ai in A:
    sumA = (sumA + ai) % MOD
ans = 0
for ai in A:
    sumA = sumA - ai
    ans = (ans + sumA * ai) % MOD

print(ans)

Measured memory_bytes: 94132
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        {
            Scanner sc = new Scanner(System.in);
            int N =sc.nextInt();
            int K= sc.nextInt();
            int[] arr = new int[N];
            for(int i = 0;i<N;i++){
                arr[i] = sc.nextInt();
            }
            int[] dp = new int[N];
            for(int i= 1;i<N;i++) dp[i]= Integer.MAX_VALUE;
            dp[0] = 0;
            for(int i = 0;i<N-1;i++){
                int j = 1;
                while(j < K+1 && (i+j)< N){
                    dp[i+j] =Math.min(dp[i+j] ,dp[i] + Math.abs(arr[i+j] - arr[i]));
                    j++;
                }
            }
            System.out.println(dp[N-1]);
        }
    }
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

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

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

//main code

int main(int argc, char const* argv[])
{
	int n,m;
	cin >> n >> m;
	VL p(m),y(m);
	VVL yd(n+1);
	for (int i = 0; i < m; i++) {
		cin >> p[i] >> y[i];
		yd[p[i]].PB(y[i]);
	}
	for (auto&& var : yd) {
		SORT(var);
	}
	for (int i = 0; i < m; i++) {
		cout << setfill('0') << right << setw(6) << p[i];
		cout << setfill('0') << right << setw(6) << lower_bound(ALL(yd[p[i]]),y[i]) - yd[p[i]].begin() + 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 8576
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
//#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e7 + 7;
//const int INF = 1e18;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

void solve(){
  string s;
  while(cin >> s){
	  while(s.find("@") != -1){
		  int idx = s.find("@");
		  string curr;
		  for(int i  = 0; i < s[idx + 1] - '0'; i++)
		    curr += s[idx + 2];
		  s.replace(idx, 3, curr);  
		}
	 cout << s << endl; 
	}	
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}



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

int main() {
  
  int H,W,N;
  cin>>H>>W>>N;
  vector<int>a(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i);
  }
  queue<int>q;
  rep(i,N){
    int p=a.at(i);
    while(p--){
      q.push(i+1);
    }
  }
  rep(i,H){
    vector<int>ans(W);
    int w=W;
    while(w--){
      ans.at(W-1-w)=q.front();
      q.pop();
    }
    if(i%2==0){
      rep(i,W){
        cout<<ans.at(i)<<" ";
      }
    }
    else{
      rep(i,W){
        cout<<ans.at(W-1-i)<<" ";
      }
    }
    cout<<endl;
  }
}

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

int main() {
	int N, M;
	map<int,int> D;
	cin >> N;
	for (int i = 0; i < N; i++) {
		int d;
		cin >> d;
		D[d]++;
	}
	string ans = "YES";
	cin >> M;
	for (int i = 0; i < M; i++) {
		int t;
		cin >> t;
		D[t]--;
		if (D[t] < 0) {
			ans = "NO";
			break;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) v.begin(), v.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
  int n, k, ans = 1; cin >> n >> k;
  for(int i = 0; i < n; i++){
    ans = min(ans*2, ans+k);
  }
  cout << ans << endl;
  system("pause");
}

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

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N, a, b;
long long X[100000], Y[100000];
map<long long, vector<long long> > mpX, mpY;
int U[100000], R[100000];
bool used[100000];

int find(int x) {
  if (U[x] == x) return x;
  return U[x] = find(U[x]);
}
map<long long, set<long long> > setX, setY;
map< pair<long long, long long>, int> id;

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

bool same(int x, int y) {
  return find(x) == find(y);
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> a >> b;
  a--, b--;
  rep(i, N) {
    long long x, y;
    cin >> x >> y;
    X[i] = x+y;
    Y[i] = x-y;
    id[P(X[i], Y[i])] = i;
    mpX[X[i]].pb(Y[i]);
    mpY[Y[i]].pb(X[i]);
    setX[X[i]].insert(Y[i]);
    setY[Y[i]].insert(X[i]);
  }
  rep(i, N) U[i] = i, R[i] = 1;

  for (auto &p : mpX) sort(all(p._2));
  for (auto &p : mpY) sort(all(p._2));
  long long D = max(abs(X[a]-X[b]), abs(Y[a]-Y[b]));

  queue<int> q;
  q.push(a);
  used[a] = true;
  setX[X[a]].erase(Y[a]);
  setY[Y[a]].erase(X[a]);
  while (!q.empty()) {
    int v = q.front(); q.pop();
    long long x = X[v], y = Y[v];

    for (int k=-1; k<=1; k+=2) {
      long long xx = x+D*k;
      // (x+-D, ?)
      auto &vs = setX[xx];
      auto lo = vs.lower_bound(y-D);
      while (lo != vs.end()) {
        long long yy = *lo;
        if (yy > y+D) break;
        int t = id[P(xx, yy)];
        unite(v, t);
        q.push(t);
        setY[yy].erase(xx);
        lo = vs.erase(lo);
      }
    }
    for (int k=-1; k<=1; k+=2) {
      long long yy = y+D*k;
      // (x+-D, ?)
      auto &vs = setY[yy];
      auto lo = vs.lower_bound(x-D);
      while (lo != vs.end()) {
        long long xx = *lo;
        if (xx > x+D) break;
        int t = id[P(xx, yy)];
        unite(v, t);
        q.push(t);
        setX[xx].erase(yy);
        lo = vs.erase(lo);
      }
    }
  }

  long long ctr = 0;
  rep(i, N) {
    long long x = X[i], y = Y[i];
    if (!same(i, a)) continue;
    // (x+D, ?)
    vector<long long> &ys = mpX[x+D];
    if (!ys.empty()) {
      auto it = lower_bound(all(ys), y-D);
      if (it != ys.end() && *it <= y+D) {
        ctr += upper_bound(all(ys), y+D) - it;
      }
    }
    // (?, y+D)
    vector<long long> &xs = mpY[y+D];
    if (!xs.empty()) {
      auto it = upper_bound(all(xs), x-D);
      if (it != xs.end() && *it < x+D) {
        ctr += lower_bound(all(xs), x+D) - it;
      }
    }
  }
  cout << ctr << "\n";
  return 0;
}


Measured memory_bytes: 78848
#include<bits/stdc++.h>
    using namespace std;
    #define ll long long int
    #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
    #define bs binary_search
    #define pb push_back
    #define pp pair<ll,ll>
    #define F first 
    #define S second 
    #define lc "\n"
    ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;} 
    ll MAX=1e18 , MIN=-1e18 , MOD=1000000007;
    int main() 
    {
        fastio
        int a,b,c,d,k=0; cin>>a>>b>>c>>d;
        while(a>0&&c>0)
        {
            if(k==0)
            c=c-b;
            else a=a-d;
            k^=1;
        }
        if(a>0) cout<<"Yes"; else cout<<"No";
        return 0;
    }

Measured memory_bytes: 3668
H, W = gets.split.map(&:to_i)

a = []
def culculate(areas, height, width)
  (1..(height-1)).each do |h1|
    a1 = h1 * width
    w = (width / 2).round
    a2 = (height - h1) * w
    a3 = (height - h1) * (width - w)
    areas << [a1, a2, a3].max - [a1, a2, a3].min

    h = ((height - h1) / 2).round
    a2 = h * width
    a3 = (height - h1 - h) * width
    areas << [a1, a2, a3].max - [a1, a2, a3].min
  end
end
culculate(a, H, W)
culculate(a, W, H)
p a.min

Measured memory_bytes: 6140
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define st(vvv) sort(vvv.begin(),vvv.end())
#define rvs(vvv) reverse(vvv.begin(),vvv.end())
int inf = 1000000007;
i64 giant = 4000000000000000000;

using namespace std;

int main() {
	int n;
	cin >> n;
	int prev = 0;
	int cur = 0;
	ff(i, 0, n) {
		int a;
		cin >> a;
		cur = a;
		if (cur > prev)cur--;
		if (cur < prev) {
			cout << "No" << endl;
			return 0;
		}
		prev = cur;
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.awt.Point;
import java.util.*;
public class Main {

		
	    public static void main(String[] args) throws java.io.IOException{
	        Scanner scan = new Scanner(System.in);
	       while(true){
	        int h=scan.nextInt();
	        int w=scan.nextInt();
	        scan.nextLine();
	        if((h|w)==0)break;
	        char [][] map =new char[h][w];
	        for(int i=0;i<h;i++){
	        	String tmp =scan.nextLine();
	        	for(int j=0;j<w;j++)map[i][j]=tmp.charAt(j);
	        }
	        
	        Queue <Point> fifo  =new  LinkedList<Point>();
	        int ans=0;
	        for(int m=0;m<h;m++){
	        	for(int n=0;n<w;n++){
	        if(map[m][n]!='.'){
	        	ans++;
	        	Point p = new Point(n,m);
		        fifo.add(p);
	        while(fifo.peek()!=null){
	        	p=fifo.poll();
	        	int x=p.x;
	        	int y=p.y;
	        	char crop = map[y][x];
	        	map[y][x]='.';
	        	int [] dx ={0,1,0,-1};
	        	int [] dy ={1,0,-1,0};
	        	
	        	for(int i=0;i<4;i++){
	        		int nx =x+dx[i];
	        		int ny =y+dy[i];
	        		if(0<=nx&&nx<w&&0<=ny&&ny<h&&map[ny][nx]==crop&&map[ny][nx]!='.'){
	        			Point np = new Point();
	        			np.x=nx;
	        			np.y=ny;
	        			fifo.add(np);
	        			
	        		}
	        	}
	        }
	        }
	        	}
	        }System.out.println(ans);
	       }
	    }
}
	    

Measured memory_bytes: 12000
S = gets.chomp
dgt = S.size
MOD = 10 ** 9 + 7

cnt = 0
short = 0
qs = []
while S.length > 0
	n = S[-1]
	if n == '?'
		qs.push(cnt % 6)
	else
		short += n.to_i * (10 ** (cnt % 6))
	end
	S.chop!
	cnt += 1
end
short = short % 13

mod = [1] + [0] * 12
while !qs.empty?
	k = qs.shift
	newmod = [0] * 13
	(0..9).each do |i|
		m =  (i * 10 ** k) % 13
		13.times do |j|
			newmod[j] = newmod[j] + mod[(j - m) % 13]
		end
	end
	13.times do |l|
		mod[l] = newmod[l] % MOD
	end
end

puts mod[(5 - short)] % MOD

Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
int a,b,c;
int main()
{
    cin>>a>>b>>c;
    cout<<a<<" "<<b<<" "<<3*c-a-b<<endl ;
    cout<<4*c-2*a-b<<" "<<c<<" "<<2*a+b-2*c<<endl;
    cout<<a+b-c<<" "<<2*c-b<<" "<<2*c-a<<endl;
    return 0;
}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             

Measured memory_bytes: 256
k = gets.chomp.to_i

result = 0
1.step(k, 1) do |a|
  1.step(k, 1) do |b|
    1.step(k, 1) do |c|
      tmp_gcd = a.gcd(b)
      tmp_result = tmp_gcd.gcd(c)
      result = result + tmp_result
    end
  end
end

puts result


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

int main(){
  string s;
  cin>>s;
  for(int i = 0;i<s.length();i+= 2){
    cout<<s[i];
  }
  cout<<endl;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int main(void){
  int A,B;
  scanf("%d%d", &A,&B);

  int ans = 0;
  int outlet = 1;

  while (outlet < B) {
    outlet = outlet - 1 + A;
    ans++;
  }

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

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
//#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (10);   小数点以下１０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//string s = to_string(int数);
//int n = stoi(string文字列);

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

  cout << s.substr(0,s.size()-8) << endl;
  
}


Measured memory_bytes: 256
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias Loc = Tuple!(long, "x", long, "y", long, "h");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

auto charcount(string s)
{
    char current = s[0];
    auto ret = new long[](1);
    foreach (e; s)
    {
        if (e != current)
        {
            ret ~= [0];
            current = e;
        }
        ret[$ - 1]++;
    }
    return ret;
}

void main()
{
    long n, k;
    scan(n, k);
    auto remainder = new long[](k);
    foreach (i; iota(1, n + 1))
        remainder[i % k]++;

    if (k % 2)
    {
        writeln(remainder[0] ^^ 3);
    }
    else
    {
        auto result = remainder[0] ^^ 3;
        result += remainder[k / 2] ^^ 3;
        result.writeln();
    }
}


Measured memory_bytes: 3068
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<map>
#include<vector>

using namespace std;


#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
	int N, K;
	cin >> N >> K;
	int now;
	double p;
	double tmp = 0.0;
	rept(i, 1, N+1) {
		p = 1.0 / N;
		now = i;
		while (now < K) {
			now *= 2.0;
			p /= 2.0;
		}
		tmp += p;
	}
	cout << setprecision(9) << tmp << endl;




	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(int i=s;i<t;i++)
const int mod=1e9+7,inv2=(mod+1)/2;
#define MAXNUM 211111
vector<int> e[MAXNUM];
int tsize[MAXNUM],fa[MAXNUM],p2[MAXNUM];
void dfs(int now,int p)
{
    fa[now]=p,tsize[now]=1;
    for(int k:e[now])if(k!=p)
        dfs(k,now),tsize[now]+=tsize[k];
}
int main()
{
    int n,a,b;scanf("%d",&n);
    p2[0]=1;
    rep(i,1,n+1)p2[i]=p2[i-1]*1ll*inv2%mod;
    rep(i,1,n)scanf("%d%d",&a,&b),e[a].push_back(b),e[b].push_back(a);
    dfs(1,1);int res=0;
    rep(i,1,n+1)
    {
        int num[3]={0};
        num[0]=1;
        for(int k:e[i])
        {
            int x=tsize[k];
            if(k==fa[i])x=n-tsize[i];
            num[2]=(num[2]+num[1]*1ll*(1-p2[x]+mod))%mod;
            num[1]=(num[1]*1ll*p2[x]%mod+num[0]*1ll*(1-p2[x]+mod))%mod;
            num[0]=num[0]*1ll*p2[x]%mod;
        }
        res=(res+num[2]*1ll*inv2%mod)%mod;
    }
    printf("%d\n",res);
}

Measured memory_bytes: 22784
#include<stdio.h>

int main()
{
    int x,y;
    while(1){
       scanf("%d %d",&x,&y);
       if(x == 0 && y == 0)
             break;
       if(x < y)
             printf("%d %d\n",x,y);
       else
             printf("%d %d\n",y,x);
    }
    return 0;
}


Measured memory_bytes: 2040