akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

int main() {
    int N;
    cin >> N;
    vector<ll> a(N);
    ll odd = 0, even = 0, quad = 0;
    REP(i, N) {
        cin >> a[i];
        if (a[i] % 2 == 0) even++; else odd++;
        if (a[i] % 4 == 0) quad++;
    }
    even -= quad;
    if (even == 0) quad++;
    if (odd <= quad) cout << "Yes" << endl;
    else cout << "No" << endl;




    return 0;
}


Measured memory_bytes: 1024
import string
import sys
s = input()
k = int(input())
a = [ord(_) for _ in s]
for i in range(len(s)-1):
    if a[i] != ord('a'):
        df = ord('z') - a[i] + 1
        if k >= df:
            a[i] = ord('a')
            k -= df
    if k == 0: break
if k != 0:
    k = k % 26
    a[len(a)-1] += k - 26 if ord('z') < k + a[len(a)-1] else k
[print(chr(_), end="") for _ in a]
print("")


Measured memory_bytes: 7024
import sys
input = sys.stdin.readline
A = int(input())
B = int(input())
C = int(input())
X = int(input())
counter = 0
for i in range(A+1):
    for j in range(B+1):
        total = 500*i + 100*j
        if total == X:
            counter += 1
        for k in range(C):
            total += 50
            if total == X:
                counter += 1
            elif total > X:
                break
print(counter)


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

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

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

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

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

    cin>>h>>w;
    rep(i,h){
        rep(j,w){
            cin>>a[i][j];
        }
    }
    rep(i,h){
        rep(j,w){
            tmp[i][j]+=(w-j)*(h-i)+((w-j)*(h-i))*(i*j+i+j);
        }
    }
    rep(i,h){
        rep(j,w){
            ans+=a[i][j]*tmp[i][j];
        }
    }
    Cout(ans);
    return 0;
}



Measured memory_bytes: 7120
#include <cstdio>
#include <vector>
using namespace std;

int main() {
  int N;
  while (scanf("%d", &N), N) {
    vector<pair<int, int>> stones(N);
    for (int i = 0; i < N; ++i) {
      int x, y; scanf("%d%d", &x, &y);
      stones[i] = {x, y};
    }
    vector<bool> collected(N, false);
    int M; scanf("%d", &M);
    int x = 10, y = 10;
    for (int i = 0; i < M; ++i) {
      char d; int l; scanf(" %c%d", &d, &l);
      int ny = y, nx = x;
      switch (d) {
      case 'N': ny += l; break;
      case 'E': nx += l; break;
      case 'S': ny -= l; break;
      case 'W': nx -= l; break;
      }
      for (int j = 0; j < N; ++j) {
        auto p = stones[j];
        if ((x == nx && nx == p.first && min(y, ny) <= p.second && p.second <= max(y, ny)) ||
            (y == ny && ny == p.second && min(x, nx) <= p.first && p.first <= max(x, nx))) {
          collected[j] = true;
        }
      }
      x = nx; y = ny;
    }
    bool ok = true;
    for (bool b : collected) {
      if (!b) { ok = false; break; }
    }
    puts(ok ? "Yes" : "No");
  }
}

Measured memory_bytes: 1012
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <vector>
#include <queue>



using namespace std;

typedef pair<double, int> P;

int main()
{
	int num;
	double time;
	
	vector<P> remain;
	for (int i=0; i<3; i++)
	{
		vector<P> men;
		
		for (int j=0; j<8; j++)
		{
			cin >> num >> time;
			men.push_back(P(time, num));
		}
		
		sort(men.begin(), men.end());
		
		printf("%d %.2lf\n", men[0].second, men[0].first);
		printf("%d %.2lf\n", men[1].second, men[1].first);
		for (int j=2; j<men.size(); j++) remain.push_back(men[j]);
		
		/*
		for (int j=0; j<men.size(); j++)
		{
			cout << men[j].first << " : " << men[j].second << endl;
		}
		*/
	}
	
	sort(remain.begin(), remain.end());
	printf("%d %.2lf\n", remain[0].second, remain[0].first);
	printf("%d %.2lf\n", remain[1].second, remain[1].first);
	
	
	return 0;
}

Measured memory_bytes: 1252
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
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; }

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  vector<string> vec(N);
  for(int i=0;i<N;i++)
  {
    cin >> vec[i];
  }
  sort(vec.begin(), vec.end());
  int count = 1;
  for(int i=0;i<N-1;i++)
  {
    if(vec[i]==vec[i+1])
    {
      continue;
    }
    else
    {
      count ++;
    }
    
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 9596
import java.util.*;


public class Main {
     public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        sc.close();
        String[] array = str.split(" ");
//        System.out.println(array[0]);
//        System.out.println(Arrays.toString(array));
        int sum = 0;
        for(int i=0; i<array.length; i++) {
            int num = Integer.parseInt(array[i]);
            sum += num;
        }
        System.out.println(15-sum);
    }
}

Measured memory_bytes: 26976
import java.util.*;

public class Main {

    int[] stones;

    private int getDist(int i, int j) {
        return Math.abs(stones[i] - stones[j]);
    }

    private void run() {
        
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        stones = new int[N];
        int[] dp = new int[N];

        for (int i = 0; i < N; i++) stones[i] = sc.nextInt();
        
        dp[N-1] = 0;
        dp[N-2] = getDist(N-1, N-2);

        for (int i = N-3; i >= 0; i--) {
            int hop1 = dp[i+1] + getDist(i,i+1);
            int hop2 = dp[i+2] + getDist(i,i+2);
            dp[i] = Math.min(hop1, hop2);
        }

        System.out.println(dp[0]);
    }
    public static void main(String[] args) {
        Main solver = new Main();
        solver.run();
    }
}

Measured memory_bytes: 51124
#include<iostream>
#include<map>
#include<vector>
#include<list>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<climits>
#include<ctime>
#include<cstring>
#define REP(i,p,n) for(int i=p;i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep_split(tok,a_str,re) for(char *tok = strtok((char *)a_str.c_str(),re); tok != NULL; tok = strtok(NULL,re))
#define all(c) (c).begin(), (c).end()

using namespace std;


int main() {
	int N;
	int year,month,day;
	int day_limit;
	int cnt;

	cin >> N;
	rep(i,N) {
		cnt=0;
		cin >> year >> month >> day;
		while(true) {
			if (year % 3 == 0) { //すべて大の月
				day_limit = 20;
			}
			else {  
				if (month % 2 == 0) { //小の月
					day_limit = 19;
				}
				else { //大の月
					day_limit = 20;
				}
			}
			if (day >= day_limit) {
				day = 1;
				if (month >= 10) {
					month = 1;
					if (year >= 999) { break; }
					else { year++; }
				}
				else { month++; }
			}
			else { day++; }
			cnt++;
		}
		cout << cnt+1 << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}

	std::string N;
	std::cin >> N;
	if (N[0] == N[2])
		std::cout << "Yes\n";
	else
		std::cout << "No\n";
}


Measured memory_bytes: 512
N = int(input())
b = [int(i) for i in input().split()]


a = []

for i in range(N):
    for j in range(len(b)):
        if b[len(b)-j-1] == len(b) - j:
            a.append(len(b)-j)
            b.pop(len(b)-j-1)
            break
    if len(a) != i+1:
        print(-1)
        exit()


for aa in a[::-1]:
    print(aa)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    int X[110];
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> X[i];
    }
    int res = 1200000;
    for(int i = 1; i < 101; i++) {
        int hp = 0;
        for(int j = 0; j < N; j++) {
            hp += pow((X[j] - i), 2);
        }

        res = min(res, hp);

    }
    cout << res << endl;

    return 0;
}

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

template<typename T, typename U> bool chmin(T &a, const U &b) {
	return (a > b ? a = b, true : false);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
	return (a < b ? a = b, true : false);
}

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;


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

	int n;cin>>n;
	
	writeln(3*n*n);
}




Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int a, b, sum = 0, sum2 = 0, n = 0;
    while(scanf("%d,%d", &a, &b) != EOF) {
        sum += a * b;
        sum2 += b;
        n++;
    }
    printf("%d\n%d\n", sum, (sum2%n*10/ n < 5) ? sum2/n : sum2/n+1);
}



Measured memory_bytes: 1992
#include<stdio.h>
#include<stdlib.h>

int main (void){

  int a,b,c,z1,z2,z3;
  scanf("%d%d%d",&a,&b,&c);
  if(1<=a<=10000 && 1<=b<=10000 && 1<=c<=10000){
  
    if(a>=b && b>=c){
      z1=c;
      z2=b;
      z3=a;
    }
    else if(a>=c && c>=b){
      z1=b;
      z2=c;
      z3=a;
    }
    
    else if(b>=a && a>=c){
      z1=c;
      z2=a;
      z3=b;
    }
    else if(b>=c && c>=a){
      z1=a;
      z2=c;
      z3=b;
    }
    else if(c>=b && b>=a){
      z1=a;
      z2=b;
      z3=c;
    }
    else if(c>=a && a>=b){
      z1=b;
      z2=a;
      z3=c;
    }
  }

  printf("%d %d %d\n",z1,z2,z3);
  return(0);
}



Measured memory_bytes: 2044
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p


X, Y = map(int, input().split())
p = 10 ** 9 + 7
turn = (X + Y)//3
N = turn + 10  # N は必要分だけ用意する
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

if (X + Y) % 3 != 0:
    print(0)
    exit()
turn = (X + Y)//3
move1 = (Y - X + turn) //2
move2 = (X - Y + turn) //2

print(cmb(turn, move1, p))


Measured memory_bytes: 118764
import java.util.Scanner;

public class Main {
    static int comparisons;

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        comparisons = 0;
        mergeSort(a, 0, a.length);
        System.out.println(printArray(a));
        System.out.println(comparisons);
    }

    private static void mergeSort(int[] a, int left, int right) {
        if (left + 1 < right) {
            int mid = (left + right) / 2;
            mergeSort(a, left, mid);
            mergeSort(a, mid, right);
            merge(a, left, mid, right);
        }
    }

    private static void merge(int[] a, int left, int mid, int right) {
        int n1 = mid - left;
        int n2 = right - mid;
        int[] l = new int[n1];
        int[] r = new int[n2];
        for (int i = 0; i < n1; i++) {
            l[i] = a[left + i];
        }
        for (int i = 0; i < n2; i++) {
            r[i] = a[mid + i];
        }
        int i = 0;
        int j = 0;
        for (int k = left; k < right; k++) {
            if (i < n1 && (j == n2 || l[i] <= r[j])) {
                a[k] = l[i];
                i++;
                comparisons++;
            } else {
                a[k] = r[j];
                j++;
                comparisons++;
            }
        }
    }

    static String printArray(int[] a) {
        StringBuilder sb = new StringBuilder();
        sb.append(a[0]);
        for (int i = 1; i < a.length; i++) {
            sb.append(" ").append(a[i]);
        }
        return sb.toString();
    }
}



Measured memory_bytes: 186544
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner scan = new Scanner(System.in);
      	int a = scan.nextInt();
      	int b = scan.nextInt();
      	int c = scan.nextInt();      
      
      	int d = ( a - b ) - c < 0 ? Math.abs(( a - b ) - c) : 0 ;
        System.out.println(d);
    }
}


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

int main() {
  int c;
  set<int> s;
  REP(i, 3) {
    cin >> c;
    s.insert(c);
  }
  cout << s.size() << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#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 REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
  int n; cin>>n;
  int b[n-1]; rep(i,n-1) cin>>b[i];
  ll ans = b[0];
  rep(i,n-2){
    ans += min(b[i],b[i+1]);
  }
  ans += b[n-2];
  cout << ans << endl;

  return 0;
}


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

using namespace std;

#define ll long long
#define pb push_back
#define vi vector<int>
#define bn(n) (n).begin(), (n).end()
#define FOR(n) for(int i = 0; i < (int)n; i++)


void solve() {
    int a, b ,c;
    cin >> a >> b >> c;
    cout << ((b*10+c) % 4 == 0 ?  "YES" : "NO") << "\n";
}

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

    int t = 1, i = 1;
    //cin >> t;
    while(t--) {
        //cout << "Case #" << i << ": ";
        solve();
        //i++;
    }
    return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ld long double
#define ull unsigned long long int
#define ll long long int
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007ll
#define rep(i,L,R) for(i=L;i<R;i++)
#define DEBUG
#ifdef DEBUG
#define deb2(args...) {dbg,args; cerr<<endl;}
#else
#define deb2(args...)
#endif
struct debb{template<typename T> debb& operator,(const T &v){cerr<<v<<" ";return *this;}}dbg;
#define deb1(args...) do {cerr << #args << " : "; dbg,args; cerr << "\n";} while(0)
#define printa(a,L,R) rep(i,L,R) cout << a[i] <<' ';cout<<"\n";
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
template<typename T>T gcd(T a,T b){if(b==0)return a;else return gcd(b,a%b);}
template<typename T>T lcm(T a,T b){return a/gcd(a,b)*b;}
ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1)res=((res%p)*(x%p))%p;y=y>>1;x=(x*x)%p;}return res;}
ll pow1(ll x,ll y){ll res=1;while(y>0){if(y&1)res=(res*x);y=y>>1;x=x*x;}return res;}
const ll INF = 1e18l+10,N = 1e5+10,MAX = 5000000;
#define sq(X) ((X)*(X))

int main()
{
    ll n,i,s=0,k;
    cin>>n>>k;
    ll p[k+1];
    
    for(i=k;i;i--)
    {
        p[i] = power(k/i,n,mod);
        for(ll j = 2*i;j<=k;j+=i)
        p[i] = (p[i]%mod - p[j]%mod +mod)%mod;
    }
    for(i=1;i<=k;i++)
    {
        s= (s%mod + (i*p[i])%mod)%mod;
    }
    cout<<s<<"\n";
}   

Measured memory_bytes: 4376
import java.util.Scanner;

public class Main {

    static String[] S = new String[3];
    static int[] cnt = new int[3];

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

        S[0] = sc.next();
        S[1] = sc.next();
        S[2] = sc.next();

        cnt[0] = S[0].length();
        cnt[1] = S[1].length();
        cnt[2] = S[2].length();

        int ans = serch(0);
        if (ans == 0)
            System.out.println('A');
        else if (ans == 1)
            System.out.println('B');
        else
            System.out.println('C');
    }

    static int serch(int thisTurn) {
        if (cnt[thisTurn] <= 0)
            return thisTurn;

        int index =  S[thisTurn].length() - cnt[thisTurn];
        char c = S[thisTurn].charAt(index);
        cnt[thisTurn]--;

        if (c == 'a')
            return serch(0);
        else if (c == 'b')
            return serch(1);
        else
            return serch(2);
    }
}

Measured memory_bytes: 23124
# solution

import io
import sys
import math
from itertools import accumulate as acc

data=sys.stdin.readline

N,C=map(int,data().split())


array=[[0 for i in range(10**5+1)] for i in range(C+1)]

rec=[0 for i in range(10**5+1)]

for i in range(N):
    s,t,c=map(int,data().split())
    recs,rect=array[c][s],array[c][t]
    if recs==0 and rect==0:
        rec[s-1]+=1
        rec[t]-=1
    elif recs==0 and rect==1:
        rec[s-1]+=1
        rec[t-1]-=1
    elif recs==1 and rect==0:
        rec[s]+=1
        rec[t]-=1
    elif recs==1 and rect==1:
        rec[s]+=1
        rec[t-1]-=1

    array[c][s],array[c][t]=1,1

tmp=0
ans=0
for i in range(10**5):
    tmp+=rec[i]
    ans=max(tmp,ans)
print(ans)

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

long long N, Q, ptst, ptend;
long long ans;

int main() {
    cin >> N >> Q;
    long long a[2][N+1], b[Q];
    for (int i=1; i<=N; i++) {
        cin >> a[0][i];
    }
    a[1][0] = 0;
    for (int i=1; i<=N; i++) a[1][i] = a[1][i-1] + a[0][i];
    for (int i=0; i<Q; i++) cin >> b[i];
    for (int i=0; i<Q; i++) {
        ptst = 1;
        ptend = 1;
        ans = 0;
        while (ptend <= N) {
            if (a[1][ptend] - a[1][ptst-1] > b[i]) {
                ans += N - ptend + 1;
                ptst++;
            }
            else {
                ptend++;
            }
        }
        ans = N*(N+1)/2 - ans;
        cout << ans << endl;
    }
}


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

char S[10]={};
int N;
 
void dfs(string s,char mx){
    if (s.size() == N){
        cout << s << endl;
        return;
    }
    for (char c = 'a'; c <= mx+1;c++){
        string t = s;//値渡し（コピーのインスタンスを作成している）
        t = t+c;//一文字追加
        dfs(t,max(mx,c));//引数のtは値渡し（stringもただのクラスだから。配列扱いではない。）
    }
}

int main(){
    cin >>N;

    dfs("a",'a');
    return 0;
}


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

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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

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

constexpr ll MOD = 1000000007;

int n, m, q, ans;
vector<vi> a(60, vi(4));

void dfs(int cnt = 0, vi v = {}, int last = 1)
{
  if (cnt == n) {
    int sum = 0;
    rep(i, q) if (v[a[i][1]-1] - v[a[i][0]-1] == a[i][2]) sum += a[i][3];

    chmax(ans, sum);
    return;
  }

  rep2(i, last, m) {
    v.eb(i);

    dfs(cnt+1, v, last = i);

    v.pop_back();
  }
}

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> n >> m >> q;
  rep(i, q) rep(j, 4) cin >> a[i][j];

  dfs();
  cout << ans << endl;

  return (0);
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
ll re(ll a,ll b) {
	if(a % b == 0) {
		return b * (2 * (a / b) - 1);
	}

	return b * (2 * (a / b)) + re(b,a % b);
}
ll n,x;
int main(){

	cin >> n >> x;
	cout << n + re(n - x,x) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 100100100100100100
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,a,n) for(int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> PLL;

int main() 
{
    int a, b; cin >> a >> b;
    
    if(b%a == 0) {
        cout << a+b << endl;
    } else {
        cout << b-a << endl;
    }

    return 0;
}



Measured memory_bytes: 256
//
//  main.cpp
//  ABC138C
//
//  Created by KJC of Kindai University on 2019/08/29.
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(int argc, const char * argv[]) {
    int N;
    cin >> N;
    vector<double>v(N);
    for (int i=0; i<N; i++) {
        cin >> v.at(i);
    }
    //昇順にソート
    sort(v.begin(),v.end());
    double ans=(v.at(0)+v.at(1))/2.0;
    for (int i=2; i<N; i++) {
        ans=(v.at(i)+ans)/2.0;
    }
    cout << ans<<endl;
    return 0;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)

using namespace std;

int n, m, q;
vector<int> a, b, c, d;

long long score(vector<int> A){
    long long ans = 0;
    REP(i,q){
        if(A[b[i]] - A[a[i]] == c[i]) ans += d[i];
    }
    return ans;
}

long long dfs(vector<int> &A){
    if(A.size() == n){
        return score(A);
    }

    int prev = (A.empty()? 0 : A.back());
    long long res = 0;

    for(int i = prev; i < m; i++){
        A.push_back(i);
        res = max(res, dfs(A));
        A.pop_back();
    }
    return res;
}



int main(void){
    cin >> n >> m >> q;
    a.resize(q); b.resize(q); c.resize(q); d.resize(q);
    REP(i,q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;
        b[i]--;
    }

    vector<int> A;
    cout << dfs(A) << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
long long int mod97=1000000007;
double pi=3.1415926536;
bool comp(pair<long long int,long long int>a,pair<long long int,long long int>b)
{
    if(a.first==b.first)
    {
        if(a.second<=b.second)
        return true;
        else
        return false;
    }
    if(a.first>b.first)
    return true;
    else return false;
}
bool rev(long long int a,long long int b)
{
    if(a>b)return true;
    else return false;
}
bool compa(pair<string,pair<int,int>>a,pair<string,pair<int,int>>b)
{
    if(a.first==b.first)
    {
        if(a.second.first>b.second.first)
        return true;
        else
        return false;
    }
    if(a.first<b.first)
    return true;
    else 
    return false;
}
long long int gcd(long long int bdda,long long int chota)
{
    if(chota==0)
        return bdda;
    return gcd(chota,bdda%chota);
}
void solve()
{
    long long int a,b,c;
    cin>>a>>b>>c;
    if(a==b && b==c)
    {
        cout<<"No";
    }
    else if(a!=b && b!=c && c!=a)
    {
        cout<<"No";
    }
    else
    cout<<"Yes";
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;    
    t=1;

    //cin>>t;
    int count=1;
    while(t--)
    {
        
        solve();
    }
}


Measured memory_bytes: 3624
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7

def deepcopy(li): return [x[:] for x in li]

def gauss_jordan(A, extended=False):
    """ ガウス・ジョルダン法(連立方程式の解) """

    N, M = len(A), max(A).bit_length()
    B = A[:]
    rank = 0
    res = []
    for col in range(M):
        if extended and col == M-1:
            break
        pivot = -1
        for row in range(rank, N):
            if B[row]>>col & 1:
                pivot = row
                break
        if pivot == -1:
            continue
        B[rank], B[pivot] = B[pivot], B[rank]
        for row in range(N):
            if row != rank and B[row]>>col & 1:
                B[row] ^= B[rank]
        res.append(col)
        rank += 1
    for row in range(rank, N):
        if B[row]>>(M-1) & 1:
            return (-1, [])
    return (rank, res)

for _ in range(INT()):
    N = INT()
    A = LIST()
    S = input()
    M = max(A).bit_length()

    mat = [0] * M
    collen = 1
    for i in range(N-1, -1, -1):
        if S[i] == '0':
            for k in range(M):
                mat[k] |= (A[i]>>k & 1) << collen
            collen += 1
        else:
            cur = mat[:]
            for k in range(M):
                cur[k] |= (A[i]>>k & 1) << collen
            rank, res = gauss_jordan(cur, extended=True)
            if rank == -1:
                print(1)
                break
    else:
        print(0)


Measured memory_bytes: 75664
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
  ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
      if(b&1)res = res * x % MOD;
      x = x * x % MOD;
      b>>=1;
    }
    return res;
  }

  ll modinv(ll x){
    return modpow(x, MOD-2);
  }

  bool was_output = false;
  template<class t>
  void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
  }
  void outendl(){
    was_output = false;
    cout << endl;
  }
  ll in(){
    ll res;
    scanf("%lld", &res);
    return res;
  }

  template<class t>
  istream& operator>>(istream&is, vector<t>&x){
    for(auto &i:x)is >> i;
    return is;
  }

  template<class t, class u>
  istream& operator>>(istream&is, pair<t, u>&x){
    is >> x.first >> x.second;
    return is;
  }

  template<class t>
  void in(t&x){
    cin >> x;
  }

  template<class t>
  t in(){
    t res; cin >> res; return res;
  }

  template<class t>
  void out(t x){
    cout << x;
  }

  template<class t>
  vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
    sort(line.begin(),line.end(),comp);
    return line;
  }

  template<class t>
  vector<t> reversed(vector<t> line){
    reverse(line.begin(),line.end());
    return line;
  }
}

using namespace templates;

int n;
vector<ll> values;
vvector<int> edges;
vector<int> anses;

vector<ll> lines;

void setup(){
  n = in();
  values.resize(n);
  edges.resize(n);
  foreach(i,values)i=in();
  anses.resize(n);
  lines.resize(n+4,INFLL);
  rep(i,n-1){
    int a = in()-1;
    int b = in()-1;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
}

void func(int place,int last){
  int p = lower_bound(all(lines),values[place])-lines.begin();
  ll v = values[place];
  swap(lines[p],v);
  anses[place] = lower_bound(all(lines),INFLL)-lines.begin();
  foreach(i,edges[place]){
    if(i==last)continue;
    func(i,place);
  }
  swap(lines[p],v);
}

int main(){
  setup();
  func(0,-1);
  foreach(i,anses)cout<<i<<endl;
  return 0;
}


Measured memory_bytes: 29512
L="".join(map(str,range(6,10)+range(5,0,-1)+range(10)))
for i in range(input()):
    s,e=raw_input().split()
    p1=L.index(s)
    p3=L.rindex(s)
    p2=L.index(e,p1+1)
    if p3>p2:p3=p1
    print " ".join(map(str,L[p3:p2+1]))

Measured memory_bytes: 4236
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  int n,k; cin >> n >> k;
  ll cnt = 0;
  
  for(int b=1;b<=n;b++){
    cnt += n/b * max(b-k,0);
    cnt += max(n%b-(k-1),0);
    if(k==0) cnt--;
    //printf("b=%d cnt=%d\n",b,cnt);
  }
  
  cout << cnt << endl;
  return 0;
}

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

#define pb push_back
#define F first
#define S second

#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define int long long
#define ll long long


	
void solve(){
	int n, tot = 0;
	cin >> n;
	int a[n];
	for(int i = 0 ; i < n ; i++){
		cin >> a[i];	
	}
	for(int i = 1 ; i < n ; i += 2){
		tot ^= (a[i] ^ a[i - 1]);
	}
	for(int i = 0 ; i < n ; i++){
		cout << (tot ^ a[i]) << " ";	
	}
}

signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t = 1;
	//cin >> t;
	while(t--)
		solve();
	return 0;
}

Measured memory_bytes: 5112
N = int(input())
A = [int(input()) for _ in range(N)]

B = [1]
i = 0
cnt = 0
flag = False
for _ in range(N):
    i = A[i] - 1
    cnt += 1
    if i == 1:
        flag = True
        break

print(cnt) if flag else print(-1)


Measured memory_bytes: 7084
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline--------------------------------------------
    n = int(input())
    p = sieve_of_eratosthenes(55555)
    ans = []
    for i in p:
        if i % 5 == 1:
            ans.append(i)
    print(*ans[:n],sep = " ")

if __name__ == "__main__":
    main() #endline===============================================
    

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

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

int main() {
  ll n,W,ans=0,INF=10000000000;
  cin >> n >> W;
  vector<vector<ll>>dp(n+5,vector<ll>(100000+5,INF));
  vector<ll>w(n);vector<ll>v(n);
  rep(i,n) cin >> w.at(i) >> v.at(i);
  dp[0][0]=0;
  rep(i,n) rep(j,100001){
    if(j-v[i]>=0) chmin(dp[i+1][j],dp[i][j-v[i]]+w[i]);
    chmin(dp[i+1][j],dp[i][j]);
  }
  rep(i,100001) if(dp[n][i]<=W) ans=max(ans,i);
  cout << ans << endl;
}


Measured memory_bytes: 83328
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
template<typename T> inline void chkmin(T &a, const T &b) { a = a < b ? a : b; }
template<typename T> inline void chkmax(T &a, const T &b) { a = a > b ? a : b; }

const int MAXN = 105, MOD = 998244353;
typedef __int128 LLL;
char str[MAXN];
map<LLL, int> mp;

int dfs(LLL s, int n) {
	if (n == 0) return 1;
	int &p = mp[s << 10 | n];
	if (p) return p;
	LL f = ((s & 1) + 1) * dfs(s >> 1, n - 1);
	for (int i = 1; i * 2 <= n; i++) {
		LLL sum = s & (((LLL)1 << i) - 1);
		for (int j = 2; i * j <= n; j++) {
			sum &= s >> (j - 1) * i;
			f = (f + (LL)dfs(sum, i) * dfs(s >> i * j, n - i * j)) % MOD;
		}
	}
	return p = f % MOD;
}

int main() {
	scanf("%s", str);
	int n = strlen(str);
	reverse(str, str + n);
	LLL t = 0;
	for (int i = 0; i < n; i++) t = t << 1 | (str[i] - '0');
	printf("%d\n", dfs(t, n));
	return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> p(N);
  REP(i, N) cin >> p[i];
  sort(p.begin(), p.end());
  ll ans = 0;
  REP(i, K) { ans += p[i]; }
  cout << ans << endl;
}

Measured memory_bytes: 3624
n = int(input())
s = list(input())
w_l = [0]*(n+1)
e_l = [0]*(n+1)
ans = float('Inf')
for i in range(0, len(s)):
  if s[i] == 'W':
    w_l[i+1] = w_l[i] + 1
    e_l[i+1] = e_l[i]
  else:
    e_l[i+1] = e_l[i] + 1
    w_l[i+1] = w_l[i]

for i in range(len(s)):
  ans = min(ans, e_l[-1] - e_l[i-1] + w_l[i-1])
print(ans)

Measured memory_bytes: 19920
#include<bits/stdc++.h>
#define ll long long
using namespace std;
signed main(){
  ll n,x=0,y=0,cun=0,a[1000000];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }

  sort(a,a+n,greater<ll>());
  for(int i=0;i<n;i++){
    if(cun==0 && a[i]==a[i+1]){
      x = a[i];
      i++;
      cun++;
    }else if(a[i]==a[i+1]){
      y = a[i];
      break;
    }
  }
  if(x==0 || y==0){
    cout<<"0\n";
  }else{
    cout<<x*y<<"\n";
  }
  return(0);
}


Measured memory_bytes: 2560
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	aa := makeInts(3, 3)
	for i := 0; i < 3; i++ {
		for j := 0; j < 3; j++ {
			aa[i][j] = getNextInt(scanner)
		}
	}
	n := getNextInt(scanner)
	bb := map[int]int{}
	for i := 0; i < n; i++ {
		bb[getNextInt(scanner)] = 1
	}
	for i := 0; i < 3; i++ {
		sum := 0
		for j := 0; j < 3; j++ {
			sum += bb[aa[i][j]]
		}
		if sum == 3 {
			fmt.Fprintln(writer, "Yes")
			return
		}
		sum = 0
		for j := 0; j < 3; j++ {
			sum += bb[aa[j][i]]
		}
		if sum == 3 {
			fmt.Fprintln(writer, "Yes")
			return
		}
	}
	sum := 0
	for i := 0; i < 3; i++ {
		sum += bb[aa[i][i]]
	}
	if sum == 3 {
		fmt.Fprintln(writer, "Yes")
		return
	}
	sum = 0
	for i := 0; i < 3; i++ {
		sum += bb[aa[i][2-i]]
	}
	if sum == 3 {
		fmt.Fprintln(writer, "Yes")
		return
	}

	fmt.Fprintln(writer, "No")
}

func makeInts(h, w int) [][]int {
	index := make([][]int, h, h)
	data := make([]int, h*w, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<string>
#include<cstring>

// ref : http://kyopro.hateblo.jp/entry/2018/12/25/174720

using ll = long long;
/*
dp[d][smaller][leadingZero][num]
numは3, 5, 7を少なくとも1回選んだかどうかのフラグとする
具体的には3bit(つまり0 ~ 7)のうち各bitで管理する
*/
ll dp[11][2][2][8];

int main(){
    std::string S;
    std::cin >> S;

    memset(dp, sizeof dp, 0);
    dp[0][0][0][0] = 1;
    for(int d = 0; d < S.size(); d++){
        for(int smaller = 0; smaller < 2; smaller++){
            for(int leadingZero = 0; leadingZero < 2; leadingZero++){
                for(int num = 0; num < 8; num++){
                    // 未計算は使わないので飛ばす
                    if(dp[d][smaller][leadingZero][num] == -1) continue;

                    if(smaller == 1){
                        // 0 ~ 9まで選べる
                        if(leadingZero == 0){
                            // まだ0が続いている状態
                            // 必ず小さいのでsmallerは1
                            dp[d + 1][1][leadingZero][0] += dp[d][smaller][leadingZero][num];
                        }
                        dp[d + 1][1][1][num | 1] += dp[d][smaller][leadingZero][num]; // 3を入れる場合
                        dp[d + 1][1][1][num | 2] += dp[d][smaller][leadingZero][num]; // 5を入れる場合
                        dp[d + 1][1][1][num | 4] += dp[d][smaller][leadingZero][num]; // 7を入れる場合
                    }else{
                        int val = S[d] - '0';
                        // 0 ~ valまで選べる
                        if(leadingZero == 0){
                            // まだ0が続いている状態
                            // 必ず小さいのでsmallerは1
                            dp[d + 1][1][leadingZero][0] += dp[d][smaller][leadingZero][num];
                        }

                        // valの値に応じてsmallerを切り替えて計算
                        if(val == 3) dp[d + 1][0][1][num | 1] += dp[d][smaller][leadingZero][num];
                        if(val > 3) dp[d + 1][1][1][num | 1] += dp[d][smaller][leadingZero][num];
                        if(val == 5) dp[d + 1][0][1][num | 2] += dp[d][smaller][leadingZero][num];
                        if(val > 5) dp[d + 1][1][1][num | 2] += dp[d][smaller][leadingZero][num];;
                        if(val == 7) dp[d + 1][0][1][num | 4] += dp[d][smaller][leadingZero][num];;
                        if(val > 7) dp[d + 1][1][1][num | 4] += dp[d][smaller][leadingZero][num];
                    }
                }
            }
        }
    }

    std::cout << dp[S.size()][0][1][7] + dp[S.size()][1][1][7] << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAX(a,b) (a>b? a:b)
#define MIN(a,b) (a>b? b:a)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long lint;
using namespace std;

int main(){
	int N;
	int *x, *y, *t;
	cin >> N;
	x = new int[N];
	y = new int[N];
	t = new int[N];
	rep(i,N) cin >> t[i] >> x[i] >> y[i];
	int cx=0, cy=0 ,d;
	rep(i,N){
		d = t[i] - (i>0?t[i-1]:0) - abs(x[i]-cx) - abs(y[i]-cy);
		if((d<0)||(d%2==1)) {
			cout << "No" << endl;
			return 0;
		}
		cx=x[i];
		cy=y[i];
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;

struct coordinates{
    int x,y;
};

bool stage[5001][5001]={};

int latte(coordinates a_c,coordinates b_c){
    coordinates diff,np,a=a_c,b=b_c;
    int situ,s;
    bool flag=true;
    np = b;
    diff.x = b.x-a.x; diff.y = b.y-a.y;
    s = (diff.x*diff.x+diff.y*diff.y)+0.1;
    //printf("1:%d,%d 2:%d,%d ",a.x,a.y,b.x,b.y);
    for(int i=3;i<=4;i++,situ++){
        swap(diff.x,diff.y);
        diff.y*=-1;
        b.x += diff.x; b.y += diff.y;
        //printf("%d:%d,%d ",i,b.x,b.y);
        if(b.x<0 || 5000<b.x || b.y<0 || 5000<b.y || !stage[b.x][b.y]){
            flag=false;
            break;
        }
    }//puts("");
    if(flag){
        //printf("%d,%d %d,%d\n",diff.x,diff.y,a.x,a.y);
        return s;
    }
    return 0;
}

int main(){
    int N;
    while(cin>>N,N){
        for(int i=0;i<=5000;i++)for(int j=0;j<=5000;j++) stage[i][j]=false;

        int ans=0;
        coordinates pole[3001];
        for(int i=0;i<N;i++){
            cin>>pole[i].x>>pole[i].y;
            stage[pole[i].x][pole[i].y]=true;
        }
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                if(i!=j){
                    ans = max(ans,latte(pole[i],pole[j]));
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 25592
#include <bits/stdc++.h>
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define DEC(i, a, b) for (int i = (a); i > (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
typedef long long ll;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
const ll LINF = (int)1e18;
const double EPS = 1e-9;

signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

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

  vector<string> ans;
  REP(i,H) {
    bool flg = false;
    for (auto c: a[i]) {
      if (c == '#') flg = true;
    }
    if (flg) {
      ans.pb(a[i]);
    } 
  }

  int j = 0;
  while(j < W) {
    bool flg = true;
    for (auto l: ans) {
      if (l[j] != '.') flg = false;
    }
    if (flg) {
      for (auto &l: ans) {
        l.erase(j,1);
      } 
      --W;
    } else ++j;
  }
  
  for (auto l: ans) {
    cout << l << endl;
  }
  return 0;
}

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

public class Program
{

	public void Proc()
	{
        string inpt = Reader.ReadLine();

        string ans = "No";
        if(inpt.Equals(string.Join("", inpt.Reverse()))) {
            ans = "Yes";
        }
        Console.WriteLine(ans);
    
    
    }


    public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"



575


";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K;
  cin >>K;
    vector<int> vec;
  vec={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout <<vec.at(K-1)<<endl;
  
  
  
  
}

  


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

vector<bool> IsPrime;
vector<int> primes;

void sieve(int max) {
    IsPrime.resize(max + 1, true);
    IsPrime[0] = IsPrime[1] = false;
    for (int i = 2; i * i <= max; ++i){
        if (IsPrime[i]){
            for (int j = i * i; j <= max; j += i) IsPrime[j] = false;
        }
    }
    for(int i = 0; i <= max; ++i) if(IsPrime[i])primes.push_back(i);
}

int main() {
    sieve(int(1e6));
    int n;
    while(cin >> n, n){
        int ans = 0;
        for(int i=0;primes[i]*2<=n;i++){
            if(IsPrime[n-primes[i]]) ans++;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3352
import math

t=int(input()) 
for i in range(t):
    a,b,c,d=map(int,input().split())
    if a<b:
        print("No")
    elif d<b:
        print("No")
    elif c>=b:
        print("Yes")
    elif b-math.gcd(b,d)+(a%math.gcd(b,d))>c:
        print("No")
    else:
        print("Yes")

Measured memory_bytes: 9088