akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;

ll cake[1000][3];
ll cake_evalution[1000];

int main() {
	int N, M;
	cin >> N >> M;
	for (int i = 0; i < N; i++)cin >> cake[i][0] >> cake[i][1] >> cake[i][2];

	ll ans = -1e18;

	for (int bit = 0; bit < (1 << 3); bit++) {
		for (int i = 0; i < N; i++){
			cake_evalution[i] = 0;
			for (int j = 0; j < 3; j++) {
				ll tmp = 1;
				if (bit & (1 << j))tmp = -1;
				cake_evalution[i] += cake[i][j] * tmp;
			}
		}
		ll tmp = 0;
		sort(cake_evalution, cake_evalution + N, greater<ll>());

		for (int i = 0; i < M; i++)tmp += cake_evalution[i];

		ans = max(ans, tmp);

	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
// Sakhiya07 - Yagnik Sakhiya
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
 
#define mp make_pair
#define bp __builtin_popcountll
#define MOD  1000000007
const int N = 10000;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));
 
void solve()
{
   ll n,p;
   cin >> n >> p;
   string s;
   cin >> s;
   ll suf[n+1]={0};
   ll ten = 1;
   map<ll,ll> y;
   y[0] = 1;
   ll ans = 0;
   for(ll i=n-1;i>=0;i--)
   {
       suf[i] = ((s[i] - '0')*ten)%p;
       suf[i] = (suf[i] + suf[i+1])%p;
       ans += y[suf[i]];
       y[suf[i]]++;
       ten *= 10;
       ten %= p;
   }
   if(p==2)
   {
   	   ll ans = 0;
   	   for(ll i=0;i<n;i++)
   	   {
   	   	   ll temp = s[i] - '0';
   	   	   if(temp%2==0)
   	   	   {
   	   	   	   ans += i+1;
   	   	   }
   	   }
   	   cout<<ans;
   	   return;
   }
   if(p==5)
   {
   	    ll ans = 0;
   	   for(ll i=0;i<n;i++)
   	   {
   	   	   ll temp = s[i] - '0';
   	   	   if(temp==0 || temp==5)
   	   	   {
   	   	   	   ans += i+1;
   	   	   }
   	   }
   	   cout<<ans;
   	   return;
   }
   cout<<ans;
}

int main()
{
    FAST;
    ll t = 1;
 //   cin >> t;
    while(t--)
    {
    	solve();
    }
}

Measured memory_bytes: 2580
// CODE © by 𝕌𝕥𝕜𝕒𝕣𝕤𝕙 𝔾𝕒𝕣𝕘
// Copying or sharing of this code without permission of the Author is strictly prohibited!!!
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define Speed ios::sync_with_stdio(0); cin.tie(0);
#define pb push_back
#define endl "\n"
int power(int x, int n, int mod) {int res = 1; x %= mod; while (n) {if (n & 1)res = (res * x) % mod; x = (x * x) % mod; n >>= 1;} return res;}
signed main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
#endif
	int a = 0, b = 0, c = 0, d = 0, i = 0, j = 0, k = 0, t = 0, n = 0, q = 0;
	// cin >> t;
	// while (t--) {
	cin >> n >> k ;
	int arr[n], dp[n] = {0};
	for (i = 0; i < n; i++)cin >> arr[i];
	dp[1] = abs(arr[1] - arr[0]);
	for (int i = 2; i < n; i++) {
		dp[i] = INT_MAX;
		for (j = 1; j <= k; j++) {
			if (i - j >= 0)
				dp[i] = min(dp[i], dp[i - j] + abs(arr[i] - arr[i - j]));
		}
		// dp[i] = min(dp[i - 1] + abs(arr[i] - arr[i - 1]), dp[i - 2] + abs(arr[i] - arr[i - 2]));
	}
	cout << dp[n - 1] << endl;
	// }
}

Measured memory_bytes: 5184
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, c;
  cin >> a >> b >> c;
  if (b > c || (a == 1 && b != c)) {
    cout << 0 << endl;
    return 0;
  }
  else if (a == 1 && b == c) {
    cout << 1 << endl;
    return 0;
  }
  cout << (a - 2) * (c - b) + 1 << endl;
}

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

int main() {
  int N;
  cin >> N;
  set<pair<char, int> > toranpu;
  for (int i=1; i<=13; i++) {
      pair<char, int> S('S', i),H('H', i),C('C', i),D('D', i);
      toranpu.insert(S);
      toranpu.insert(H);
      toranpu.insert(C);
      toranpu.insert(D);
  }
  for (int i=0; i<N; i++) {
      char a;
      int b;
      cin >> a >> b;
      pair<char, int> A(a,b);
      toranpu.erase(A);
  }
  for (int i=0; i<=13; i++) {
      pair<char,int> A('S',i);
      if(toranpu.count(A)) cout << "S " << i << endl;
  }
  for (int i=0; i<=13; i++) {
      pair<char,int> A('H',i);
      if(toranpu.count(A)) cout << "H " << i << endl;
  }
  for (int i=0; i<=13; i++) {
      pair<char,int> A('C',i);
      if(toranpu.count(A)) cout << "C " << i << endl;
  }
  for (int i=0; i<=13; i++) {
      pair<char,int> A('D',i);
      if(toranpu.count(A)) cout << "D " << i << endl;
  }
}


Measured memory_bytes: 3108
var input = '';
var readable = process.stdin;
readable.resume();
readable.setEncoding( 'utf-8' );
readable.on( 'data', function( chunk ) {
  input += chunk;
});

readable.on( 'end', function() {
  var data = input.split( " " );
  var x1 = parseFloat( data[0] );
  var y1 = parseFloat( data[1] );
  var x2 = parseFloat( data[2] );
  var y2 = parseFloat( data[3] );
   
  var d = Math.sqrt( Math.pow( x1-x2, 2 )+Math.pow( y1-y2, 2 ) ).toFixed(5);
  console.log( d );
});

Measured memory_bytes: 15536
#include <iostream>
#include <cmath>
#include <string>
#include <sstream>
using namespace std;

string str;

string its(int n){
    stringstream s;
    s << n;
    return s.str();
}

int judge(int n){
    string ss = its(n);
    int len = ss.size();
    
    for(int i = 0 ; i <= len/2 ; i++){
        if(ss[i] != ss[len-i-1]) return 0;
    }
    return 1;
}

int main(){
    int n,a,b;
    
    cin >> n;
    for(int i = n ; ; i++){
        if(judge(i)){
            a = i;
            break;
        }
    }
    for(int i = n ; ; i--){
        if(judge(i)) {
            b = i;
            break;
        }
    }
    
    if(abs(n-a) == abs(n-b)) cout << b << endl;
    else if(abs(n-a) < abs(n-b)) cout << a << endl;
    else cout << b << endl;
    
    return 0;
}

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

using namespace std;

int main()
{
    vector<int> my_v;
    int dummy;

    for(int i = 0; i < 3; i++){
        cin >> dummy;
        my_v.push_back(dummy);
    }
    sort(my_v.begin(),my_v.end());
    if(my_v[0] == 5 && my_v[1] == 5 && my_v[2] == 7)
        cout << "YES" <<endl;
    else
        cout << "NO" <<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int n, x;
    cin >> n;
    bool isOdd = false;
    for (int i = 0; i < n; i++) {
        cin >> x;
        if (x % 2 == 1) isOdd = true;
    }
    if (isOdd) cout << "first" << '\n';
    else cout << "second" << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;

int main(){
    int r,c;cin>>r>>c;int exel[r+1][c+1];
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++) cin>>exel[i][j];
    }
    for(int i=0;i<r;i++){
        int sum=0;
        for(int j=0;j<c;j++){
            sum+=exel[i][j];
        }
        exel[i][c]=sum;
    }
    for(int i=0;i<c;i++){
        int sum=0;
        for(int j=0;j<r;j++){
            sum+=exel[j][i];
        }
        exel[r][i]=sum;
    }
    exel[r][c]=0;
    for(int i=0;i<c;i++) exel[r][c]+=exel[r][i];
    for(int i=0;i<r+1;i++){
        for(int j=0;j<c+1;j++){
            if(j==0) cout<<exel[i][j];
            else cout<<" "<<exel[i][j];
        }
        cout<<endl;
    }
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int main2() {
  int H, W; cin >> H >> W;
  vector<string> s(H);
  REP(i, H) cin >> s[i];

  vector<int> existH(H);
  vector<int> existW(W);
  REP(i, H) REP(j, W) if (s[i][j]=='#') {
    existH[i] = 1;
    existW[j] = 1;
  }
  REP(i, H) {
    string line;
    REP(j, W) {
      if (existH[i] && existW[j]) {
        line += s[i][j];
      }
    }
    if (line.size() > 0) cout << line << endl;
  }
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 256
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, l = list(map(int, readline().split()))
    a = collections.deque(list(map(int, readline().split())))
    for i in range(1, n):
        if a[i] + a[i-1] >= l:
            print("Possible")
            for j in range(1, i):
                print(j)
            for j in range(n - 1, i, -1):
                print(j)
            print(i)
            exit()
    print("Impossible")


if __name__ == '__main__':
    solve()


Measured memory_bytes: 58224
import sys
from collections import Counter
N, T = map(int, input().split())
A = [int(_) for _ in input().split()]

if N == 2:
    print(1)
    sys.exit()

start = A[0]
max_diff = 0
max_count = 0


for n in range(1, N):
    if A[n] < A[n - 1]:
        start = min(A[n], start)
        #print(start)
    else:
        diff = A[n] - start
        if diff > max_diff:
            max_diff = diff
            max_count = 1
        elif diff == max_diff:
            max_count += 1


print(max_count)


Measured memory_bytes: 14636
#include <bits/stdc++.h>
using namespace std;
#define N 105
int main(){
	int h,w;
	string s;
	cin>>h>>w;
	for(int i=0;i<w+2;i++)cout<<'#';
	cout<<'\n';
	for(int i=0;i<h;i++){
		cin>>s;
		cout<<'#'<<s<<'#'<<'\n';
	}
	for(int i=0;i<w+2;i++)cout<<'#';
	cout<<'\n';
}

Measured memory_bytes: 256
//============================================================================
// Name        : ProjG.cpp
// Author      : Yong Kiat
// Version     :
// Copyright   : By Algotae.
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <bits/stdc++.h>

using namespace std;

const int mxN = 3e3;
int n;
long double p[mxN], dp[mxN][mxN], res;

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

    cin >> n;

    for (int i = 0; i < n; i++) {
    	cin >> p[i];
    }

    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
    	for (int j = 0; j <= i; j++) {
    		dp[i+1][j+1] += dp[i][j] * p[i];
    		dp[i+1][j] += dp[i][j] * (1 - p[i]);
    	}
    }

    for (int i = (n + 1) / 2; i <= n; i++) {
    	res += dp[n][i];
    }

    cout << fixed << setprecision(16) << res;
}


Measured memory_bytes: 139136
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void p(vector<int> A){rep(i,A.size()){cout << A[i];}cout << endl;}

int main(){
    int d, n;
    cin >> d >> n;
    if (n == 100)printf("%d",101*(int)pow(100,d));
    else cout << n*pow(100,d);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

long long choose2(long long n) {
	return (n*(n-1)/2);
}

int main() {
	long long n;
	cin >> n;
	vector<int> s(n);
	map<int, int> cnt;
	long long total = 0;

	for (int i=0; i<n; i++) {
		cin >> s[i];
		s[i]--;
	}

	for (int i=0; i<n; i++)
		cnt[s[i]]++;

	for (int i=0; i<n; i++)
		total += choose2(cnt[i]);

	for (int i=0; i<n; i++) {
		long long ans = total;
		ans -= choose2(cnt[s[i]]);
		ans += choose2(cnt[s[i]]-1);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 12800
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
#define N 100005
char s[N];int sr,sb,n;
int main(){scanf("%d%s",&n,s+1);for(int i=1;i<=n;i++)sr+=s[i]=='R';sb=n-sr;if(sr>sb)puts("Yes");else puts("No");}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int n;
    cin >> n;
    ll ans;
    ans = (ll)n*(n-1)/2;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;int c=0;
  for(int i=1;i<=9;i++)
  {
    if(n%i==0&&n/i>=1&&n/i<=9)
    {
      c++;
    }
  }
  if(c>0)
    cout<<"Yes";
  else
    cout<<"No";
    return 0;
}
      
    

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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    vector<int> a(n); 
    REP(i,n) cin>>a[i];
    bool flag = true;
    REP(i,n){
        if(a[i]%2==0){
            if(a[i]%3!=0 && a[i]%5!=0) flag = false;
        }
    }
    if(flag) print("APPROVED");
    else print("DENIED");
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8-*-
if __name__ == '__main__':
    a = []
    b = []
    idx = 0
    r = 10
    for i in range(5):
        a.append(int(input()))
        if a[-1] % 10 == 0:
            if r == 10:
                idx = i
            b.append(a[-1])
        else:
            if r > a[-1] % 10:
                r = a[-1] % 10
                idx = i
            b.append(a[-1] - a[-1] % 10 + 10)
    sum = 0
    for i in range(5):
        if i == idx:
            sum += a[i]
        else:
            sum += b[i]
    print(sum)


Measured memory_bytes: 3064
#include<iostream>
#include<queue>
using namespace std;
int main(){
	long long n,m,i,t,sum=0;
	cin>>n>>m;
	priority_queue<long long> k;
	for(i=0;i<n;i++){
		cin>>t;
		k.push(t);
	}
	for(i=0;i<m;i++){
		t=k.top()/2;
		k.pop();
		k.push(t);
	}
	for(i=0;i<n;i++){
		sum+=k.top();
		k.pop();
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 1400
#include<iostream>
using namespace std;
int main(){
    int n,x,t,b;
    t=0;
    n=1;
    x=1;
    cin>>n>>x;
    while(n!=0||x!=0){
        for(int i=1;i<=n;i++){
            for(int a=i+1;a<=n;a++){
                for(int b=a+1;b<=n;b++){
                    if (a+b+i==x) t+=1;
                }
            }
        }
    cout<<t<<endl;
    cin>>n>>x;
    t=0;
    }
}



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

int main() {
	char C11,C12,C13,C21,C22,C23;
    cin >> C11 >> C12 >> C13;
    cin >> C21 >> C22 >> C23;
    if(C11 == C23 && C12 == C22 && C13 == C21){
      cout << "YES" << endl;
    }
    else{
      cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n;
  string s;
  cin >> n >> s;
  int x=0,y=0;
  rep(i,n) {
    if(s[i]=='R') x++;
    else y++;
  }
  if(x>y) pr("Yes");
  else pr("No");
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AizuOnlineJudge
{
    class Program
    {
        static void Main(string[] args)
        {
            var arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var y = arr[0];
            var x = arr[1];
            var ys = new int[x];
            Enumerable.Range(0, y).Select(e => new SomeClass{ Index = e, Arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray() })
                .ToList().ForEach(e => Interact(e, ref ys));
            Console.WriteLine($"{string.Join(" ", ys)} {ys.Sum()}");
        }

        private static void Interact(SomeClass e, ref int[] ys)
        {
            for(var i = 0; i < ys.Length; ++i)
            {
                ys[i] += e.Arr[i];
            }
            Console.WriteLine($"{string.Join(" ", e.Arr)} {e.Arr.Sum()}");
        }

        private class SomeClass
        {
            public int Index { get; set; }
            public int[] Arr { get; set; }
        }

        /*private static bool IsInput(out int[] arr)
        {
            var s = Console.ReadLine();
            if (s == "0 0") { arr = null; return false; }

            arr = s.Split(' ').Select(int.Parse).ToArray();
            return true;
        }
        // */
    }
}


Measured memory_bytes: 16440
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int64_t dceil(int64_t, int64_t);
int64_t dfloor(int64_t, int64_t);

int64_t dceil(int64_t x, int64_t y)
{
    if (y < 0) {
        return dceil(-x, -y);
    }
    if (x < 0) {
        return -dfloor(-x, y);
    }
    return (x + y - 1) / y;
}

int64_t dfloor(int64_t x, int64_t y)
{
    if (y < 0) {
        return dfloor(-x, -y);
    }
    if (x < 0) {
        return -dceil(-x, y);
    }
    return x / y;
}

int64_t gcd(int64_t x, int64_t y)
{
    if (x == 0) {
        return y;
    }
    return gcd(y % x, x);
}

int main()
{
    int64_t n, m;
    cin >> n >> m;

    int64_t L = 1;
    vector<int64_t> a(n);
    rep(i, n)
    {
        cin >> a[i];
        a[i] /= 2;
        L = L / gcd(L, a[i]) * a[i];
    }

    bool c = true;
    rep(i, n)
    {
        c = c && (L / a[i] % 2 == 1);
    }

    if (!c) {
        cout << 0 << endl;
    } else {
        int64_t lb = dceil(1 - L, 2 * L), ub = dfloor(m - L, 2 * L);
        cout << max(0L, ub - lb + 1) << endl;
    }

    return 0;
}

Measured memory_bytes: 1152
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define SIZE(x) ((int)(x).size())
#define UQ(v) v.erase(unique(v,begin(),v,end()),v.end());
ll INF = 1LL <<61;
#define pb push_back 
int dxy4[5] = { 0,1,0,-1,0 };
int dxy8[9] = { 0,1,1,0,-1,1,-1,-1,0 };
int gcd(int a, int b) { return min(a,b) ? gcd(min(a,b), max(a,b)%min(a,b)) : max(a,b); }
ll mod7 = 1000000007;
ll mod9 = 1000000009;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define FOR(i,x,n) for(int i=x;i<n;++i)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define print(x) cout<<x<<endl;
#define wait int xxxxxxx;cin>>xxxxxxx;

//vector< vector<int> > v (max1, vector<in t>(max2) );
int main() {
	int n;
	cin >> n;

	int now = int((999 / 3) * 5) + 999 * 195 +1;

	rep(i, n) {

		int y, m, d;
		cin >> y >> m >> d;
		int b = int((y-1) / 3) * 5 +( y -1) * 195;
		rep(i, m) {
			if (i + 1 == m) {
				rep(j, d)b++;
			}
			else {
				if (y % 3 == 0 or i % 2 == 0)rep(j, 20)b++;
				else rep(j, 19)b++;
			}

		}

		print(now - b);


	}
	wait
	return 0;
}


Measured memory_bytes: 3080
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

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

    li a, b;
    cin >> a >> b;
    cout << max(a - 2 * b, 0LL) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<set>
using namespace std;
int main(){
    for(;;){
        int m,n;
        scanf("%d",&m);
        if(m==0)break;
        vector<pair<int,int> > cons(m);
        for(int i=0;i<m;i++){
            int ia,ib;
            scanf("%d%d",&ia,&ib);
            cons[i]=make_pair(ia,ib);
        }
        scanf("%d",&n);
        set<pair<int,int> > stset;
        for(int i=0;i<n;i++){
            int ia,ib;
            scanf("%d%d",&ia,&ib);
            stset.insert(make_pair(ia,ib));
        }
        for(set<pair<int,int> >::iterator it=stset.begin();it!=stset.end();it++){
            int dx=it->first-cons[0].first,dy=it->second-cons[0].second;
            bool is=true;
            for(int i=1;i<m;i++){
                if(stset.find(make_pair(cons[i].first+dx,cons[i].second+dy))==stset.end()){
                    is=false;
                    break;
                }
            }
            if(is){
                printf("%d %d\n",dx,dy);
                break;
            }
        }
    }
}

Measured memory_bytes: 0
#include<stdio.h>
main(){
    int i,text,a,b;
    while(scanf("%d",&a)!=EOF){
        scanf("%d",&b);
        i=1;
        a+=b;
        while(a>=10){
            a/=10;
            i++;
        }
    printf("%d\n",i);
}
    return 0;
}


Measured memory_bytes: 1928
#include<stdio.h>
long long int n, a[200100][2], sum, s, t;
int main(){
	int i,j=0;
	scanf("%lld", &n);
	for(i=1; i<=n; i++){
		scanf("%lld", &a[i][0]);
		t=0;
		while(a[i][0]<a[j][0]){
			t=t+a[j][1];
			s=s-a[j][0]*a[j][1];
			j--;
		}
		a[++j][1]=t+1;
		a[j][0]=a[i][0];
		s=s+a[i][0]*(t+1);
		sum=sum+s;
	}
	printf("%lld", sum);
}

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

int main() {
  int n;
  cin >> n;
  vector<int[3]> dp(n + 1);
  rep(i, n) {
    int h[3];
    cin >> h[0] >> h[1] >> h[2];
    rep(j, 3) {
      rep(k, 3) {
        if (j != k) dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + h[j]);
      }
    }
  }
  cout << *max_element(begin(dp[n]), end(dp[n])) << endl;
}

Measured memory_bytes: 1536
import java.util.Scanner;

class Main
{
    static int N = 100;
    static int[][]M = new int[N][N];


    public static void main(String[] args)
    {
	int n;
	int []p = new int[N + 1];
	int[][]m = new int[N + 1][N + 1];

	Scanner In = new Scanner(System.in);

	n = In.nextInt();

	for(int i = 1; i <= n; i++)
	    {
		p[i - 1] = In.nextInt();
		p[i] = In.nextInt();
	    }

	for(int i = 1; i <= n; i++) m[i][i] = 0;

	for(int j = 2; j <= n; j++)
	    {
		for(int i = 1; i <= n - j + 1; i++)
		    {
			int k = i + j - 1;
			m[i][k] = 200000;
			for(int l = i; l <= k - 1; l++)
			    {
				m[i][k] = ((m[i][k] < m[i][l] + m[l + 1][k] + p[i - 1] * p[l] * p[k]) ? m[i][k] : (m[i][l] + m[l + 1][k] + p[i - 1] * p[l] * p[k])); 
			    }
		    }
	    }
	System.out.println(m[1][n]);
    }
}

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

int main(){
  int n,ans=0;
  cin >> n;
  char *color = new char[n], last_color = '0';

  for(int i=0;i<n;i++){
    cin >> color[i];
  }

  for(int j=0;j<n;j++){
    if(color[j] != last_color){
      ans++;
      last_color = color[j];
    }
  }

  cout << ans;

  delete [] color;
  return 0;
}

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

using namespace std;

#define int long long
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

typedef pair<int,int> PI;
typedef pair<int,pair<int,int>> PII;
static const int INF=1010000000000000017LL;
static const double eps=1e-12;
static const double pi=3.14159265358979323846;
static const int dx[4]={1,-1,0,0};
static const int dy[4]={0,0,1,-1};
static const int ddx[8]={1,-1,0,0,1,1,-1,-1};
static const int ddy[8]={0,0,1,-1,1,-1,1,-1};

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

template<typename T>
struct Vector2 {
    T x, y;
    Vector2() {}
    Vector2(T x, T y) : x(x), y(y) {}
    void operator=(const Vector2 &other) {
        x = other.x;
        y = other.y;
    }
    Vector2 operator+(const Vector2 &other) {
        return Vector2(x + other.x, y + other.y);
    }
    Vector2 operator-(const Vector2 &other) {
        return Vector2(x - other.x, y - other.y);
    }
    bool operator==(const Vector2 &other) {
        return (x == other.x && y == other.y);
    }
    int dot(Vector2 other) {
        return x * other.x + y * other.y;
    }
    int det(Vector2 other) {
        return x * other.y - y * other.x;
    }
};

template<typename T>
bool cmp_x(const Vector2<T> &p, const Vector2<T> &q) {
    if(p.x != q.x) return p.x < q.x;
    return p.y < q.y;
}

template<typename T>
vector<Vector2<T>> convexhull(vector<Vector2<T>> &ps) {
    sort(ps.begin() , ps.end(), cmp_x<T>);
    int size = ps.size();
    int k = 0;
    if (size <= 2) return ps;
    vector<Vector2<T>> qs(size * 2);
    for (int i = 0; i < size; ++i) {
        while (k > 1 && (qs[k - 2] - qs[k - 1]).det(ps[i] - qs[k - 1]) <= 0) k--;
        qs[k++] = ps[i];
    }
    for (int i = size - 2, t = k; i >= 0; i--) {
        while(k > t && (qs[k - 2] - qs[k - 1]).det(ps[i] - qs[k - 1]) <= 0) k--;
        qs[k++] = ps[i];
    }
    qs.resize(k - 1);
    return qs;
}

int N;
vector<Vector2<int>> P;

signed main(){
    cin>>N;
    for(int i=0;i<N;++i){
        int x,y;
        cin>>x>>y;
        P.push_back(Vector2(x,y));
    }
    auto qs=convexhull(P);
    int ans=0;
    for(int i=0;i<qs.size()-1;++i){
        for(int j=i+1;j<qs.size();++j){
            int d=abs(qs[i].x-qs[j].x)+abs(qs[i].y-qs[j].y);
            chmax(ans,d);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 7456
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

int main() {
    int x[5];
    for (auto& xi:x)
        cin >> xi;

    auto index = distance(begin(x), find(begin(x), end(x), 0));

    cout << (index + 1) << endl;
    return 0;
}


Measured memory_bytes: 3564
n = int(input())
s = input()
table = {x: 2**i for i, x in enumerate(map(chr, range(97, 123)))}

SEG_LEN = n
SEG = [0]*(SEG_LEN*2)


def update(i, x):
    i += SEG_LEN
    SEG[i] = table[x]
    while i > 0:
        i //= 2
        SEG[i] = SEG[i*2] | SEG[i*2+1]


def find(left, right):
    left += SEG_LEN
    right += SEG_LEN
    ans = 0
    while left < right:
        if left % 2 == 1:
            ans = SEG[left] | ans
            left += 1
        left //= 2
        if right % 2 == 1:
            ans = SEG[right-1] | ans
            right -= 1
        right //= 2
    return format(ans, 'b').count('1')


for i, c in enumerate(s):
    update(i, c)

q = int(input())
for _ in range(q):
    com, *query = input().split()
    if com == '1':
        idx, x = query
        update(int(idx)-1, x)
    else:
        L, R = map(int, query)
        print(find(L-1, R))


Measured memory_bytes: 83656
#include<iostream>
#include<map>
#include<algorithm>
#define Pair map<char, pair<char, char> >
#define x first
#define y second
#define mk make_pair

using namespace std;

Pair root;

void init(Pair* root){
  root->insert(mk('A', mk('Y', 'X')));
  root->insert(mk('B', mk('X', 'Y')));
  root->insert(mk('W', mk('Y', 'B')));
  root->insert(mk('X', mk('Z', '.')));
  root->insert(mk('Y', mk('.', 'X')));
  root->insert(mk('Z', mk('B', 'W')));
}

bool solve(string& s){
  char c='A';
  for(int i=0; i<s.size(); ++i){
    c = (s[i] == '1' ? root[c].x : root[c].y);
    if(c == '.') return false;
  }
  return c == 'B';
}

int main(){
  init(&root);
  string s;
  while(1){
    cin >> s;
    if(s == "#") break;
    if(solve(s)) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 1184
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  int a;
  string s;
  cin >> a >> s;
  if(a >= 3200)cout << s << endl;
  else cout << "red" << endl;
}

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



int main() {
  int a, b, c; cin >> a >> b >> c;
  for (int i = 1; i <= b; ++i) if (((a * i) % b) == c) {
    cout << "YES" << endl;
    return 0;
  }
  cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <map>

#define p(a, b) pair<a, b>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x,y,z;
    cin >> x >> y >> z;
    x -= z;
    y += z;
    cout << x/y;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){

	int a[10];
	int temp = 0;

	for(int i=0	;i<10 ;i++) scanf("%d",&a[i]);

	for(int i=0; i<9; i++){
		for(int j=9; j>i; j--){
			if(a[j-1] < a[j]){
				temp = a[j];
				a[j] = a[j-1];
				a[j-1] = temp;
			}
		}
	}

	for(int i=0; i<3; i++) printf("%d\n",a[i]);
}

Measured memory_bytes: 1028
import java.util.Scanner

import scala.annotation.tailrec
import scala.collection.mutable.ArrayBuffer


object Main{
  def read() = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val a = for (_ <- 0 until n) yield sc.nextLong()
    (n, a)
  }

  def divisor(n: Long): IndexedSeq[Long] = {
    val buf = ArrayBuffer.empty[Long]
    for (i <- 1 to Math.sqrt(n).toInt) {
      if (n % i == 0) {
        buf.append(i)
        if (i * i != n) {
          buf.append(n / i)
        }
      }
    }
    buf.toIndexedSeq
  }

  def solve(n: Int, a: IndexedSeq[Long]): Long = {
    val cand = IndexedSeq.concat(divisor(a(0)), divisor(a(1))).distinct.sorted

    def satysfies(x: Long): Boolean = {
      //a.count(ae => ae % x == 0) >= a.length - 1
      a.count(_ % x == 0) >= a.length - 1
    }

    cand.filter(satysfies).max
  }

  @tailrec
  def gcd(x: Long, y: Long): Long = {
    assert(x >= 0 && y >= 0)
    if (y == 0) x else gcd(y, x % y)
  }

  def solve2(n: Int, a: IndexedSeq[Long]): Long = {
    val cumGCDLeft = a.scanLeft(0L)(gcd)
    val cumGCDRight = a.reverse.scanLeft(0L)(gcd).reverse

    // [0, end)
    def subCumGCDLeft(end: Int) = cumGCDLeft(end)

    // [start, n)
    def subCumGCDRight(start: Int) = cumGCDRight(start)

    // [0, i) + [i+1, n)
    (0 until n).map(i => gcd(subCumGCDLeft(i), subCumGCDRight(i + 1))).max
  }

  // O(n^2)愚直解
  def solve3(n: Int, a: IndexedSeq[Long]): Long = {
    // [0, end)
    def subCumGCDLeft(end: Int) = (0 until end).map(a).foldLeft(0L)(gcd)

    // [start, n)
    def subCumGCDRight(start: Int) = (start until n).map(a).foldLeft(0L)(gcd)

    // [0, i) + [i+1, n)
    (0 until n).map(i => gcd(subCumGCDLeft(i), subCumGCDRight(i + 1))).max
  }


  def main(args: Array[String]): Unit = {
    val (n, a) = read()
    println(solve2(n, a))
  }
}

Measured memory_bytes: 53688
dict_ = {}
def collatz(s):
    if s in dict_.keys():
        dict_[s] += 1
        return sum(dict_.values())
    else:
        dict_[s] = 1
        return collatz(s/2) if s%2==0 else collatz(3*s+1)

s = int(input())
print(collatz(s))

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

int main() {
    int edges[3];
    int sha = 0;
    for(int i=0; i<3; i++) {
        cin >> edges[i];
        sha = max(sha, edges[i]);
    }

    int res = 1;
    for(int i=0; i<3; i++) {
        if(edges[i] == sha) continue;
        res *= edges[i];
    }
    res /= 2;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))

ans = 0
t = 0
S = [0]*30

def func(cur, S):
    cur_bi = list(format(cur, 'b'))
    cur_bi = list(reversed(cur_bi))
    flag = True
    for i in range(len(cur_bi)):
        if cur_bi[i] == '1' and S[i] == 1:
            flag = False
            break
    return flag

for s in range(n):
    while t < n and func(A[t], S):
        cur = A[t]
        cur_bi = list(format(cur, 'b'))
        cur_bi = list(reversed(cur_bi))
        for i in range(len(cur_bi)):
            if cur_bi[i] == '1':
                S[i] = 1
        t += 1
    ans += t-s
    if s == t:
        t += 1
    else:
        cur = A[s]
        cur_bi = list(format(cur, 'b'))
        cur_bi = list(reversed(cur_bi))
        for i in range(len(cur_bi)):
            if cur_bi[i] == '1':
                S[i] = 0

print(ans)

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s; cin>>s;
	bool yes = true;
	rep(i, s.size()){
		if (i%2==0){
			if (!(s[i]=='R' || s[i]=='U' || s[i]=='D')){
				yes = false;
				break;
			}
		}else{
			if (!(s[i]=='L' || s[i]=='U' || s[i]=='D')){
				yes = false;
				break;
			}
		}
	}
	if (yes){
		cout << "Yes\n";
	}else{
		cout << "No\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s,ss,sss;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
      
    cin>>s>>ss>>sss;
    if(s[Size(s)-1]!=ss[0]){
        Cout("NO");
        return 0;
    }
    if(ss[Size(ss)-1]!=sss[0]){
        Cout("NO");
        return 0;
    }
    Cout("YES");
    return 0;
}


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

int main(){

  long long n, a[100000], sum=0, cnt=1;

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

  sort(a, a+n);

  for(int i=1;i<n;i++){
    if(a[i]==a[i-1]){
      cnt++;
    }else{
      if(cnt%2) sum++;
      cnt=1;
    }
  }

  if(cnt%2) sum++;

  if(sum>0) cout<<sum<<endl;
  else cout<<0<<endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;

int main(){
    int n;cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> dp(n,INF);
    rep(i,n){
        *lower_bound(dp.begin(),dp.end(),a[i]) = a[i];
    }
    cout << lower_bound(dp.begin(),dp.end(),INF) - dp.begin() << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
const static long long int MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

template<typename T> T combination(T n, T r)
{
    if (r == 0 || r == n)
        return (1);
    else if (r == 1)
        return (n);
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

int main(int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, p, a, even = 0, odd = 0;
    cin >> n >> p;
    rep(i, n) {
        cin >> a;
        if (a % 2) ++odd;
        else ++even;
    }

    llong ans = 0;
    rep(i, odd + 1) {
        if (p) {
            if (i % 2) ans += combination(odd, i);
        } else {
            if (!(i % 2)) ans += combination(odd, i);
        }
    }
    ans *= pow(2, even);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int march[5] = {0, 2, 7, 12, 17};
int main(){
  int N;
  cin >> N;
  long long name[26] = {};
  string S;
  for(int i = 0; i < N; i++){
    cin >> S;
    name[int(S[0]) - 65] += 1;
  }
  long long ans = 0;
  for(int i = 0; i < 3; i++){
    for(int j = i + 1; j < 4; j++){
      for(int k = j + 1; k < 5; k++){
        ans += name[march[i]] * name[march[j]] * name[march[k]];
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main () {
	int a , b;
	double x = 0 , y = 0 , rad = 0 , tmp;
	while (1) {
		scanf("%d,%d,",&a,&b);
		if ( a == 0 && b==0 ) break;
		y += a * cos(rad / 180 * M_PI );
		x += a * sin(rad / 180 * M_PI );
		rad += b;
	}
	printf("%d\n%d\n",(int)x,(int)y);
	return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define all(x) x.begin(), x.end()

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 & y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 & y) {if (x < y) x = y;}
#define int ll
void read() {
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (i % 3 == 0 || i % 5 == 0) continue;
		ans += i;
	}
	cout << ans;
}

void run() {

}

void write() {

}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	read();
	run();
	write();
	return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
const ll inf=5e18;
const int min_pos=-2e9;
ll ans=0;
ll netx[1010],nety[1010];
int xcnt=0,ycnt=0;
struct node{
    int xl=1;
    int xr=1;
    int yu=1;
    int yd=1;
    int mark=0;
}net[1010][1010];
struct p{
    int x;
    int y;
};
queue<p> que;
struct seg{
    int pos;
    int fr;
    int to;
    int pos_rank;
    bool operator<(const seg& seg2){
        return(pos<seg2.pos||
        (pos==seg2.pos&&fr<seg2.fr));
    }
}xseg[1001],yseg[1001],lastx={min_pos},lasty={min_pos};

int lb(ll* q,int l,int r,const int& x){
    while(l<r){
        int mid=(l+r)/2;
        if(x>q[mid])l=mid+1;
        else r=mid;
    }return l;
}

void cutx(const seg& s){
    for(int i=lb(nety,0,ycnt-1,s.fr);nety[i+1]<=s.to;i++){
        net[s.pos_rank-1][i].xr=net[s.pos_rank][i].xl=0;
    }
}
void cuty(const seg& s){
    for(int i=lb(netx,0,xcnt-1,s.fr);netx[i+1]<=s.to;i++){
        net[i][s.pos_rank-1].yu=net[i][s.pos_rank].yd=0;
    }
}
//bfs
void bfs(){
    que.push({lb(netx,0,xcnt-1,0)-1,lb(nety,0,ycnt-1,0)-1});
    do{
        p p1=que.front();
        que.pop();
        int x=p1.x;
        int y=p1.y;
        node& n1=net[x][y];
        if(n1.mark)continue;
        if(x==0||x==xcnt||y==0||y==ycnt){
            ans=inf;
            break;
        }
        ans+=(netx[x+1]-netx[x])*(nety[y+1]-nety[y]);
        n1.mark=1;
        if(n1.xl)que.push({x-1,y});
        if(n1.xr)que.push({x+1,y});
        if(n1.yu)que.push({x,y+1});
        if(n1.yd)que.push({x,y-1});
    }while(!que.empty());
}

int main(){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>xseg[i].fr>>xseg[i].to>>xseg[i].pos;
    }
    for(int i=0;i<m;i++){
        cin>>yseg[i].pos>>yseg[i].fr>>yseg[i].to;
    }
    sort(xseg,xseg+n);
    sort(yseg,yseg+m);
    netx[xcnt++]=min_pos;
    nety[ycnt++]=min_pos;
    for(auto& i:xseg){
        if(i.pos>lastx.pos){
            netx[xcnt++]=lastx.pos=i.pos;
        }i.pos_rank=xcnt-1;
    }
    for(auto& i:yseg){
        if(i.pos>lasty.pos){
            nety[ycnt++]=lasty.pos=i.pos;
        }i.pos_rank=ycnt-1;
    }
    netx[xcnt]=2e9;
    nety[ycnt]=2e9;
    if(0<=netx[1]||0<=nety[1]||0>=netx[xcnt-1]||0>=nety[ycnt-1]){
        cout<<"INF";
        return 0;
    }
    for(int j=0;j<n;j++){
        if(j<n-1)if(xseg[j].pos==xseg[j+1].pos&&xseg[j].to>=xseg[j+1].fr){
            xseg[j+1].fr=xseg[j].fr;
            xseg[j+1].to=max(xseg[j].to,xseg[j+1].to);
            continue;
        }
        cutx(xseg[j]);
        
    }
    for(int j=0;j<m;j++){
        if(j<m-1)if(yseg[j].pos==yseg[j+1].pos&&yseg[j].to>=yseg[j+1].fr){
            yseg[j+1].fr=yseg[j].fr;
            yseg[j+1].to=max(yseg[j].to,yseg[j+1].to);
            continue;
        }
        cuty(yseg[j]);
    }
    bfs();
    if(ans>=inf)cout<<"INF";
    else cout<<ans;
}

Measured memory_bytes: 23472
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define max 100005
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
int main(){
    int n,m;
    cin>>n>>m;
    Graph G(n);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<int> dist(n,-1);
    vector<int> pre(n,-1);
    queue<int> que;

    dist[0]=0;
    que.push(0);

    while(!que.empty()){
        int v=que.front();
        que.pop();
        for(int nv:G[v]){
            if(dist[nv]!=-1)continue;
            dist[nv]=dist[v]+1;
            pre[nv]=v;
            que.push(nv);
        }
    }
    cout<<"Yes"<<endl;
    for(int v=1;v<n;++v){
        cout<<++pre[v]<<endl;
    }
    return 0;
}
    

Measured memory_bytes: 10476
# https://atcoder.jp/contests/code-festival-2016-quala/tasks/codefestival_2016_qualA_c
# 前の方からgreedyに`a`に変えていって、残った回数は最後の一文字で無限に回す?


def ord_until_a(char):
    if char == 'a':
        return 0
    return ord('a') + 26 - ord(char)
    # return 26 - (ord(char) - ord('a'))


S = input()
K = int(input())
ans = []
for s in S:
    diff = ord_until_a(s)
    if K >= diff:
        ans.append('a')
        K -= diff
    else:
        ans.append(s)

if K > 0:
    K %= 26
    last = ord(ans[-1]) + K
    if last > ord('z'):
        last -= 26
    ans[-1] = chr(last)

print(''.join(ans))


Measured memory_bytes: 46576
import java.util.*;

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

        String S = sc.next();
        String T = sc.next();
        sc.close();

        int count = 0;

        for (int i = 0; i < S.length(); i++) {
            if (S.charAt(i) == T.charAt(i))
                count++;
        }

        System.out.println(count);


    }
}

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

int main() {
  int N, M;
  std::cin >> N >> M;

  std::vector<int> A(N);
  for (int i = 0; i < N; i++) std::cin >> A[i];
  int sum{0};
  for (auto&& v : A) sum += v;

  double th = sum * 1.0 / (4 * M);

  int res{0};
  for (auto&& v : A) {
    if (v >= th) res++;
  }
  std::cout << (res >= M ? "Yes" : "No") << std::endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1000000;
// clang-format on

ll N, M;

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

  ll ans = 0;
  if (2 * N < M) {
    ans = N;
    ll left = M - (ll)2 * N;
    ans += (left / 4);
  } else {
    ans = M / 2;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
/*bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}*/

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

const ll mod = 1e9 + 7;
const ll IMF = 1LL<<29;
const double PI = 3.14159265358979323846;


// ***************************CODE**********************//



int main(){

        ll N,k;
        cin >> N >> k;

        ll sum = 0;
        for(ll j = 1; j <= N; j++){
                if(j < k) continue;
                sum += (N/j) * (j-k);
                if(N % j - (k-1) > 0){
                        sum += N % j - (k-1);
                }

        }

        if(k == 0){
                sum = N * N;
        }

        cout << sum << endl;
        return 0;
}


Measured memory_bytes: 256
function Main(input) {
  const lines = input.split("\n");
  const n = +lines[0];
  const rest = lines.slice(1);

  /**
   * 証言一覧
   * @type {[xij, yij][]}
   */
  const rules = [];
  var ai, rule;
  var i, j;
  for (i = 0; i < rest.length; i++) {
    ai = +rest[i];
    rule = [];
    for (j = 1; j <= ai; j++) {
      rule.push(rest[i + j].split(' ').map(Number));
    }
    rules.push(rule);
    i += ai;
  }

  var answer = 0, honestFlags, honestsCount;
  // bit全探索
  for (honestFlags = Math.pow(2, n) - 1; honestFlags > 0; honestFlags--) {
    honestsCount = countHonests(honestFlags);

    // 正直者の数がこれまでの最大値以下なら検証しない
    if (honestsCount <= answer) {
      continue;
    }

    // 矛盾がないかどうか確認
    if (checkIsValid(honestFlags, rules)) {
      answer = honestsCount;
    }
  }

  //出力
  console.log(answer);
}

/**
 * ビットフラグ中の正直者の数をカウント
 * @param {number} honestFlags 正直者ビットフラグ
 */
function countHonests(honestFlags) {
  var tmpHonestFlags = honestFlags;
  var count = 0;
  while (tmpHonestFlags > 0) {
    if (tmpHonestFlags % 2) {
      count++;
    }
    tmpHonestFlags = tmpHonestFlags >> 1;
  }

  return count;
}

/**
 * 証言に矛盾がないかどうか検証
 * @param {number} honestFlags 正直者ビットフラグ
 * @param rules 証言一覧
 */
function checkIsValid(honestFlags, rules) {
  return rules.every((rule, i) => {
    // 証言者が正直者かどうか
    const isHonest = (honestFlags >> i) % 2;
    // 正直者でなければ検証しない
    if (!isHonest) {
      return true;
    }

    // i人目の証言に矛盾がないか確認
    return rule.every((r) => {
      const xij = r[0];
      // xij人目が正直者かどうか(証言)
      const yij = r[1];
      // xij人目が正直者かどうか(実際)
      const xijIsHonest = (honestFlags >> (xij - 1)) % 2;

      return yij === xijIsHonest;
    });
  });
}

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

Measured memory_bytes: 10436