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

vector<string> divide = {"dream", "dreamer", "erase", "eraser"};

int main() {
  string S; cin >> S;
  
  reverse(S.begin(), S.end());
  for (int i = 0; i < 4; i++) reverse(divide.at(i).begin(), divide.at(i).end());
  
  bool can = true;
  
  for (int i = 0; i < S.size();) {
    bool can2 = false;
    for (string s : divide) {
      if (S.substr(i, s.size()) == s) {
        i += s.size();
        can2 = true;
      }
    }
    if (!can2) {
      can = false;
      break;
    }
  }
  
  if (can) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll MOD = 1000000007;

int main(){
  int N,M;cin >> N >> M;
  vector<string> A(N);
  vector<string> B(N);
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  for(int i=0;i<M;i++){
    cin >> B[i];
  }
  for(int k=0;k<N-M+1;k++){
    for(int l=0;l<N-M+1;l++){
      bool match = true;
      for(int i=0;i<M;i++){
        for(int j=0;j<M;j++){
          if(A[i+k][j+l]!=B[i][j]){
            match = false;
            break;
          }
        }
      }
      if(match){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
    int a, b;
    std::cin >> a >> b;

    if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
        std::cout << "Possible" << std::endl;
    } else {
        std::cout << "Impossible" << std::endl;
    }
}

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

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(), a.end(), greater<int>());
  cout << accumulate(a.begin(), a.begin() + k, 0) << endl;
  return 0;
} 

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

int ri() {
    int n;
    cin >> n;
    return n;
}


int main()
{

  
    int k,a,b;
    k = ri();
    a = ri();
    b = ri();

    int m = b % k;
    if (b - m >= a) {
        cout << "OK";
    }
    else {
        cout << "NG";
    }
    

    return 0;
}

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

int main(){
  int n,ans=0;
  string s,f,l;
  char a;
  cin>>n>>s;
  for(int i=1;i<n-1;i++){
    int cnt=0;
    f=s.substr(0,i);
    l=s.substr(i,n-i);
    for(char c='a';c<='z';c++){
       bool fok=false,lok=false;
      for(int j=0;j<f.size();j++){
	if(f.at(j)==c)fok=true;
      }
      for(int j=0;j<l.size();j++){
	if(l.at(j)==c)lok=true;
      }
      if(fok&&lok)cnt++;
    }
    ans=max(ans,cnt);
  }
  cout<<ans<<endl;
  return 0;
}

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

class Main{
	public static void main(String[] args){
		BufferedReader reader = 
		new BufferedReader(new InputStreamReader(System.in));
		
		String[] bit = new String[10];
		bit[0] = "0111111";
		bit[1] = "0000110";
		bit[2] = "1011011";
		bit[3] = "1001111";
		bit[4] = "1100110";
		bit[5] = "1101101";
		bit[6] = "1111101";
		bit[7] = "0100111";
		bit[8] = "1111111";
		bit[9] = "1101111";
		
		int n,x;
		String[] segment = new String[2];
		
		while(true){
			try{
				n = Integer.parseInt(reader.readLine());
				if(n == -1)break;
				
				segment[0] = "0000000";
				
				for(int i = 0; i < n; i++){
					
					segment[1] = "";
					x = Integer.parseInt(reader.readLine());
					
					for(int j = 0; j < 7; j++)
						segment[1] += String.valueOf(
								Integer.parseInt(String.valueOf(segment[0].charAt(j))) ^
							    Integer.parseInt(String.valueOf(bit[x].charAt(j))));
					
					System.out.println(segment[1]);
					segment[0] = bit[x];
				}
			}catch(IOException e){
			}
		}
		
		try{
			reader.close();
		}catch(IOException e){
		}
}
}

Measured memory_bytes: 18632
import java.util.Scanner;
public class Main {
	private static Scanner sc=new Scanner(System.in);
	public static void main (String[] args){
	while(true){
		int n=sc.nextInt();
		if(n==0) break;
		int[] s=new int[n];
		double sum=0;
		for(int i=0;i<n;i++){
			s[i]=sc.nextInt();
			sum=sum+s[i];
		}
		double ave=sum/n;
		double ssum=0;
		for(int i=0;i<n;i++){
			ssum=ssum+(s[i]-ave)*(s[i]-ave);
		}
		System.out.println(Math.sqrt(ssum/n));
	}
	}
}

Measured memory_bytes: 31548
#include<cstdio>
#include<cstring>
char str[100050];
int main()
{
	while(~scanf("%s",str))
	{
		int ans = 0;
		char ch;
		int n = strlen(str);
		ch = str[0];
		for(int i = 0;i < n;i++)
		{
			if(str[i] != ch)
			{
				ans++;
				ch = str[i];
			}
		} 
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
int Max = 10000000;
int main()
{
	int n;
	cin >> n;
	vector < pair<pair<string, int>, int>> aa(n);
	rep(i, n) {
		cin >> aa[i].first.first;
		cin >> aa[i].first.second;
		aa[i].first.second *= -1;
		aa[i].second = i + 1;
	}
	sort(aa.begin(), aa.end());
	rep(i, n) {
		cout << aa[i].second << endl;
	}
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;
const LL INF = 1e11;
int N;
map<LL, int> cnt;

const LL L = 2155;
const int M = 100001;
bool is_composite[M];
vector<LL> ps, tris;
map<LL, LL> sq2p, p2sq;

LL Reduce(LL v) {
  for (LL p : tris) {
    while (v%p == 0) v /= p;
  }
  return v;
}

LL Rev(LL v) {
  LL ret = 1;
  for (LL p : ps) {
    int e = 0;
    while (v%p == 0) {
      e++;
      v /= p;
    }

    assert(e <= 2);
    if (e == 1) ret *= p*p;
    else if (e == 2) ret *= p;
  }

  if (1 < v) { 
    assert(v > 2000);
    if (sq2p.count(v)) v = sq2p[v];
    else if (p2sq.count(v)) v = p2sq[v];
    else return -1;
    ret *= v;
  } 

  return ret;
}

int main() {
  reps(i, 2, M) {
    if (is_composite[i]) continue;
    LL p = i;
    if (p < L) {
      ps.eb(p);
      tris.eb(p*p*p);
    } else {
      sq2p[p*p] = p;
      p2sq[p] = p*p;
    }

    for (int j=i+i; j<M; j+=i) {
      is_composite[j] = true;
    }
  }
  //cout << ps.size() << endl;

  scanf("%d", &N);
  rep(i, N) {
    LL s;
    scanf("%lld", &s);
    cnt[Reduce(s)]++;
  }

  int ans = N;
  for (auto &p : cnt) {
    LL v = p.X;
    int a = p.Y;
    //printf("%lld: %d\n", v, a);
    LL r = Rev(v);
    if (!cnt.count(r)) continue;
    int b = cnt[r];
    if (a > b) continue;
    if (a == b && v < r) continue;
    if (a == b && v == r) assert(v == 1);
    //printf("removed (%lld,%d) because of (%lld, %d)\n", v, a, r, b);
    ans -= a;
  }

  if (cnt.count(1)) ans++;
  printf("%d\n", ans);
}


Measured memory_bytes: 7808
#include<cstdio>
#define maxn 200010
using namespace std;
int n,m,fa[maxn],dis[maxn];
int find(int x){
	if(x!=fa[x]){
		int f=fa[x];
		fa[x]=find(fa[x]);
		dis[x]+=dis[f];	
	}
	return fa[x]; 
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		fa[i]=i;
	int falg=0;
	for(int i=1;i<=m;i++){
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		int r1=find(x);
		int r2=find(y);
		if(r1==r2){
			if(dis[r2]+dis[y]!=z+dis[x])falg=1;
			else continue;
		}
		else {
			fa[r2]=r1;
			dis[r2]=z+dis[x]-dis[y];
		}
	}
	if(falg)printf("No\n");
	else printf("Yes\n");
	return 0; 
}

Measured memory_bytes: 896
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, A: int, B: int):
    print(min(B, N*A))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int a,b,c;
	cin>>a>>b>>b>>b>>b>>c;
	if(b-a<=c)cout<<"Yay!"<<endl;
	else cout<<":("<<endl;
}







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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

// 約数列挙
vector<ll> divisor(ll N) {
    vector<ll> res;
    for (ll i = 1L; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            ll j = N / i;
            if (j != i)  {
                res.push_back(j);
            }
        }
    }
    sort(res.begin(), res.end());
    return res;
}

void Main() {
    ll N;
    cin >> N;
    ll ans = divisor(N - 1).size() - 1;
    vector<ll> divisor_n = divisor(N);
    for (auto v : divisor_n){
        ll tmp = N;
        if (v == 1){continue;}
        while (tmp % v == 0){tmp = tmp / v;}
        if (tmp % v == 1){ans += 1;}
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 384
///A drunk man will find his way home, but a drunk bird may get lost forever...i
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef pair <int, int> pii;
#define pb push_back
#define pf push_front
#define f first
#define s second
#define sz(x) (int)x.size()
#define smin(x , y) x = min(x , y)
//const int mx = 1000 * 100 + 5;
int32_t main(){		
	ios_base::sync_with_stdio(false);
    cin.tie(0);
	cout.tie(0);
	string s, t;
	int n;
	cin >> n >> s >> t;
	for(int i = 0; i < n; i++)
		cout << s[i] << t[i];
	cout << endl;
	return 0;
}


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

#define rep(i,a,b)      for(int i=a;i<=b;i++)
#define revp(i,a,b)     for(int i=b;i>=a;i--)

string a,b,c;
int l1,l2;
int main()
{

    cin>>a>>b>>c;
    l1=a.length();
    l2=b.length();
    if(a[l1-1]==b[0] and b[l2-1]==c[0])
        cout<<"YES";
    else
        cout<<"NO";
}




Measured memory_bytes: 256
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
n = int(stdin.readline())
readline = stdin.readline
d = dict()
while n:
    n -= 1
    cmd, c = readline().split()
    if cmd.startswith('i'):
        d[c] = True
    elif d.get(c):
        print('yes')
    else:
        print('no')

Measured memory_bytes: 30880
N = int(input())
S = list(input())
answer = 0

for i in range(1, N):
    count = 0
    front = list(set(S[:i]))
    back = list(set(S[i:]))
    F = len(front)
    for j in range(F):
        count += back.count(front[j])
    if count>answer:
        answer = count
print(answer)


Measured memory_bytes: 3060
//In The Name of Allah
//Fri 12/2/97
#include <bits/stdc++.h>

#define Init ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define forar(i,n) for(long long int i = 0; i < n;i++)
#define fori(i,a,b) for(long long int i = a; i < b;i++)
#define WFile freopen("test.in","r",stdin),freopen("test.out","w",stdout)
#define Log(x) cout << "Log: " << x << endl;
#define F first
#define S second
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const ll mod = 1e9+7,M = 2e5+100;

void Solution();

int32_t main()
{
	Init;
	Solution();
	return 0;
}

inline void Solution(){
	int x=0,k,sum=0;
	forar(i,3){
		int a;
		cin >> a;
		sum += a;
		x = max(x,a);
	}
	sum -= x;
	cin >> k;
	forar(i,k){
		x*=2;
	}
	cout << sum+x << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
pair<int,int> a[1100000];
int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i].first;
	for(int i = 0; i < n; i++) a[i].second = i%2;
	sort(a,a+n);
	LL ans = 0;
	for(int i = 0; i < n; i++){
		ans += (i%2 != a[i].second%2);
	}
	cout << ans/2 << endl;

}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
using namespace std;

int main()
{
  string s;
  cin>>s;
  cout<< s.substr(0,5) << " " << s.substr(6,7) << " " << s.substr(14,5) <<endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[]args){
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    String s=sc.next();
    if(a>=3200){
      System.out.println(s);
    }else{
      System.out.println("red");
    }

  }
}


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



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

    int H, W;
    cin >> H >> W;
    vector<vector<int>> aij(H, vector<int>(W));
    vector<vector<int>> bij(H, vector<int>(W));
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            int a;
            cin >> a;
            aij.at(i).at(j) = a; 
        }
    }
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            int b;
            cin >> b;
            bij.at(i).at(j) = b;
        }
    }
    vector<vector<vector<bool>>> dp(H, vector<vector<bool>>(W, vector<bool>(6401, false)));
    dp.at(0).at(0).at(abs(aij.at(0).at(0) - bij.at(0).at(0))) = true;
    for(int i = 1; i < H + W - 1; i++){
        int currentH = i + 1;
        int currentW = -1;
        while(currentH >= 0){
            currentH--;
            currentW++;
            if(currentH >= H || currentH < 0 
            || currentW >= W || currentW < 0){
                continue;
            }
            int ababs = abs(aij.at(currentH).at(currentW) - bij.at(currentH).at(currentW));
            for(int j = 0; j < 6321; j++){
                if(currentH > 0){
                    dp.at(currentH).at(currentW).at(j) = dp.at(currentH).at(currentW).at(j) | dp.at(currentH - 1).at(currentW).at(abs(j - ababs));
                    dp.at(currentH).at(currentW).at(j) = dp.at(currentH).at(currentW).at(j) | dp.at(currentH - 1).at(currentW).at(j + ababs); 
                }
                if(currentW > 0){
                    dp.at(currentH).at(currentW).at(j) = dp.at(currentH).at(currentW).at(j) | dp.at(currentH).at(currentW - 1).at(abs(j - ababs)); 
                    dp.at(currentH).at(currentW).at(j) = dp.at(currentH).at(currentW).at(j) | dp.at(currentH).at(currentW - 1).at(j + ababs); 
                }
            }
        }
    }
    for(int i = 0; i < 81; i++){
        if(dp.at(H - 1).at(W - 1).at(i)){
            cout << i << endl;
            break;
        }
    }
    return 0;
}



Measured memory_bytes: 7808
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
using namespace std;
int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i, n)
    {
        cin >> h[i];
    }
       vector<int> dp(n + 4, 1'000'000'007);
    dp[0] = 0;
    rep(i, n)
    {
        if (dp[i] == 1'000'000'007)
            continue;
        for (int j = 1; j <= k; j++)
        {
            if(i+j<n){
                dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
            }
        }
    }
    cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1024
#include <stdlib.h>
#include <limits.h>
#define min(a, b) ((a) < (b) ? (a) : (b))
#define INF ((LONG_MAX)/3)

int main(void)
{
    int n, wSum, w[100], v[100];
    int res = 0;
    scanf("%d%d", &n, &wSum);
    for(int i=0; i<n; i++) {
        scanf("%d%d", &w[i], &v[i]);
    }
 
    long dp[101][100001] = {};
    for (int i = 0; i < n; i++) {
	    for (int j = 0; j <= 100000; j++) {
          dp[i][j] = INF;
        }
    }
  dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
	    for (int j = 0; j <= 100000; j++) {
          	if(j >= v[i]) {
		        dp[i+1][j] = min(dp[i][j-v[i]] + w[i], dp[i][j]);
            } else {
		        dp[i+1][j] = dp[i][j];
            }
        }
    }
    for (int j = 1; j <= 100000; j++) {
    	if(dp[n][j] <= wSum)
    	res = j;
    }

    printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 79232
S = str(input())
L = int(S[:2])
R = int(S[2:])

if L == 0:
    L = 99
if R == 0:
    R = 99

if (L > 12 and R > 12) or (L == 0 and R == 0):
    print("NA")
elif 0 < L <= 12 and 0 < R <= 12:
    print("AMBIGUOUS")
elif L > R:
    print("YYMM")
else:
    print("MMYY")


Measured memory_bytes: 3060
A,B,C,X=$stdin.read.split.map(&:to_i)
ans = 0
for a in 0..A
  for b in 0..B
    for c in 0..C
      if a*500 + b*100 + c*50 == X
        ans += 1
      end
    end
  end
end
p ans

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

int main()
{
   int a,b;
   cin>>a>>b;
   int c = a+b;
   int d = a-b;
   int e = a*b;
   int m = max(e,max(c,d));
   cout<<m<<endl;



    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pi 3.1415926535897932384626
using namespace std;
      
struct P{
  int x;
  long long y;
  /*bool operator < (const P &a )const{
    //if(y!=a.y)
    return y<a.y;
  };*/
};

int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
long long o[122111];
long long l[111111];
long long j[1];

long long x,y,z,mod=1000000007;
//string r;
char r[3];

P u[1];
queue<P> q;
stack<int> s;
//set<int> s;
map<int,int> p;

vector<int> v;


bool as(P a,P b)
{
  //if(a.x!=b.x)
  //return a.x<b.x;
  return a.y>b.y;
}

int main()
{
  scanf("%d",&a);
  scanf("%d",&n);
  o[1]=l[1]=n;
  for(int t=2;t<=a;t++)
  {
    scanf("%s %d",r,&n);
    if(r[0]=='+') o[t]=o[t-1]+n,l[t]=l[t-1]+n;
    else
    {
      o[t]=o[t-1]-n,l[t]=l[t-1]+n;
      v.push_back(t);
    }
  }
  x=o[a];
  for(int h=0;h+1<v.size();h++)
  {
    x=max(x,o[v[h]-1]+l[a]-l[v[h+1]-1]-(l[v[h+1]-1]-l[v[h]-1]));
    //printf("%lld %lld %lld\n",o[v[h]-1],l[a]-l[v[h+1]-1],(l[v[h+1]-1]-l[v[h]-1]));
  }
  printf("%lld",x);
}
//0
//12




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

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef long double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main() {
	int n, d; scanf("%d%d", &n, &d);
	int store[n][d];
	forn(i, n) {
		forn(j, d) {
			scanf("%d", &store[i][j]);
		}
	}
	int total = 0;
	forn(i, n) {
		for(int j = i + 1; j < n; j++) {
			double result = 0;
			forn(k, d) {
				result += pow(store[i][k] - store[j][k], 2);
			}
			result =  pow(result, 0.5);
			if(modf(result, &result) == 0)
				total++;
	 }
 }
 printf("%d", total);







	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

const int MaxN = 55;

char a[MaxN][MaxN], b[MaxN][MaxN];

int n, m;

int check(int si, int sj)
{
   int i, j;
   for (i = 0; i < m; i++)
     for (j = 0; j < m; j++)
       if (a[i+si][j+sj] != b[i][j])
         return 0;
   return 1;
}

int main( void )
{
  int i, j;
  scanf("%d %d", &n, &m);
  for (i = 0; i < n; i++)
    scanf (" %s", a[i]);
  for (i = 0; i < m; i++)
    scanf (" %s", b[i]);
  string ans = "No";
  for (i = 0; i + m <= n; i++)
    for (j = 0; j + m <= n; j++)
      if (check(i, j))
        ans = "Yes";
  cout << ans << endl;
  return 0;
}

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

/**
 * vector<int>ar(3);
 * for(auto&e:ar){
 *     scanf("%d",&e);
 * }
 * sort(ar.begin(),ar.end())
 * int sum=accumulate(ar.begin(),ar.end(),0);
 ***/
int gcd(int a,int b){
    int tmp;
    if(a<b){
        tmp=a;
        a=b;
        b=tmp;
    }
    for(;;){
        if(a%b==0) break;
        tmp=a%b;
        a=b;
        b=tmp;
    }
    return b;
}




int main(){
    double pai=3.141592653589;
    long x,y,ans;
    scanf("%ld %ld",&x,&y);
    printf("%ld\n",gcd(x,y));
    return 0;
}

Measured memory_bytes: 1168
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int k = 1; k <= m; k++) {
		for (int i = 0; i < n-1; i++) {
			if (a[i]%k > a[i+1]%k) {
				swap(a[i], a[i+1]);
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << a[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <vector>
#include <atcoder/lazysegtree>
using namespace std;
using namespace atcoder;
typedef long long ll;

const ll MOD = 998244353;

struct S
{
    ll a;
    ll b;
};

S op(S a, S b){
    return S{(a.a + b.a) % MOD, (a.b + b.b) % MOD};
}

S e(){
    return S{0, 0};
}

struct F
{
    ll a;
};

S mapping(F f, S a){
    if(f.a == 0) return a;
    return S{f.a * a.b, a.b};
}

F composition(F f, F g){
    if(f.a == 0) return g;
    return f;
}

F id(){
    return F{0};
}

int main()
{
    int n, q;
    cin >> n >> q;
    vector<S> v(n);
    ll b = 1;
    for(int i = n - 1; i >= 0; i--){
        v[i] = S{b, b};
        b = b * 10 % MOD;
    }
    lazy_segtree<S, op, e, F, mapping, composition, id> seg(v);
    while(q--){
        int l, r, d;
        cin >> l >> r >> d;
        l--;
        seg.apply(l, r, F{d});
        cout << seg.all_prod().a << endl;
    }
}


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

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second

#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; }

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(1e5) + 17;

int n, k;
int a[MAXN];
ll dp[102][MAXN];

bool read() {
    if (!(cin >> n >> k))
        return false;

    forn (i, n)
        cin >> a[i + 1];

    return true;
}

void solve() {
    for (int i = 0; i <= k; ++i)
        dp[0][i] = 1;

    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= k; ++j) {
            int l = max(0, j - a[i]);
            int r = j;
            dp[i][j] = INF + dp[i - 1][r];

            if (l != 0)
                dp[i][j] -= dp[i - 1][l - 1];

            dp[i][j] %= INF;
        }

        if (i == n) {
            cout << dp[i][k] << endl;
            return ;
        }

        for (int j = 1; j <= k; ++j) {
            dp[i][j] += dp[i][j - 1];
        }
    }
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
#ifdef SEREZHKA
    freopen("file.in", "r", stdin);
#endif
    
    while (read())
        solve();
    
    return 0;
}



Measured memory_bytes: 80128
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		if(a < c) {
			if(b > c) {
				System.out.println("Yes");
			}else {System.out.println("No");
			}
		}
		if(a > c) {
			if(b < c) {
				System.out.println("Yes");
			}else {System.out.println("No");
			}
		}
	}

}


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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

const ll INF = 1LL << 50;

const ll mod = 1e9 + 7;

int main() {
  ll n;
  while (true) {
    cin >> n;
    if (n == 0) break;

    vll ws(n);
    rep(i, n) cin >> ws[i];

    vvll dp(n, vll(n, 0));

    rep(i, n - 1) dp[i][i + 1] = 2 * (abs(ws[i] - ws[i + 1]) <= 1);

    for (ll h = 2; h <= n; h++) {
      for (ll i = 0; i < n - h + 1; i++) {
        ll k = i + h - 1;
        for (ll j = i; j <= k - 1; j++) {
          chmax(dp[i][k], dp[i][j] + dp[j+1][k]);
        }  // j
        bool cond = dp[i][k] == h && i >= 1 && k <= n - 2 &&
                    abs(ws[i - 1] - ws[k + 1]) <= 1;
        if (cond) {
          dp[i - 1][k + 1] = h + 2;
        }
      }  // i
    }    // h

    ll ans = dp[0][n - 1];
    cout << ans << endl;
  }  // while
  return 0;
}



Measured memory_bytes: 3680
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int flag = 0;

		for(int i = 1; i <= B; i++) {
			if(A * i % B == C) {
                System.out.println("YES");
				flag = 1;
				break;
			}
		}

		if(flag == 0) {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define INF 10000000
using ll = long long;
using itn = int;
using namespace std;
using Graph = vector<vector<int>>;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
vector<int> to[2000010];
vector<ll> cnt;
void dfs(int v,int p=-1){
    for(int u : to[v]){
        if(u==p) continue;
        cnt[u]+=cnt[v];
        dfs(u,v);
    }
}
int main(){
    int N,Q;
    cin>>N>>Q;
    int a[N-1],b[N-1];
    rep(i,N-1){
        int a,b;
        cin>>a>>b;
        to[a-1].push_back(b-1);
        to[b-1].push_back(a-1);
    }
    cnt.resize(N);
    rep(i,Q){
        int p,x;
        cin>>p>>x;
        cnt[p-1]+=x;
    }
    dfs(0);
    rep(i,N){
        cout<<cnt[i]<<" ";
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 66432
#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>
#include <queue>
#include<algorithm>
#include<cstring>
#include <cstdlib>
#include <cstdio>
#include <set>
#include <iomanip>
#include <map>
#include <stack>
#include <memory>
#include <numeric>
#include <type_traits>
 
using namespace std;
 
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
typedef long long ll;





int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  while(a > 0 && c > 0){
    a -= d;
    c -= b;
  }
  if (a <= 0 && c <= 0){
    cout << "Yes";
  }
  else if (a <= 0){
    cout << "No";
  }
  else if (c <= 0){
    cout << "Yes";
  }

  return 0;
}

Measured memory_bytes: 3624
i = input().split()
n1 = max(int(i[0]),int(i[1]))
n2 = min(int(i[0]),int(i[1]))
aa = list(range(n2,n1))
#print(int(i[2]) in aa)
#変数 = 真の場合の代入値 if 条件文 else 偽の場合の代入値

ans = ('Yes' if int(i[2]) in aa else 'No')
print(ans)

Measured memory_bytes: 3060
N = int(input())
A = list(map(int, input().split()))
res = [-1]*N

for i in reversed(range(1, N + 1)):
    p = (N // i) * i
    s = 0
    while res[p - 1] != -1:
        s += res[p - 1]
        s %= 2
        p -= i
    res[p - 1] = (A[p - 1] - s) % 2

print(sum(res))
for i in range(N):
    if res[i] == 1:
        print(i + 1)

Measured memory_bytes: 12320
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vi a(n);
	cin>>a;
	vi ans;
	rep(i,n){
		rrep(j,n-i){
			if(a[j]==j+1){
				ans.push_back(j+1);
				a.erase(a.begin()+j);
				break;
			}
		}
		if(ans.size()!=i+1){
			puta(-1);
			return 0;
		}
	}
	reverse(all(ans));
	rep(i,n)puta(ans[i]);
	return 0;
}

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

#define rep(i, a) for (int i = 0; i < (a); i++ )

 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    int H,W,N;
    int sr,sc;
    cin >> H >> W >> N;
    cin >> sr >> sc;
    sr--,sc--;
    string S,T;
    cin >> S >> T;

    string ans = "YES";
    // LR
    int wmax,wmin;
    wmax = W-1;
    wmin = 0;
    if (S[N-1]=='L') wmin++;
    else if (S[N-1]=='R') wmax--;

    //cout << wmin << " " << wmax << endl;

    for (int i=N-2; i>=0; i--) {
        if (T[i]=='L') wmax = min(wmax+1, W-1);
        else if (T[i]=='R') wmin = max(wmin-1, 0);

        if (S[i]=='L') wmin++;
        else if (S[i]=='R') wmax--;

        if (wmax<wmin) ans = "NO";
        //cout << wmin << " " << wmax << endl;
    }
    if (wmin>sc || wmax<sc) ans = "NO";

    //cout << ans << endl;

    // UD
    int hmax,hmin;
    hmax = H-1;
    hmin = 0;
    if (S[N-1]=='U') hmin++;
    else if (S[N-1]=='D') hmax--;

    //cout << hmin << " " << hmax << endl;

    for (int i=N-2; i>=0; i--) {
        if (T[i]=='U') hmax = min(hmax+1, H-1);
        else if (T[i]=='D') hmin = max(hmin-1, 0);

        if (S[i]=='U') hmin++;
        else if (S[i]=='D') hmax--;

        if (hmax<hmin) ans = "NO";
        //cout << S[i] << " " << T[i] << " " << hmin << " " << hmax << endl;
    }
    if (hmin>sr || hmax<sr) ans = "NO";
    cout << ans << endl;

}


Measured memory_bytes: 3900
/*  /$$                                     /$$
      | $$                                    | $$
  /$$$$$$$  /$$$$$$   /$$$$$$$  /$$$$$$   /$$$$$$$  /$$$$$$   /$$$$$$
 /$$__  $$ /$$__  $$ /$$_____/ /$$__  $$ /$$__  $$ /$$__  $$ /$$__  $$
| $$  | $$| $$$$$$$$| $$      | $$  \ $$| $$  | $$| $$$$$$$$| $$  \__/
| $$  | $$| $$_____/| $$      | $$  | $$| $$  | $$| $$_____/| $$
|  $$$$$$$|  $$$$$$$|  $$$$$$$|  $$$$$$/|  $$$$$$$|  $$$$$$$| $$
 \_______/ \_______/ \_______/ \______/  \_______/ \_______/|__//$$$$$$ /$$$$$$
                                                               |______/|______/

*/
#include <bits/stdc++.h>
#define fastio        ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ln            cout<<endl;
#define vi            vector<int>
#define vll           vector<long long>
#define sortl(vec)    sort(vec.begin(), vec.end());
#define sortr(vec)    sort(vec.rbegin(), vec.rend());
#define forn(i, x, n) for(long long i = x; i < n; i++)
#define revn(i, n, x) for(long long i = n; i >= x ; i--)
#define in(vec)       for(auto &it : vec) cin >> it;
#define loop(vec)     for(auto &it : vec)
#define	out(vec)      for(auto &it : vec) cout << it << " "; ln
#define ll            long long
#define mod           1000000007
#define debug(x)      cout << x << endl;
#define pb            emplace_back
#define mp            make_pair
#define um            unordered_map
#define pii           pair<int, int>
#define pll           pair<ll, ll>
#define f             first
#define s             second
#define pi            3.14159265359
#define CLOCK         cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
using namespace std;

ll power(ll x, ll y, ll p) {
	ll res = 1;
	x = x % p;

	while (y > 0) {
		if (y & 1)
			res = (res * x) % p;

		y = y >> 1;
		x = (x * x) % p;
	}
	return res;
}

ll modulo(ll a, ll b) {
	ll c = a % b;
	return (c < 0) ? c + b : c;
}

int main() {
// in(vec) works for size-defined type vectors

#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input1.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output1.txt", "w", stdout);
#endif

	fastio
	ll t = 1;
	while (t--) {
		ll n;
		cin >> n;
		vll vec(n);
		in(vec);
		ll XOR = 0;

		forn(i, 0, n) {
			XOR ^= vec[i];
		}

		forn(i, 0, n) {
			ll a = XOR ^ vec[i];
			cout << a << " ";
		}
		ln


	}
	CLOCK
	return 0;
}



Measured memory_bytes: 4764
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    i64 n, k;
    std::cin >> n >> k;
    std::vector<i64> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }

    i64 x = 0, x2 = 0;
    i64 i = 0;
    bool flg = true;
    while ((1ll << (i + 1)) <= k) i++;
    if ((1ll << i) <= k) x2 = (1ll << i);
    i--;
    for (; i >= 0; i--) {
        int cnt = 0;
        for (int j = 0; j < n; j++) {
            if (a[j] & (1ll << i)) cnt++;
        }
        if (cnt < (n + 1) / 2) {
            // 1にする
            if (flg && x2 + (1ll << i) <= k) {
                if (x2 + (1 << i) <= k) x2 += (1ll << i);
            } else if (!flg) {
                x2 += (1ll << i);
            }
            x += (1ll << i);
        } else {
            // 0にする
            if ((1ll << i) & k) flg = false;
        }
    }

    i64 ret = 0, ret2 = 0;
    for (int i = 0; i < n; i++) {
        ret += x ^ a[i];
        ret2 += x2 ^ a[i];
    }
    std::cout << std::max(ret, ret2) << std::endl;

    return 0;
}


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

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;


int main(){
  int N,H,W;
  cin>>N>>H>>W;
  int cnt(0);
  for(int i(0);i<N;i++){
    int a,b;
    cin>>a>>b;
    if(a >= H && b >= W) cnt++;
  }
  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 3564
#include <cstdio>
#include <algorithm>

using namespace std;

int A;

int gcd(int x, int y) {
    int M = max(x, y);
    int m = min(x, y);
    if (M % m == 0) { return m; }
    return gcd(m, M % m);
}

void f_minus(int p, int q, int i, int& rp, int& rq) {
    int np_c = p * i - q;
    int nq_c = q * i;
    if (np_c == 0) { rp = 0; return; }
    if (np_c < 0) { rp = -1; return; }
    int np_nq_gcd = gcd(np_c, nq_c);
    rp = np_c / np_nq_gcd;
    rq = nq_c / np_nq_gcd;
}

int dfs(int p, int q, int m, int n, int mm) {
    int r = 0;
    for (int i = mm; q * n >= p * i && m * i <= A; i++) {
        int np, nq;
        f_minus(p, q, i, np, nq);
        if (np == 0) {
            r++;
        } else if (np < 0) {
            continue;
        } else {
            r += dfs(np, nq, m * i, n - 1, i);
        }
    }
    return r;
}

int main() {
    for (;;) {
        int p, q, n;
        scanf("%d%d%d%d", &p, &q, &A, &n);
        if (!p) { break; }
        printf("%d\n", dfs(p, q, 1, n, 1));
    }
    return 0;
}

Measured memory_bytes: 1028
#include<stdio.h>

int main(void)
{
    int S;
    int h;
    int m;
    int s;

    scanf("%d",&S);
    h = S / 3600;
    m = (S - h * 3600) / 60;
    s = (S - h * 3600) % 60;
    printf("%d:%d:%d\n",h,m,s);

    return 0;
}

Measured memory_bytes: 592
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        if (a < 10 && b < 10) {
            System.out.println(a*b);
            return;
        }

        System.out.println(-1);
    }
}


Measured memory_bytes: 23252
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def ave(L):
    if len(L) == 1: return L[0]
    elif len(L) == 2: return (L[0] + L[1]) / 2
    else: return (L[0] + ave(L[1:len(L)])) / 2
    


def main():
    N = INT()
    V = LIST()
    
    V = sorted(V, reverse=True)
    print(ave(V))


if __name__ == '__main__':
        main()

Measured memory_bytes: 38768
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long


signed main(){
  string s;
  int cnt=0;
  cin>>s;
  rep(i,s.size() ){
    if(s[i]=='x') cnt++;
  }
  if(cnt>7) cout<<"NO"<<endl;
  else cout<<"YES"<<endl;

  return 0;
}


Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}


unsigned long xor128() {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y; y = z; z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

#define int ll

int dist[100];
int neko[100];
vector<int> vertexs[100];
vector<int> visitings[3][100];
void solve(){
    int n, m, a, b, c;
    cin >> n >> m >> a >> b >> c;
    REP(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        swap(a, b);
        vertexs[a].push_back(b);
    }
    REP(i, n) {
        int cnt[51][101] = {};
        cnt[i][0] = 1;
        for (int q = 0; q < 100; ++q) {
            REP(j, n) {
                if (cnt[j][q] == 0) continue;
                for (auto x : vertexs[j]) {
                    cnt[x][q + 1] = 1;
                }
            }
        }
        REP(q, n) {
            if (cnt[q][a] == 1) visitings[0][i].push_back(q);
            if (cnt[q][b] == 1) visitings[1][i].push_back(q);
            if (cnt[q][c] == 1) visitings[2][i].push_back(q);
        }
        dist[i] = 1e9;
    }
    dist[n - 1] = 0;
    neko[n - 1] = 7;
    queue<int> next;
    next.push(n - 1);
    while (next.empty() == false) {
        int now = next.front();
        next.pop();
        REP(q, 3) {
            for (auto x : visitings[q][now]) {
                if (neko[x] & (1 << q)) {
                    continue;
                }
                neko[x] |= (1 << q);
                if (neko[x] == 7) {
                    dist[x] = dist[now] + 1;
                    next.push(x);
                }
            }
        }
    }
    if (dist[0] == 1e9) {
        cout << "IMPOSSIBLE" << endl;
    }
    else {
        cout << dist[0] << endl;
    }
    
}

#undef int
int main() {
    init();
    solve();
}


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

void solve() 
{
    ll n,k;cin>>n>>k;
    ll a[n];REP(i,n)cin>>a[i];REP(i,n)a[i]--;
    vector<ll>b(n,-1);b[0]=0;
    ll i=1;ll now=a[0];
    for(;b[now]==-1;i++){
        b[now]=i;
        now=a[now];
        if(i==k-1){
            cout<<now+1<<endl;
            return;
        }
    }
    ll l=i-b[now];
    // cout<<i<<b[now]<<endl;
    ll t=(k-b[now])%l;
    // cout<<t<<endl;
    REP(j,t){
        now=a[now];
        // cout<<now<<endl;
    }
    cout<<now+1<<endl;
}

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

Measured memory_bytes: 6424
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int P = 1e9 + 7;
int a , b , c , d;
inline void pp(int &a,int b){if((a+=b)>=P)a-=P;}
inline int mul(int a,int b){return ll(a)*b%P;}
inline int ceil(ll a,ll b){return (a+b-1)/b;}

int main(){
    cin >> a >> b >> c >> d;
    int ans=mul(min(a,d+1),mul(min(b,d+1),min(c,d+1)));
    rep(times,0,3){
        int x=1,limx=a-d-1;
        while(x<=limx) {
            int y=ll(x)*b/a;
            int z=ll(x)*c/a;
            int nx=limx+1;
            if(0<=y-d&&y+d<b) nx=min(nx,ceil(ll(b-d)*a,b));
            else nx=min(nx,ceil(ll(y+1)*a,b));
            if(0<=z-d&&z+d<c) nx=min(nx,ceil(ll(c-d)*a,c));
            else nx=min(nx,ceil(ll(z+1)*a,c));
            int ly=min(b-1,y+d)-max(0,y-d)+1;
            int lz=min(c-1,z+d)-max(0,z-d)+1;
            pp(ans,mul(nx-x,mul(ly,lz)));
            x=nx;
        }
        swap(a,b);swap(b,c);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cassert>

#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <limits>
using namespace std;

#define rep_init(i, init, n) for(int i = (init); i < (n); ++i)
#define rep(i, n) rep_init(i, 0, n)


void Main()
{
	int N;
	cin >> N;
	vector<int> d(N);
	rep(i, N)
	{
		cin >> d[i];
	}

	sort(d.begin(), d.end());

	int pre = 1000;
	int count = 0;
	rep(i, N)
	{
		if (pre != d[i])
		{
			++count;
			pre = d[i];
		}
	}

	cout << count << 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: 256