akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

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

        flag=false;
        s=next();

        for(int i=0;i<s.length();i++){
            if(i%2==0){
                if(s.charAt(i)=='R'||s.charAt(i)=='U'||s.charAt(i)=='D'){
                    flag=true;
                }
                else{
                    flag=false;
                    break;
                }
            }
            else{
                if(s.charAt(i)=='L'||s.charAt(i)=='U'||s.charAt(i)=='D'){
                    flag=true;
                }
                else{
                    flag=false;
                    break;
                }
            }
        }
        yesNo(flag);
    }



    public static int nextInt(){
        return Integer.parseInt(scan.next());
    }
    public static long nextLong(){
        return Long.parseLong(scan.next());
    }
    public static String next(){
        return scan.next();
    }
    public static double nextDouble(){
        return Double.parseDouble(scan.next());
    }
    public static float nextFloat(){
        return Float.parseFloat(scan.next());
    }

    //Yes or No
    public static void yesNo(boolean flag){
        if(flag) System.out.println("Yes");
        else System.out.println("No");
    }
    public static void print(Object a){
        System.out.println(a);
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
ll ans=0;
ll gcd(ll a,ll b)
{
	if(b==0)
		return a;
	else{
		ans+=b*2*(a/b);
		return gcd(b,a%b);
	}
}
int main()
{
	ll n;ll x;
	cin>>n>>x;
	ans+=x+(n-x);
	ll l=gcd(x,n-x);
	ans-=l;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<deque>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<tuple>
#include<utility>
#include<vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<vector<int>> vvi;

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define REP(i, n)  for(int i=0; i<(int)(n); i++)
#define REPS(i, n)  for(int i=1; i<=(int)(n); i++)
#define PER(i, n) for(int i=(int)(n)-1; i>= 0; i--)
#define PERS(i, n)  for(int i=(int)(n); i>0; i--)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
#define RFOR(i, c)  for(__typeof((c).rbegin()) i=(c).rbegin(); i!=(c).end(); i++)
#define ALL(container)  (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) (container).size()
#define FILL0(n)  setfill('0') << right << setw(n)
#define mp(a, b)  make_pair(a, b)
#define toLower(c)  c+0x20
#define toUpper(c)  c-0x20
#define pb  push_back
#define eb  emplace_back

const int INF = 1e9;
const long long LLINF = 1e18;
const ll MOD = 1000000007;
const int MSIZE = 100007;
const double Pi = 3.14159265358979323146;

int main(){
  int n, m, x;  cin >> n >> m >> x;
  vi c(n);
  vector<vi> a(n, vi(m));
  REP(i, n){
    cin >> c[i];
    REP(j, m){
      cin >> a[i][j];
    }
  }
  int ans = MOD;
  for(int bits=0; bits<(1<<n); bits++){
    vi skills(m, 0);
    int cst = 0;
    for(int i=0; i<n; i++){
      if((bits>>i)&1){
        cst += c[i];
        for(int j=0; j<m; j++){
          skills[j] += a[i][j];
        }
      }
    }
    bool ok = true;
    for(int i=0; i<m; i++){
      if(skills[i]<x){
        ok = false;
      }
    }
    if(ok){
      ans = min(ans, cst);
    }
  }

  cout << (ans==MOD? -1 : ans) << endl;
}


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

int main()
{
  int N, L[100];
  cin >> N;
  
  for (int i = 0; i < N; i++)
  {
    cin >> L[i];
  }
  
  int count = 0;
  
  for (int i = 0; i < N; i++)
  {
    for (int j = i+1; j < N; j++)
    {
      for (int k = j+1; k < N; k++)
      {
        if (i >= j || j >= k || L[i] == L[j] || L[j] == L[k] || L[k] == L[i]) continue;
        else if ( (L[i]+ L[j] + L[k]) - 2 * max({L[i], L[j], L[k]}) > 0)
        {
          count++;
          //cout << L[i] << ' ' << L[j] << ' ' << L[k] << endl;
        }
      }
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
const int N=2005;
int qa,qb,n;
bool honest[N<<1];

inline int nxi(FILE *fd=stdin){
	int x=0;
	char c;
	while((c=fgetc(fd))>'9'||c<'0');
	while(x=x*10-48+c,(c=fgetc(fd))>='0'&&c<='9');
	return x;
}

int main(){
	static int stk[N<<1];
	int top=0;
	qa=nxi(),qb=nxi();
	if(qa<=qb){
		puts("Impossible");
		return 0;
	}
	n=qa+qb;
	for(int i=0; i<n; ++i){
		if(!top) stk[++top]=i;
		else{
			printf("? %d %d\n",stk[top],i);
			fflush(stdout);
			char c;
			while((c=getchar())!='N'&&c!='Y');
			if(c=='N') --top;
			else stk[++top]=i;
		}
	}
	int rt=stk[top];
	honest[rt]=1;
	for(int i=0; i<n; ++i){
		if(i==rt) continue;
		printf("? %d %d\n",rt,i);
		fflush(stdout);
		char c;
		while((c=getchar())!='N'&&c!='Y');
		honest[i]=c=='Y';
	}
	printf("!");
	for(int i=0; i<n; ++i){
		putchar(honest[i]+'0');
	}
	puts("");
	return 0;
}


Measured memory_bytes: 724
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i < (int)n;i++)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int N;
    cin >> N;
    int tmp;
    int count = 0;
    rep(i,N)
    {
        cin >> tmp;
        if(tmp % 2 == 1)
            count++;
    }
    if(count % 2 == 1)
        cout << "NO\n";
    else
        cout << "YES\n";
}

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


void solve(long long N, long long K){
     N = N % K;
     cout << min(N, abs(N-K)) << endl;

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    solve(N, K);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<28)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int x, y;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> x >> y;
    if (x % y) cout << x << endl;
    else cout << -1 << endl;
    return 0;
}

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

int main(){
    int w,h,x,y;
    cin >> w >> h >> x >> y;
    double ans =(double)w*h/2;
    int num = (w==x*2 && h==y*2) ? 1 :0;
    printf("%.10f %d\n",ans, num);
    return 0;
}

Measured memory_bytes: 256
// C++ 14
#include <bits/stdc++.h>
using namespace std;
template <typename T>  ostream& operator<<(ostream& os, const vector<T>& v)  {  os << "[";  for (int i = 0; i < v.size(); ++i) {  os << v[i];  if (i != v.size() - 1)  os << ", ";  }  os << "]";  return os;  }
template <typename T> void print(T v, string s = "\n") { cout << v << s; }
template <typename T> void in(T &v) { cin >> v; }
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

int main() {
  int n;in(n);
  if (n>=30) print("Yes");
  else print("No");
  return 0;
}


Measured memory_bytes: 3624
# require 'pry'
# binding.pry

h, w=gets.chomp.split.map(&:to_i)

if h%3==0 or w%3==0
  puts 0
else
  dif=10**12
  hh=h/2
  (1...w).each do |j|
    x=hh*j
    y=(h-hh)*j
    z=h*(w-j)
    d=[x, y, z].max-[x, y, z].min
    dif=[dif, d].min
  end
  dif=[dif, h].min

  h, w=w, h
  hh=h/2
  (1...w).each do |j|
    x=hh*j
    y=(h-hh)*j
    z=h*(w-j)
    d=[x, y, z].max-[x, y, z].min
    dif=[dif, d].min
  end
  dif=[dif, h].min
  
  puts dif
end

=begin
x+y+z=h*w (x<=y<=z)
a*b+c*d+e*f=h*w
=end


Measured memory_bytes: 1788
a,b,c,k = map(int,input().split())

tmp = k
ans = 0
k -= a
if k <= 0:
    print(tmp)
    exit()
ans += a
k -= b
if k <= 0:
    print(ans)
    exit()
k -= c
if k <= 0:
    print(a - (tmp-(a+b)))
    exit()
ans -= c
print(ans)


Measured memory_bytes: 61804
h,w=map(int,input().split())
field=[[int(i) for i in input().split()] for i in range(10)]
wall=[[int(i) for i in input().split()] for i in range(h)]


def warshall_floyd(d,n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d
    
warshall_floyd(field,10)

ans=0
for i in wall:
    for j in i:
        if j!=-1 and j!=1:
            ans+=field[j][1]
print(ans)

Measured memory_bytes: 3316
//ABC073C
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	int n;
	long long int T;
	cin >> n >> T;
	vector<long long int> t(n);
	long long int ans = 0;
	for(int i=0;i<n;i++){
		cin >> t.at(i);
	}
	for(int i=0;i<n;i++){
		if(i == n-1){
			ans += T;
		}else{
			ans += min(t.at(i+1)-t.at(i),T);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

// linear search
int search(int A[], int n, int key)
{
    int i = 0;
    A[n] = key;
    while (A[i] != key) i++;
    return i != n;
}

int main()
{
    int i, n, A[10001], q, key, sum = 0;

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }
    
    scanf("%d", &q);
    for (i = 0; i < q; i++) {
        scanf("%d", &key);
        if (search(A, n, key)) sum++;
    }
    printf("%d\n", sum);

    return 0;
}


Measured memory_bytes: 2776
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
//#include <list>
#include <iomanip>
//#include <stdlib.h>
//#include <cctype>

using namespace std;

const int MAX_N = 1000000;
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)

void printVec(std::vector<int> &vec) {
//    std::cout << "";
    for (auto it = vec.begin(); it != vec.end(); ++it) {
        std::cout << *it << " ";
    }
    cout << '\n';
}

void printVec1(std::vector<string> &vec) {
//    std::cout << "";
    for (auto it = vec.begin(); it != vec.end(); ++it) {
        std::cout << *it << " ";
    }
    cout << '\n';
}

void printVec2(std::vector<Int> &vec) {
//    std::cout << "";
    for (auto it = vec.begin(); it != vec.end(); ++it) {
        std::cout << *it << " ";
    }
    cout << '\n';
}

Int gcd(Int a, Int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

Int lcm(Int a, Int b) {
    return a / gcd(a, b) * b;
    //a*bは64bit integer overflow
}

bool integer(double num) {
    return floor(num) == num;
}

Int fact(int num) {
    if (num == 0)
        return 1;
    else
        return num * fact(num - 1);
}

int n;
int a;
int x[52];
bool dfs(int i,int sum,int cnt){
    if(i==n) return a==(sum/cnt);
    if(dfs(i+1,sum,cnt))return true;
    if(dfs(i+1,sum+x[i],cnt+1))return true;
    return false;
}

int cnt=0;
int main() {
    IOS;
    //prec;
    //std::ifstream in("01-04.txt");
    //std::cin.rdbuf(in.rdbuf());
    int n;cin>>n;
    vector<Int>d(n);
    for (int i = 0; i <n ; ++i) {
        cin>>d[i];
    }
    int m;cin>>m;
    vector<Int>t(m);
    for (int i = 0; i <m ; ++i) {
        cin>>t[i];
    }
    ssort(d);ssort(t);
    Int check=t[0];
    Int now=0;
    for (int i = 0; i <n ; ++i) {
        if(d[i]==check){
            now++;
            check=t[now];
        }
    }
    if(now==m)cout<<"YES";
    else cout<<"NO";


    cout << endl;
    return 0;
}

/*
テレビも無ェ ラジオも無ェ
自動車もそれほど走って無ェ
ピアノも無ェ バーも無ェ
巡査 毎日ぐーるぐる
朝起ぎで 牛連れで
二時間ちょっとの散歩道
電話も無ェ 瓦斯も無ェ
バスは一日一度来る
俺らこんな村いやだ 俺らこんな村いやだ
東京へ出るだ 東京へ出だなら
銭コァ貯めで 東京でベコ(牛)飼うだ
*/


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int dp[3005][3005];

int main(){
  int N, T;
  cin >> N >> T;
  vector<vector<int>> v;
  rep(i,N){
    int a, b;
    cin >> a >> b;
    v.push_back({a,b});
  }
  sort(ALLOF(v));

  rep(i,3005) rep(j,3005) dp[i][j] = -1;
  
  dp[0][0] = 0;
  rep(i,N){
    int t = v[i][0];
    int x = v[i][1];
    
    rep(j,T){
      if(dp[i][j] == -1) continue;
      dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
      dp[i+1][min(T,j+t)] = max(dp[i+1][min(T,j+t)], dp[i][j] + x);
    }
    dp[i+1][T] = max(dp[i+1][T], dp[i][T]);
  }

  int ret = 0;
  rep(i,T+1){
    //cout << i << "\t" << dp[N][i] << endl;
    ret = max(ret, dp[N][i]);
  }

  cout << ret << endl;
  
  return 0;
}


Measured memory_bytes: 35712
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;
int main(){
  string a;
  cin >> a;
  for(int i = 0;i <= a.size() - 1;i++){
    if(i == a.size() - 1){
      cout << "x" << endl;
    }
    else{
      cout << "x";
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int tot = 0;
  int mnidx = 0;
  for (int i = 0; i < n; i++) tot += a[i];
  for (int i = 0; i < n; i++)
    if (abs(n * a[i] - tot) < abs(n * a[mnidx] - tot))
      mnidx = i;
  cout << mnidx << '\n';
  return 0;
}

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

void Main() {
  int n, m;
  cin >> n >> m;
  int ac[n], wa[n];

  memset(ac, 0, sizeof(ac));
  memset(wa, 0, sizeof(wa));
  for (int i = 0; i < m; i++) {
    int p;
    string s;
    cin >> p >> s;
    if (s == "AC") ac[p - 1] = 1;
    else {
      if (!ac[p - 1]) wa[p - 1] += 1;
    }
  }

  int ans = 0, pena = 0;
  for (int i = 0; i < n; i++) {
    ans += ac[i];
    if (ac[i]) pena += wa[i];
  }
  cout << ans << " " << pena << endl;
}

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


Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
using namespace std;


int main(void)
{
	int N; cin >> N;
	string S; cin >> S;
	int max_x = 0, tmp_x = 0;
	rep(i, 0, N) {
		if (S[i] == 'I')tmp_x++;
		else tmp_x--;
		max_x = max(max_x, tmp_x);
	}
	cout << max_x << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,ten[100],i,max=0,min=1000,sum=0,ave=0;

  while(1){
    max=0;
    min=1000;
    sum=0;
    ave=0;
    scanf("%d",&a);
    if(a==0)break;
    else{
      for(i=0;i<a;i++){
	scanf("%d",&ten[i]);
      }
      for(i=0;i<a;i++){
	if(max<ten[i]){
	  max=ten[i];
	}
      }
      for(i=0;i<a;i++){
	if(min>ten[i]){
	  min=ten[i];
	}
      }
      
      for(i=0;i<a;i++){
	sum+=ten[i];
      }
      ave=(sum-max-min)/(a-2);
      printf("%d\n",ave);
    }
  }


return 0;
}

Measured memory_bytes: 1028
/***** author :  C0d1ngPhenomena *****/

#include <bits/stdc++.h>
#define endl "\n"
#define ll long long int
#define TestCases int T; cin>>T; while(T--)
#define rep(i,a,b) for(ll i = a; i < b; i++)
#define revrep(i,a,b) for(ll i = b-1; i >= a; i--)
#define vll vector<ll>
#define vvll vector < vll >
#define pll pair<ll, ll>
#define vpll vector <pll>
#define mp(x,y) make_pair(x,y)
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define alld(c) c.begin(),c.end(),greater<int>()
#define mem(a,val) memset(a,val,sizeof(a))
#define f first
#define s second
#define pb push_back
using namespace std;

bool sortbysec(const pair<int, int> &a, const pair<int, int> &b)
{
	return (a.second < b.second);
}





int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin >> n;
	vll heights(n);

	rep(i, 0, n)
	cin >> heights[i];

	vll dp(n + 1);
	dp[1] = abs(heights[1]-heights[0]);

	rep(i, 2, n)
	{
		dp[i] = dp[i-1] + abs(heights[i-1] - heights[i]);
		dp[i] = min(dp[i], dp[i-2] + abs(heights[i-2] - heights[i]));

	}

	cout << dp[n-1];

	return 0;
}







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

int main() {
    int s;
    cin >> s;
    vector<int> ans(1, s);
    int cnt = 1;
    while (1) {
        cnt++;
        if (s % 2 == 0) {
            s /= 2;
        }
        else{
            s = 3 * s + 1;
        }
        auto itr = find(ans.begin(), ans.end(), s);
        if (itr == ans.end()) ans.push_back(s);
        else {
            cout << cnt << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(ll i=(x);i<(y);i++)
#define disp(a) cout << a << endl;
typedef long long ll;
using namespace std;
int main()
{
	int N, D, X, ANS = 0;
	vector<int>A;
	cin >> N >> D >> X;
	fore(i, 0, N) {
		int t;
		cin >> t;
		A.push_back(t);
	}
	for (int i = 0;i<N;i++) {
		for (int j = 0;;++j) {
			if (D>=j*A[i]+1) {
				ANS++;
			}
			else {
				break;
			}
		}
	}
	cout << ANS + X << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

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

  public void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      String op;
      String[] words;
      Tree tree = new Tree();

      for(int i=0,k=0; i<n; i++,k=0){
        words = br.readLine().split(" ");
        op  = words[k++];
        if ( op.equals("insert") ) { 
          tree.insert(Integer.parseInt(words[k++]));
        }
        else {
          tree.dispRoundPath();
        }
      }

    }
    catch(IOException e) {
      System.out.println("IOException!");
    }
  }
}

class Tree {

  static final BTreeNode NIL = new BTreeNode();
  BTreeNode root;
  StringBuilder buf;

  public Tree() {
    root = NIL;
    buf = new StringBuilder();
  }

  public void insert(int val) {
    BTreeNode y = NIL;
    BTreeNode x = root;
    BTreeNode z = new BTreeNode();
    z.key = val;

    while( !x.equals(NIL) ) {
      y = x;
      if( z.key < x.key )
        x = x.left;
      else
        x = x.right;
    }
    z.parent = y;

    if( y.equals(NIL) ){
      root = z;
    }
    else if( z.key < y.key )
      y.left = z;
    else
      y.right = z;
  } 
  void preParse(BTreeNode u) {
    if( !u.equals(NIL) ) {
      buf.append(" ").append(u.key);
      preParse(u.left);
      preParse(u.right);
    }
  }
  void inParse(BTreeNode u) {
    if( !u.equals(NIL) ) {
      inParse(u.left);
      buf.append(" ").append(u.key);
      inParse(u.right);
    }
  }

  void dispRoundPath() {

    inParse(root);
    buf.append("\n");
    preParse(root);
    buf.append("\n");

    System.out.print(buf);
    buf.setLength(0);
  }
}

class BTreeNode {
  int key;
  BTreeNode parent,left,right;

  public BTreeNode() {
    this.key = -1;
    this.parent =
    this.left =
    this.right = Tree.NIL;
  }

  @Override
  public boolean equals(Object o) {
    if(o == this) return true;
    if(o == null) return false;
    if(!(o instanceof BTreeNode)) return false;

    BTreeNode node = (BTreeNode)o;
    if(!(this.key == node.key)) return false;

    return true;
  }
}


Measured memory_bytes: 126568
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {  
    int n; cin >> n;
    vector<bool> col(10, false); int over = 0, und = 0;
    rep(i, n){
        int a; cin >> a;
        if(a >=3200)over++;
        else{
            if(col[a/400] == false){col[a/400] = true; und++;}
        }
    }
    cout << max(1, und) << " " << min(n, und+over) << ln;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
 
using namespace std;

int binpow(int,int);
void dfs( vector< vector<int> >&, int , vector<int>& );
void bfs( vector< vector<int> >&, int , vector<int>& );

void solve()
{
    int n;
    cin>>n;

    vector<int> a(n);

    rep(i,0,a.size())
    {
        cin>>a[i];
    }

    vector<int> v1;
    vector<int> v2;

    rep(i,0,a.size())
    {
        v1.pb(a[i]+i+1);
        v2.pb(i+1-a[i]);
    }

    map< int,vector<int> > p;

    rep(i,0,v2.size())
    {
        p[v2[i]].pb(i);
    }
    int cnt = 0;
    rep(i,0,v1.size())
    {
        rep(j,0,p[v1[i]].size())
        {
            if ( i <= p[v1[i]][j] )
            {
                cnt += p[v1[i]].size()-j;
                break;
            }
        }
    }

    cout<<cnt<<endl;
}

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

void dfs ( vector< vector<int> > &v , int x , vector<int> &vis )
{
    vis[x] = 1;

    rep(i,0,v[x].size())
    {
        if( vis[v[x][i]] == 0 )
        {
            dfs(v,v[x][i],vis);
        }
    }
}

void bfs( vector< vector<int> > &v , int x , vector<int> &vis )
{
    queue<int> q;
    q.push(x);

    while( !q.empty() )
    {
        int p = q.front();
        q.pop();

        rep(i,0,v[p].size())
        {
            if ( vis[v[p][i]] == 0 )
            {
                vis[v[p][i]] = 1;
                q.push(v[p][i]);
            }
        }
    }
}

Measured memory_bytes: 42056
#include <iostream>
#include <vector>
#include <string>
#include <stddef.h>
#include <algorithm>

class Dice {
private:
	std::vector<int> faces;

	void setFaces(int f1, int f2, int f3, int f4, int f5, int f6) {
		faces[0] = f1;
		faces[1] = f2;
		faces[2] = f3;
		faces[3] = f4;
		faces[4] = f5;
		faces[5] = f6;
	}
	void toTop(int idx) {
		switch (idx) {
		case 0:
			break;
		case 1:
			roll('N');
			break;
		case 2:
			roll('W');
			break;
		case 3:
			roll('E');
			break;
		case 4:
			roll('S');
			break;
		case 5:
			roll('N');
			roll('N');
			break;
		}

	}
	void rotate() {
		setFaces(faces[0], faces[3], faces[1], faces[4], faces[2], faces[5]);
	}
	bool facesEqual(Dice dice2) {
		if (faces.size() == dice2.faces.size()) {
			for (int i = 0; i < faces.size(); i++) {
				if (faces[i] != dice2.faces[i])
					return false;
			}
			return true;
		}
		else
			return false;
		
	}
public:
	Dice() {}
	void readInValues() {
		int val;
		faces.clear();
		for (int i = 0; i < 6; i++) {
			std::cin >> val;
			faces.push_back(val);
		}
	}

	int getTop() {
		return faces[0];
	}
	int getFront() {
		return faces[1];
	}
	int getRight() {
		return faces[2];
	}
	int getLeft() {
		return faces[3];
	}
	int getBack() {
		return faces[4];
	}
	int getBot() {
		return faces[5];
	}

	void roll(char dir) {
		switch (dir) {
		case 'N':
			setFaces(faces[1], faces[5], faces[2], faces[3], faces[0], faces[4]);
			break;
		case 'S':
			setFaces(faces[4], faces[0], faces[2], faces[3], faces[5], faces[1]);
			break;
		case 'W':
			setFaces(faces[2], faces[1], faces[5], faces[0], faces[4], faces[3]);
			break;
		case 'E':
			setFaces(faces[3], faces[1], faces[0], faces[5], faces[4], faces[2]);
			break;
		}
	}

	bool findTopFront(int top, int front) {
		ptrdiff_t top_pos = std::find(faces.begin(), faces.end(), top) - faces.begin();
		if (faces.size() > top_pos) {
			toTop(top_pos);
		}
		ptrdiff_t front_pos = std::find(faces.begin(), faces.end(), front) - faces.begin();
		if (faces.size() - 1 > front_pos) {
			while (getFront() != front) {
				rotate();
			}
		}
		else
			return false;
		return true;

	}

	bool isSame(Dice dice2) {
		std::string sequence = "NWWWN";
		for (std::string::iterator it = sequence.begin(); it <= sequence.end();it++) {
			for (int i = 0; i < 4; i++) {
				if (facesEqual(dice2))
					return true;
				rotate();
			}
			roll(*it);
		}
		return false;
	}


};

int main()
{
	Dice dice1, dice2;
	int val;
	dice1.readInValues();
	dice2.readInValues();

	if (dice1.isSame(dice2))
		std::cout << "Yes\n";
	else
		std::cout << "No\n";
	return 0;
}



Measured memory_bytes: 3240
// Hovalhagh
// Ya Aziz & Hakim
// AliReza Kaboli

#include <bits/stdc++.h>

using namespace std;

int main() {
	int d, n;
	cin >> d >> n;
	for (int i = 1; i <= 1e7; ++i) {
		int sa = i, cnt = 0;
		while (sa % 100 == 0) {
			sa /= 100;
			++cnt;
		}
		if (cnt == d) {
			--n;
			if (!n) {
				cout << i << '\n';
				return 0;
			}
		}
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
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 main(){
    string sa, sb, sc; cin>>sa>>sb>>sc;
    ll a=0, b=0, c=0;
    ll next=1;
    while(true){
        if(next==1){
            if(a==sa.size()){
                cout<<'A'<<endl;
                return 0;
            }
            next=sa[a]-'a'+1;
            a++;
        }else if(next==2){
            if(b==sb.size()){
                cout<<'B'<<endl;
                return 0;
            }
            next=sb[b]-'a'+1;
            b++;
        }else if(next==3){
            if(c==sc.size()){
                cout<<'C'<<endl;
                return 0;
            }
            next=sc[c]-'a'+1;
            c++;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ;
int a[100000] ,n ,k ;
bool dp[100000][2] , A[100000][2] ;

bool f(int i,int turn)
{
    if( i == 0 ) return false ;
    if( i < 0 ) return true ;
    if( A[i][turn] ) return dp[i][turn] ;
    A[i][turn] = true ;
    for( int j = 0 ; j < n ; j++ )
    {
        if( f(i-a[j] , 1 - turn ) == false )
            return  dp[i][turn] = true ;
    }
    return dp[i][turn] = false ;

}

int main()
{
    ios_base :: sync_with_stdio(NULL) ;
    cin.tie(false) ;
    cin >> n >> k ;
    for(int i=0;i<n;i++) {
        cin >> a[i] ;
        A[i][0] = A[i][1] = false ;
    }

    if( f(k,0) ) cout << "First" ;
    else cout << "Second" ;

    return 0;
}


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

typedef struct node {
  int key;
  struct node *prev;
  struct node *next;
} node_t;

node_t *null;

void init() {
  null = malloc(sizeof(node_t));
  null->prev = null;
  null->next = null;
}

void insert(int key) {
  node_t *x;
  x = malloc(sizeof(node_t));
  x->key = key;
  x->next = null->next;
  null->next->prev = x;
  x->prev = null;
  null->next = x;
  if (x->next == null) {
    null->prev = x;
  }
}

node_t *NodeSearch(int key) {
  node_t *ret = null->next;
  while (ret != null && ret->key != key) {
    ret = ret->next;
  }
  return ret;
}

void delete(node_t *x) {
  if (x == null) return;
  x->next->prev = x->prev;
  x->prev->next = x->next;
  free(x);
}

void deleteFirst() {
  delete(null->next);
}

void deleteLast() {
  delete(null->prev);
}

void PrintNode() {
  node_t *p = null->next;
  while (1) {
    printf("%d", p->key);
    if (p->next == null) break;
    putchar(' ');
    p = p->next;
  }
  putchar('\n');
}

int main() {
  int n;
  int i;
  int key;
  char cmd[20];

  scanf("%d", &n);

  init();

  for (i = 0; i < n; i++) {
    scanf("%s", cmd);
    if (!strcmp(cmd, "insert")) {
      scanf("%d", &key);
      insert(key);
    }
    else if (!strcmp(cmd, "delete")) {
      scanf("%d", &key);
      node_t *tmp = NodeSearch(key);
      delete(tmp);
    }
    else if (!strcmp(cmd, "deleteFirst")) {
      deleteFirst();
    }
    else if (!strcmp(cmd, "deleteLast")) {
      deleteLast();
    }
  }

  PrintNode();
  
  return 0;
}



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

using namespace std;

struct BipartiteMatching
{
  vector< vector<int> > G;
  vector<int> matched;
  vector<bool> used;
  BipartiteMatching(int V):G(V), matched(V, -1), used(V, false){}
  void add_edge(int u, int v)
  {
    G[u].emplace_back(v);
    G[v].emplace_back(u);
  }
  bool dfs(int u)
  {
    used[u] = true;
    for(auto& v : G[u]) {
      int w = matched[v];
      if(w < 0 || !used[w] && dfs(w)) {
	matched[u] = v;
	matched[v] = u;
	return true;
      }
    }
    return false;
  }
  int match()
  {
    int res = 0;
    for(int u = 0; u < G.size(); u++) {
      if(matched[u] < 0) {
	used.clear(); used.resize(G.size(), false);
	if(dfs(u)) res++;
      }
    }
    return res;
  }
};

int main()
{
  int m, n;
  while(cin >> m >> n, m || n) {
    vector<int> b(m), r(n);
    for(int i = 0; i < m; i++) cin >> b[i];
    for(int i = 0; i < n; i++) cin >> r[i];
    BipartiteMatching bimatch(m + n);
    for(int i = 0; i < m; i++) {
      for(int j = 0; j < n; j++) {
	if(__gcd(b[i], r[j]) > 1) bimatch.add_edge(i, m + j);
      }
    }
    cout << bimatch.match() << endl;
  }
  return 0;
}

Measured memory_bytes: 4496
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll a,b,c;
    cin >> a >> b >> c;
    if(a == b){ cout << c; return 0; }
    if(a == c){ cout << b; return 0; }
    if(c == b){ cout << a; return 0; }
    cout << endl;
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
from collections import deque
N = int(input())
A = list(map(int, input().split()))

A.sort()
A = deque(A)
while len(A) > 1:
  s = []
  for i in range(len(A)-1):
    div = A[-1] % A[0]
    A.pop()
    if div != 0:
      s.append(div)
  s.append(A[0])
  s.sort()
  A = deque(s)
print(*A)


Measured memory_bytes: 20460
#include <iostream>
#include <string>
using namespace std;
string a,b;

int main(){
	cin>>a>>b;
	if(a[0]==b[2]&&a[1]==b[1]&&a[2]==b[0]){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
using System;

public class Program
{
  static public void Main ()
  {
    String[] ints = Console.ReadLine().Split(' ');
    int a = int.Parse(ints[0]);
    int b = int.Parse(ints[1]);
    int bmax = b - a;
    int ans = 0;
    for(int i = 1; i <= bmax; ++i) ans += i;
    Console.WriteLine (ans - b);
  }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(j, m) for (int j = 0; j < (int)(m); j++)
#define rep2(i, l, n) for (int i = l; i < (int)(n); i++)


int main() {
    string S;
    cin >> S;
    rep(i,S.size()) {
        if (i%2 == 0) {
            cout << S[i];
        }
    }
    cout << endl;
}



Measured memory_bytes: 3660
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<unordered_set>
#include<cmath>
#include<tuple>
#include<numeric>
#include<iterator>
#include<set>
#include<unordered_map>
#include<map>


#define fastio                      ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define lp(i , aa , bb)             for(auto i = aa ; i < bb ; i++)
#define dbg(a)                      cout << "here is " << a << "\n";
#define ain(a , n)                  for(auto i = 0 ; i < n ; i++) cin >> a[i]
#define aout(a , n)                 for(auto i = 0 ; i < n ; i++) cout << a[i] << " "
#define dist(a , b , x , y)         abs(x - a)*abs(x - a) + abs(y - b)*abs(y - b)
#define M                           998244353
#define mp                          make_pair
#define mt                          make_tuple
#define cend                        cout << "\n"

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <char> vch;
typedef vector <string> vs;

/*----------------------------- # --- MATH ALGORITHMS --- # -----------------------------*/

template <class T> T gcd(T a , T b){ while(a != 0){T temp = a; a = b % a; b = temp;}return b;}
template <class T> T egcd(T a , T b , T &x , T &y){T gcd , xt , yt;if(a == 0){gcd = b;x = 0 , y = 1;}else {gcd = egcd(b % a , a , xt , yt);x = yt - (b/a)*xt; y = xt;}return gcd;}
template <class T> T expo(T base , T exp , T mod){T res = 1;base = base % mod;while (exp > 0){if (exp & 1)res = (res*base) % mod;exp = exp>>1;base = (base*base) % mod;}return res;}
template <class T> T modinv(T a , T mod){T x , y; egcd<T>(a , mod , x , y);while(x < 0) x += mod; while(x >= mod) x -= mod; return x;}
template <class T> T modinvfermat(T a , T mod){return expo<T>(a , mod - 2 , mod);}
template <class T> bool rev(T a , T b){return a > b;}
template <class T> int maxpower(T a , T b){int ans = 0;while(a > 0 && a % b == 0){ans++;a /= b;}return ans;}


/*----------------------------- # --- MAIN CODE --- # -----------------------------*/
int dp[101][101];
int h , w;
char c[101][101];
int f(int i , int j){
    if(i == h - 1 && j == w - 1) return c[i][j] == '#';
    if(i >= h || j >= w) return 1000000000;
    if(dp[i + 1][j] == -1) dp[i + 1][j] = f(i + 1 , j);
    if(dp[i][j + 1] == -1) dp[i][j + 1] = f(i , j + 1);
    int ans = 0 , a = 0 , b = 0;
    if(i < h && j < w && c[i][j] == '#'){
        if(i + 1 < h && j < w && c[i + 1][j] == '.') a++;
        if(i < h && j + 1 < w && c[i][j + 1] == '.') b++;
    }
    dp[i][j] = min(dp[i + 1][j] + a , dp[i][j + 1] + b) + ans;
    return dp[i][j];
}

int main(){
    cin >> h >> w;
    lp(i , 0 , h){
        lp(j , 0 , w){
            cin >> c[i][j];
        }
    }
    lp(i , 0 , 101){
        lp(j , 0 , 101){
            dp[i][j] = -1;
        }
    }
    cout << f(0 , 0);
}

















Measured memory_bytes: 384
//#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
#define mp make_pair
#define f first
#define s second
#define pb push_back

const int N = 1e5 + 5;
const int OO = 2e9;

void init() {

}

int X1,Y1,X2,Y2;

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> X1 >> Y1 >> X2 >> Y2;

    cout << X2+Y1-Y2 << ' ' << Y2+X2-X1 << ' ' << X1+Y1-Y2 << ' ' << Y1+X2-X1 << '\n';

    return 0;

}

Measured memory_bytes: 256
mod=10**9+7
f=[1]
for i in range(2*10**6+7):f+=[f[-1]*(i+1)%mod]
def comb(a,b):return f[a]*pow(f[b],mod-2,mod)*pow(f[a-b],mod-2,mod)%mod
k=int(input())
s=input()
n=len(s)
ans=0
for i in range(k,-1,-1):
  ans+=comb(n+k,i)*pow(25,i,mod)
  ans%=mod
print(ans%mod)

Measured memory_bytes: 149952
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> namespace mp = boost::multiprecision; //mp::cpp_intで宣言
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
//ll inf=(ll)1E12;//10^12
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
//const long double EPS=1E-8;
////////////////////////////////////////

ll gcd(ll a,ll b){
    if(a>b)swap(a,b);
    if(a==0)return b;
    else return gcd(b%a,a);
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    
    ll n,m;cin>>n>>m;
    string s,t;cin>>s>>t;
    ll g=gcd(n,m);
    ll l=n*m/g;
    
    
    ll np=0,mp=0;
    while(np<l&&mp<l){
        if(np==mp){
            if(s[np*n/l]!=t[mp*m/l]){
                cout<<-1<<endl;
                return 0;
            }else{
                np+=l/n;
                mp+=l/m;
            }
        }else if(np>mp){
            mp+=l/m;
        }else{
            np+=l/n;
        }
    }
    cout<<l<<endl;
    
    return 0;
}
//ios::sync_with_stdio(false);cin.tie(0);


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool f[114514];
ll cnt[114514];
int main(){
	ll n,m;
	cin>>n>>m;
	ll ansac=0,answa=0;
	for(int i=0;i<m;i++){
		ll x;
		string s;
		cin>>x>>s;
		if(!f[x]){
			if(s=="WA")cnt[x]++;
			else {
				f[x]=1;
				ansac++;
				answa+=cnt[x];
			}
		}
	}
	cout<<ansac<<' '<<answa;
	return 0;
}


Measured memory_bytes: 1152
import math
N = int(input())
C = [0 for i in range(N)]
S = [0 for i in range(N)]
F = [0 for i in range(N)]
for i in range(N-1):
    C[i], S[i], F[i] = map(int, input().split())
for i in range(N):
    x = S[i] + C[i]
    for j in range(i+1,N-1):
        if x < S[j]:
            x = S[j] + C[j]
        else:
            x = S[j] + F[j] * math.ceil((x - S[j]) / F[j]) + C[j]
    print(x)

Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for(int i=0;i<n;i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;  
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VII;   // VII a(n,vector<int>(m)) n * m 
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b){
    if (a < b){ a = b;return 1;}
    return 0;
}
template <class T, class U> //chmin(min,a)
bool chmin(T &a, U b){
    if (a > b){ a = b; return 1;}
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}
   
// g++ -std=c++11 prac.cpp 
int main(){
    ll x=0,y,z,n,m=0,k,h,w,sum=0,ans=1,Max=-1e9,count=0,Min=1e9+1;
    string s,t,u1,u2;
    bool ok=false;
    cin >> s;
    VI alpha(26);
    if(s.size() < 26){
        rep(i,s.size()){
            alpha[s[i]-'a']++;
        }
        rep(i,26){
            if(alpha[i]==0){
                x = i;
                break;
            }
        }   
        cout << s + (char)(x+'a') << endl;
        return 0;
    }
    else{
        for(int i = s.size()-2; i>=0;i--){
            if(s[i] < s[i+1]){
                char c = s[i+1];
                for(int j=i+1; j<s.size();j++){
                    if(s[j] > s[i])
                        c = min(c,s[j]);
                }
                s[i] = c;
                s = s.substr(0,i+1);
                cout << s << endl;
                return 0;
            }
        }
        cout << -1 << endl;
    }
    return 0;
}

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

long long n , k , sum;

int main ( void )
{
	cin >> n >> k;
	for ( int i = k + 1 ; i <= n ; i++ ) {
		if ( n % i >= k - 1 ) {
			sum += ( n / i ) * ( i - k ) + ( n % i ) - k + 1;
		} else {
			sum += ( n / i ) * ( i - k );
		}
	}
	if ( k == 0 ) {
		sum -= n;
	}
	cout << sum << endl;
	return 0;
}

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

int main(){
    int N, sum=0;
    int s[4];
    string S;
    for(int i=0; i<4; i++) s[i] = 0;

    cin >> N;
    for(int i=0; i<N; i++){
        cin >> S;
        if(S=="P"){
            s[0]=1;
        }else if(S=="W"){
            s[1]=1;
        }else if(S=="G"){
            s[2]=1;
        }else if(S=="Y"){
            s[3]=1;
        }
    }

    for(int i=0; i<4; i++){
        sum+=s[i];
    }
    if(sum==3){
        cout << "Three" << endl;
    }else{
        cout << "Four" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){

	char txt[256];
	scanf("%s",txt);

	if(txt[0]=='S'){
		printf("Cloudy");
	}else if(txt[0]=='C'){
		printf("Rainy");
	}else if(txt[0]=='R'){
		printf("Sunny");
	}

}


Measured memory_bytes: 128
#include <stdio.h>
#include <algorithm>
#include <map>
using namespace std;

int N,X[202],Y[202];

int gcd(int a, int b)
{
	return b ? gcd(b,a%b) : a;
}

int main()
{
	scanf ("%d",&N);
	for (int i=0;i<N;i++) scanf ("%d %d",&X[i],&Y[i]);

	long long mod = 998244353;
	long long pw[202] = {1,};
	for (int i=1;i<=N;i++) pw[i] = pw[i-1] * 2 % mod;

	long long ans = (pw[N] - 1 + mod - N) % mod;

	for (int i=0;i<N;i++){
		map<pair<int, int>, int> chk;
		for (int j=i+1;j<N;j++){
			int dx = X[j] - X[i], dy = Y[j] - Y[i];
			int g = gcd(abs(dx),abs(dy));
			dx /= g; dy /= g;
			if (dx < 0 || (dx == 0 && dy < 0)) dx = -dx, dy = -dy;
			chk[{dx,dy}]++;
		}

		for (auto &p : chk) ans = (ans + mod - pw[p.second] + 1) % mod;
	}
	
	printf ("%lld\n",ans);
	return 0;
}

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

int mod;
// const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const { //値をt乗する
    if (!t) return 1; // t == 0
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this; //*thisは元の値(t乗する対象)
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main() {
  ll n,k,b; cin >> n >> k; mod = k;
  vector<mint> a(n);
  rep(i,n){ cin >> b; a[i] = mint(b);}

  vector<mint> m(n+1);
  rep(i,n) m[i+1] = m[i]+a[i];
  rep(i,n+1) m[i] -= i;

  ll ans = 0;
  map<ll,ll> mp;
  int l = 0;
  rep(r,n+1){
    if(r-l+1>k){
      mp[m[l].x]--;
      ++l;
    }
    ans += mp[m[r].x];
    mp[m[r].x]++;
  }
  cout << ans << endl;
}


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

int a[6], b[6];
double calc(double x) {
	double ret = 0;
	for (int i = 0; i < 6; ++i)
		ret += max(a[i] * x, b[i] * (1 - x));
	for (int i = 0; i < 6; ++i)
		ret += max(a[i] * x, b[i] * (1 - x));
	return ret;
}

int main() {
	for (int i = 0; i < 6; ++i)
		scanf("%d", a + i);
	for (int i = 0; i < 6; ++i)
		scanf("%d", b + i);
	double ans1, ans2, res = 1e9;
	double l = 0, r = 1, m1, m2;
	for (int it = 0; it < 200; ++it) {
		m1 = (2 * l + r) / 3;
		m2 = (l + 2 * r) / 3;
		ans1 = calc(m1);
		ans2 = calc(m2);
		if (ans1 < ans2) {
			r = m2;
			res = min(res, ans1);
		} else {
			l = m1;
			res = min(res, ans2);
		}
	}
	cout << fixed << setprecision(20) << res / 200.0 << endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
abc = []
for _ in range(N):
    abc.append(list(map(int, input().split())))
INF = 10**9
dp = [[-INF]*3 for i in range(N)]
dp[0][0] = abc[0][0]
dp[0][1] = abc[0][1]
dp[0][2] = abc[0][2]
for i in range(N-1):
    dp[i+1][0] = max(dp[i+1][0], dp[i][1]+abc[i+1][0], dp[i][2]+abc[i+1][0])
    dp[i+1][1] = max(dp[i+1][1], dp[i][0]+abc[i+1][1], dp[i][2]+abc[i+1][1])
    dp[i+1][2] = max(dp[i+1][2], dp[i][0]+abc[i+1][2], dp[i][1]+abc[i+1][2])
print(max(dp[N-1]))

Measured memory_bytes: 47396
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#define ll long long 
using namespace std;

int main() {
	int a, b, c;
	cin >> a>>b>>c;
	int x[11] = {};
	string ans = "NO";
	x[a]++; x[b]++; x[c]++;
	if (x[5] == 2 && x[7] == 1) {
		ans = "YES";
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#pragma GCC target("avx,avx2")
using namespace std;
using ll=long long ;
ll get_num(vector<int>v){
  int sum=0;
  ll ans=0;
  for(int i=0;i<v.size();++i){
    if(v[i]==0)sum++;
    else{
      ans+=sum;
    }
  }
  return ans;
}
    
void solve(){
  string st;cin>>st;
  vector<int>v;

  ll answer=0;
  for(int i=0;i<st.size();++i){
    bool ok=true;
    if(st[i]=='A'){
      v.push_back(0);
    }else{
      if(st[i]=='B'){
        if(i!=st.size()-1&&st[i+1]=='C'){
          i++;
          v.push_back(1);
        }else{
          ok=false;
        }
      }else{
        ok=false;
      }
    }
    if(!ok){
      answer+=get_num(v);
      v.clear();
    }
  }
  answer+=get_num(v);
  cout<<answer<<endl;
}

int main(void){
  solve();


  return 0;
}

Measured memory_bytes: 2168