akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << " " << *t++;
        // if(t != V.end()) cout << " ";
    }
    cout << endl;
};

bool checkqueen(vector<vector<char>> &B, int r, int c) {
    rep(i, 8) if(B[r][i] == 'Q') return false;
    rep(i, 8) if(B[i][c] == 'Q') return false;
    int rr = r, cc = c;
    while(rr > 0 && cc > 0) {
        rr--;
        cc--;
    }
    for(int i = 0; rr + i < 8 && cc + i < 8; i++)
        if(B[rr + i][cc + i] == 'Q') return false;
    rr = r, cc = c;
    while(rr < 7 && cc > 0) {
        rr++;
        cc--;
    }
    for(int i = 0; rr - i > -1 && cc + i < 8; i++)
        if(B[rr - i][cc + i] == 'Q') return false;
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, r, c;
    vector<vector<char>> B(8, vector<char>(8, '.'));
    stack<pair<int, int>> L;
    vector<int> resr(8, 0), resc(8, 0);
    cin >> n;
    rep(i, n) {
        cin >> r >> c;
        resr[r] = resc[c] = 1;
        L.push(make_pair(r, c));
        B[r][c] = 'Q';
    }

    int str = 0, stc = 0, size = 0;
    while(L.size() < 8) {
        bool checkmate = true;
        rep(i, str, 8) {
            if(resr[i]) continue;
            rep(j, stc, 8) {
                if(resc[j]) continue;
                if(checkqueen(B, i, j)) {
                    L.push(make_pair(i, j));
                    B[i][j] = 'Q';
                    checkmate = false;
                    resr[i] = resc[j] = 1;
                    str = (i + 1) % 8;
                    stc = 0;
                }
            }
        }
    onemore:
        if(checkmate) {
            pair<int, int> tmp = L.top();
            L.pop();
            B[tmp.first][tmp.second] = '.';
            resr[tmp.first] = resc[tmp.second] = 0;
            str = tmp.first;
            stc = tmp.second + 1;
            if(stc == 8 && L.size() > n) goto onemore;
        }
    }

    rep(i, 8) {
        rep(j, 8) cout << B[i][j];
        cout << "\n";
    }
}



Measured memory_bytes: 3208
// @snippet<sh19910711/contest:headers.cpp>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <limits>
#include <complex>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

// @snippet<sh19910711/contest:solution/interface.cpp>
namespace solution {
    class ISolution {
    public:
        virtual void init() {};
        virtual bool input() { return false; };
        virtual void output() {};
        virtual int run() = 0;
    };
}

// @snippet<sh19910711/contest:solution/solution.cpp>
namespace solution {
    using namespace std;
    const int SIZE = 501;
    int n;
    int A[SIZE];
    class Solution: public ISolution {
    public:
        bool input() {
            if ( ! ( cin >> n ) )
                return false;
            for ( int i = 0; i < n; ++ i )
                cin >> A[i];
            return true;
        }
        void solve() {
            int D[4];
            fill( D, D+4, 0 );
            sort( A, A+n, greater<int>() );
            long long res = 0;
            for ( int i = 0; i < n; ++ i ) {
                int di = i % 4;
                if ( A[i] <= D[di] )
                    continue;
                res += A[i] - D[di];
                D[di] ++;
            }
            cout << res + 1 << endl;
        }
        int run() {
            while ( init(), input() ) {
                solve();
                output();
            }
            return 0;
        }
    };
}


// @snippet<sh19910711/contest:main.cpp>

int main() {
    return solution::Solution().run();
}

Measured memory_bytes: 1180
def main2():
    h,w,k = map(int,input().split()) 
    G = []
    for _ in range(h):
        c = list(input())
        G.append(c)
    ans = 0

    for ib in range(1<<h):
        for jb in range(1<<w):
            ct = 0
            for i in range(h):
                for j in range(w):
                    if (ib>>i)&1 and (jb>>j)&1 and G[i][j]=="#":
                        ct+=1
            
            if ct == k:
                ans+=1
    
    print(ans)
main2()

Measured memory_bytes: 9116
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

X = int(input())
if X >= 30:
    print("Yes")
else:
    print("No")




Measured memory_bytes: 10624
/*
Problem : AtCoder Grand Contest 030 - A
Algorithm : math
Status :
*/
#include <bits/stdc++.h>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;

int a,b,c,ans;

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%d%d%d",&a,&b,&c);
	ans = b + min(c,a + b + 1);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	string s ; cin >> s ;
	yorn(!(s=="AAA"||s=="BBB")) ;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        String str = sc.next();
        if(str.length() <= k) System.out.println(str);
        else {
            String str1 = str.substring(0, k);
            System.out.println(str1 + "...");
        }
    }
}

Measured memory_bytes: 38540
import sys
import math
import itertools
import collections
import heapq
import numpy as np

rl = sys.stdin.readline

n = int(rl())

blue = [rl() for _ in range(n)]

m = int(rl())
red = [rl() for _ in range(m)]

ans = 0
for i in list(set(blue)):
    b = blue.count(i) - red.count(i)
    if b > ans:
        ans = b
print(ans)


Measured memory_bytes: 12440
#include <stdio.h>

int main(){
	int i;
	double x;
	i=0;
	while(1){
		scanf("%d",&i);
		if(i==-1)
			break;
		x=i;
		x=(x/2)-((x/2)*(x/2)*(x/2)-i)/(3*(x/2)*(x/2));
		while((0.99999*i>=x*x*x) | (x*x*x>=1.00001*i)){
			x=x-(x*x*x-i)/(3*x*x);
		}
		printf("%lf\n",x);
	}
	return 0;
}

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

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

	int a[n][m];
	int b[m];
	
	for (int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			int x;
			cin >> x;
			a[i][j] = x;
		}
	}
	
	for (int i = 0; i < m; i++){
		int y;
		cin >> y;
		b[i] = y;
	}

	for (int i = 0; i < n; i++){
		int ans = 0;
		for(int j = 0; j < m; j++){
			ans += a[i][j] * b[j];
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i <= (int)(n); i++)
const long long INF = 1LL << 60;
const double PI=3.14159265358979323846;
int main() 
{
    int r;
    cin >> r;

    cout << r*r << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repR(i, n) for(int i = n; i >= 0; ++i)
#define FDS(i, n) for(ll i = 0; i < n; ++i)
#define FDSR(i, n) for(int i = n; i >= 0; ++i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define FORR(i, m, n) for(int i = m;i >= n;--i)
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define itn int
#define ednl endl
using namespace std;
typedef long long ll;
int main(){
	int N,K;
	cin>>N>>K;
	vector<int> X(N);
	FDS(i,N){
		cin>>X[i];
	}
	int ans=INF;
	int sub=0;
	FDS(i,N-K+1){
		sub=0;
		sub+=min(abs(X[i]),abs(X[i+K-1]));
		sub+=abs(X[i]-X[i+K-1]);
		if(sub<=ans){
			ans=sub;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) int(a.size())
const ll Inf=1e18;

int gi() {
	int x=0,o=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*o;
}

ll n;
int d,p[6];
unordered_map<ll,ll> M;

ll mul(ll a,ll b) {
	if((long double)a*b>Inf) return Inf;
	return a*b;
}

ll cal(ll n) {
	if(M.count(n)) return M[n];
	ll ret=mul(n,d);
	for(auto k:{2,3,5}) {
		ll t=(n+k-1)/k;if(t==n) continue;
		ret=min(ret,mul(k*t-n,d)+p[k]+cal(t));
		t=n/k;ret=min(ret,mul(n-k*t,d)+p[k]+cal(t));
	}
	return M[n]=ret;
}

int main() {
	int T=gi();
	while(T--) {
		cin>>n>>p[2]>>p[3]>>p[5]>>d;
		M.clear();
		cout<<cal(n)<<'\n';
	}
	return 0;
}


Measured memory_bytes: 4060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

struct State{
    int v, d, c;
    State(int v, int d, int c): v(v), d(d), c(c){}
    bool operator<(const State& right ) const {
        return d == right.d ? c > right.c : d > right.d;
    }
};

struct edge{
    int to, d, c;
    edge(int to, int d, int c) : to(to), d(d), c(c) {}
};

int mind[100002];
int minc[100002];

int main(){
    while(true){
        int N, M;
        cin >> N >> M;
        if(N == 0) break;

        vector<vector<edge>> G(N);
        for(int i=0;i<M;i++){
            int u, v, d, c;
            cin >> u >> v >> d >> c;
            u--;
            v--;
            G[u].emplace_back(v, d, c);
            G[v].emplace_back(u, d, c);
        }

        priority_queue<State> que;
        que.emplace(0, 0, 0);
        fill(mind, mind+N, (1<<29));
        fill(minc, minc+N, (1<<29));
        mind[0] = 0;
        minc[0] = 0;

        int ans = 0;
        while(que.size()){
            State s = que.top(); que.pop();
            if(mind[s.v] < s.d || minc[s.v] < s.c) continue;
            ans += s.c;
            for(edge e : G[s.v]){
                int nd = s.d + e.d;
                if(mind[e.to] > nd || (mind[e.to] == nd && minc[e.to] > e.c)){
                    mind[e.to] = nd;
                    minc[e.to] = e.c;
                    que.emplace(e.to, nd, e.c);
                }
            }
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 4020
#include <bits/stdc++.h>
using namespace std;
template <typename T>void read(T &x){
	x = 0; int f(1); char c = getchar();
	for(;!isdigit(c);c = getchar()) if(c == '-') f = -1;
	for(;isdigit(c);c = getchar()) x = x*10+c-'0';
	x *= f;
}
int n,m,q,va[11],ans;
struct edge{int a,b,c,d;}A[55];
void solve(int,int);
int main(){
	read(n); read(m); read(q);
	for(int i(1);i <= q;++i)
		scanf("%d%d%d%d",&A[i].a,&A[i].b,&A[i].c,&A[i].d);
	solve(1,1); printf("%d\n",ans);
	return 0;
}
void solve(int x,int lst){
	if(x == n+1){
		int sum = 0;
		for(int i(1);i <= q;++i)
			if(va[A[i].b]-va[A[i].a] == A[i].c)	sum += A[i].d;
		ans = max(ans,sum); return;
	}
	for(int i = lst;i <= m;++i)
		va[x] = i,solve(x+1,i),va[x] = 0;
}

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

int main()
{
    string str;
    char a,b,c;
    cin >> str;
    if(str[0]!=str[1] && str[0]!=str[2] && str[1]!=str[2])
        cout << "Yes\n";
    else
        cout << "No\n";
}


Measured memory_bytes: 256
def main():
    result = []
    strings = ["A", "T", "G", "C"]
    S = input()
    tmp = 0
    for s in S:
        if s in strings:
            tmp += 1
        else:
            result.append(tmp)
            tmp = 0
    result.append(tmp)
    print(max(result))


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
package main

import "fmt"

func main() {
	// Code for A - Don't be late
	var D, T, S int
	fmt.Scanf("%d %d %d", &D, &T, &S)

	if D <= S*T {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1836
#include <stdio.h>
#include <stdlib.h>
   
struct node{
   
int id;
struct node* parentNode;
struct node* leftChild;
struct node* rightChild;
   
};
   
struct node *createNode(int);
void insert(struct node*);
void printNodes(void);
void preOrder(struct node *);
void inOrder(struct node *);
   
struct node* nodes[500001];
struct node* root;
  
int num_nodes=0, n; 
  
main(){
   
int i, id;
char command[7];
 struct node* tmpNode;
   
scanf("%d",&n);
   
for(i=0; i<n; i++){
   
scanf("%s",command);
if(command[0]=='i'){
scanf("%d",&id);
insert(createNode(id));
}else if(command[0]=='p'){
printNodes();
}
   
}/* END OF LOOP */
  
 return 0;
   
}
  
struct node *createNode(int id){
  struct node *newNode;
  if(id<0) return NULL;
  
  newNode=(struct node*)malloc(sizeof(struct node));
  newNode->id=id;
  newNode->parentNode=NULL;
  newNode->rightChild=NULL;
  newNode->leftChild=NULL;
    
  nodes[num_nodes++]=newNode;
  return newNode;
}
 
void insert(struct node* z){
   
  struct node* y = NULL;
  struct node* x = root;
  
  while(x != NULL){
    y = x;
    if(z->id < x->id){
      x = x->leftChild;
    }else{
      x = x->rightChild;
    }
  }
  z->parentNode = y;
  if(y == NULL){
    root = z;
  }else{
    if(z->id < y->id){
      y->leftChild = z;
    }else{
      y->rightChild = z;
    }
  }
   
}
   
void printNodes(void){
     
  inOrder(root);
  printf("\n");
  preOrder(root);
  printf("\n"); 
  
}
   
void preOrder(struct node* nd){
  printf(" %d",nd->id);
  if(nd->leftChild){
    preOrder(nd->leftChild);
  }
  if(nd->rightChild){
    preOrder(nd->rightChild);
  }
   
}
   
void inOrder(struct node* nd){
  if(nd->leftChild){
    inOrder(nd->leftChild);
  }
  printf(" %d",nd->id);
  if(nd->rightChild){
    inOrder(nd->rightChild);
  }
   
}

Measured memory_bytes: 13000
#include<iostream>
#include<cstdio>
#include<algorithm>
typedef long long ll;
const int N=1e5+5,INF=1e9+7;
bool vis[N]={};int n,m,a[N],cnt,head[N];
struct Edge {
    int to,nxt;
}edge[N<<1];
void init() {
    for(int i=0;i<n;i++) head[i]=-1,vis[i]=false;cnt=0;
}
void addEdge(int from,int to) {
    edge[cnt].to=to;edge[cnt].nxt=head[from];head[from]=cnt++;
}
int dfs(int u) {
    vis[u]=true;int res=u,tmp;
    for(int i=head[u];~i;i=edge[i].nxt) {
        int v=edge[i].to;
        if(vis[v]) continue;
        tmp=dfs(v);
        if(a[tmp]<a[res]) res=tmp;
    }
    return res;
}
int main() {
    scanf("%d%d",&n,&m);init();int u,v;
    for(int i=0;i<n;i++) scanf("%d",a+i);
    while(m--) {
        scanf("%d%d",&u,&v);
        addEdge(u,v);addEdge(v,u);
    }
    ll ans=0;int cnt=0;
    for(int i=0;i<n;i++) {
        if(vis[i]) continue;
        cnt++;u=dfs(i);
        ans+=a[u];a[u]=INF;
    }
    if(cnt==1) {
        printf("0\n");
        return 0;
    }
    std::sort(a,a+n);
    for(int i=0;i<cnt-2;i++) {
        if(a[i]>=INF) {
            printf("Impossible\n");
            return 0;
        }
        ans+=a[i];
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((ll)(x).size())

const double PI  = acos(-1.0);
const double EPS = 1e-9;
const ll INF = 1e9+10;
const ll mod = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define print(x) cerr << #x << " is " << x << endl;
//#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 
int N, M, Q;
int A[100], B[100], C[100], X[100];
ll D[100];
ll dfs(int d, int lower){
    ll best = 0;
    if (d == N){
        ll val = 0;
        rep(q, Q){
            if (X[B[q]] - X[A[q]] == C[q])val += D[q];
        }
        return val;
    }
    reps(i, lower, M + 1){
        X[d] = i;
        ll val = dfs(d + 1, X[d]);
        chmax(best, val);
    }
    return best;
}
int main()
{

    cin >> N >> M >> Q;
    rep(i, Q){
        cin >> A[i] >> B[i] >> C[i] >> D[i];
        A[i]--;B[i]--;
    }
        
    
    cout << dfs(0, 1);
    return 0;
}


Measured memory_bytes: 3560
#!/usr/bin/env python3
#ABC63 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def f(t):
    lst = list(map(lambda x: max(0, math.ceil((x-b*t)/(a-b))),h))
    if sum(lst) <= t:
        return True
    return False

n,a,b = LI()
h = [I() for _ in range(n)]
maxh = max(h)
ok,ng = math.ceil(maxh/b),0
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if f(mid):
        ok = mid
    else:
        ng = mid
print(ok)


Measured memory_bytes: 130696
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int n = in.nextInt();
        final int x = in.nextInt();
        int dis = 0;
        int count = 0;
        if (count <= x) {
            count++;
        }
        for (int i = 0; i < n; i++) {
            int l = in.nextInt();
            dis += l;
            if (dis <= x) {
                count++;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 21844
N = int(input())
P = list(map(int,input().split()))
T = [P[0]]+[10**10]*(N-1)
ans = 0

for i in range(N):
    T[i] = min(T[i-1],P[i])

for i in range(N):
    if P[i] <= T[i]:
        ans += 1

print(ans)

Measured memory_bytes: 32256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	a := nextInt()
	b := nextInt()
	c := nextInt()
	x := nextInt() // a
	y := nextInt() // b
	//l := make([]int, n)

	costDefault := a*x + b*y
	costmin := costDefault
	// ABピザを2枚ずつAピザ,Bピザで置き換えていく
	for ab := 0; ab <= 100000; ab++ {
		newcost := 2*c*ab + a*max(0, x-ab) + b*max(0, y-ab)
		costmin = min(costmin, newcost)
	}

	fmt.Println(costmin)

}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1780
#include <stdio.h>

int main() {
  int h1, h2, m1, m2, k, ans;
  scanf("%d%d%d%d%d", &h1, &m1, &h2, &m2, &k);
  ans = (h2 - h1) * 60 + (m2 - m1) - k;
  printf("%d\n", ans);
}

Measured memory_bytes: 1712
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

vector<ll> divisors(ll N) {
  vector<ll> res;
  for (ll d = 1; d * d <= N; d++) {
    if (N % d == 0) {
      res.push_back(d);
      if (N / d != d) res.push_back(N / d);
    }
  }
  return res;
}

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  ll N;
  while (cin >> N) {
    int res = 0;
    for (ll d : divisors(N)) {
      if (d == 1) continue;
      ll M = N;
      while (M % d == 0) M /= d;
      if (M % d == 1) ++res;
    }
    res += divisors(N - 1).size() - 1;
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 384
def n_pow(a, n):
    if n <= 0:
        return 0
    return pow(a, n)


def main():
    bags, remainder = map(int, input().split())
    biscuits = list(map(int, input().split()))
    count = [0, 0]
    for b in biscuits:
        count[b % 2] += 1
    if remainder == 1 and count[1] == 0:
        print(0)
    elif count[1] == 0:
        print(pow(2, bags))
    else:
        print(n_pow(2, bags - 1))


if __name__ == '__main__':
    main()



Measured memory_bytes: 3060
def main():
    s = [int(i) for i in input()]
    op = {'+':1, '-':-1}
    for a in op:
        for b in op:
            for c in op:
                if s[0] + op[a] * s[1] + op[b] * s[2] + op[c] * s[3] == 7:
                    return (str(s[0]) + a + str(s[1]) + b + str(s[2]) + c + str(s[3]) + '=7')

        
if __name__ == '__main__':
    print(main())

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

int main(void)
{
    int N,M;
    cin >> N >> M;
    int a[M];
    int b[M];
    int t1[M];
    int t2[M];
    int tmp1,tmp2;
    int count = 0;
    int count2 = 0;
    int count3 = 0;

    for( int i = 0; i < M; i++){
        cin >> tmp1 >> tmp2;
        if(tmp1 == 1 || tmp2 == N){
            a[count] = tmp1;
            b[count] = tmp2;
            count++;
        }
    }
    sort(a, a+count);
    sort(b, b+count);
    //puts("");
    for( int i = 0; i < count ; i++){
        //printf("%d %d\n",a[i],b[i]);
        if( a[i] == 1 && (count3 == 0 || t1[count3-1] != a[i])){
            t1[count3] = b[i];
            count3++;
        }
        if( b[i] == N && (count2 == 0 || t2[count2-1] != a[i])){
            t2[count2] = a[i];
            count2++;
        }
    }
    //puts("");

    if( count2 > count3){
        for( int i = 0; i < count3; i++){
            for( int j = 0; j < count2; j++){
                if( t1[i] > t2[j+count2/2]){
                    j += count2/2;
                }
                //printf("%d %d\n",t1[i],t2[j]);
                if( t1[i] == t2[j] ){
                    printf("POSSIBLE");
                    return 0;
                }
                if( t1[i] < t2[j] ){
                    break;
                }
            }
        }
    }else{
        for( int j = 0; j < count2; j++){
            for( int i = 0; i < count3; i++){
                if( t1[i+count2/2] < t2[j]){
                    i += count2/2;
                }
                //printf("i = %d, j = %d\n", i, j);
                //printf("%d %d\n",t2[j],t1[i]);
                if( t1[i] == t2[j] ){
                    printf("POSSIBLE");
                    return 0;
                }
                if( t2[j] < t1[i] ){
                    //printf("break!\n");
                    break;
                }
            }
        }
    }
    printf("IMPOSSIBLE");
    
    return 0;
}

Measured memory_bytes: 3328
N = gets.to_i
A = gets.split.map &:to_i

c = Array.new(3) { |i| A.select { |x| x % 2**i == 0 && (i == 2 || x % 2**(i + 1) > 0) } .size }

ans = []

N.times do |i|
  3.times do |j|
    t = i % 2 == 0 ? j : 2 - j
    next if c[t] == 0
    ans << t
    c[t] -= 1
    break
  end
end

(N - 1).times do |i|
  if ans[i] + ans[i + 1] < 2
    puts "No"
    exit
  end
end

puts "Yes"


Measured memory_bytes: 12676
#include <iostream>
using namespace std;
int a[4][3][10] = {0};
int main(){
	int n, b, f, r, v;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> b >> f >> r >> v;
		a[b-1][f-1][r-1] += v;
	}
	for(int i = 0; i < 4; i++){
		for(int j = 0; j < 3; j++){
			for(int k = 0; k < 10; k++){
				cout << " " << a[i][j][k];
			}
			cout << endl;
		}
		if (i < 3){
			cout << "####################" << endl;
		}
	}
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional>
#define ll long long int
#define ld long double
#define pb push_back
#define pll pair<ll,ll>
#define pint pair<int,int>
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define mod 1000000007
#define MAX 10000002
#define endl '\n'
#define mp make_pair
#define INF INT_MAX
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ff first
#define ss second
#define ps(x,y) fixed<<setprecision(y)<<x
#define setbits(x) __builtin_popcountll(x)			//counts no of ones in binary representation
#define w(t) 	int t; cin>>t; while(t--)
#define pi 3.141592653589793238
#define sortt(v)  sort(v.begin(),v.end())
#define lb(v,x) std::lower_bound(v.begin(),v.end(),x)
#define ub(v,x) std::upper_bound(v.begin(),v.end(),x)

using namespace std;

ll dp[MAX];

void SieveOfEratosthenes(int n) 			//best way to find primes O(nlog(logn))
{ 
	int cnt=0;
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
              
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
}

int main(){
	fast;
	ll n;
	cin>>n;
	ll ans=0;
	memset(dp,0,sizeof(dp));
	for(ll i=1;i<=n;i++){
		for(ll j=1;j*i<=n;j++)	dp[i*j]++;
	}
	for(ll i=1;i<=n;i++){
		ll x=i*dp[i];
		ans+=x;
	}
	cout<<ans;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	string s, t;
	cin >> s >> t;

	bool ans = false;
	rep(i, s.length()){
		cerr << s << endl;
		if(s == t) ans = true;
		s = s.substr(1, s.length()-1) + s[0];
	}

	cout << (ans ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
// #define int long long
struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
}IoSetup;

using Int = __int128_t;
using ll = long long;
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int SMOD = 1000000007;
constexpr int NMOD = 998244353;
constexpr int dx[]={1,0,-1,0,1,1,-1,-1};
constexpr int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T&b){if(a<b)return(a=b,1);return 0;}
template<class T>bool chmin(T &a, const T&b){if(b<a)return(a=b,1);return 0;}


signed main() {

    string s, t;

    cin >> s >> t;
    int mv = t.size();
    for(int i = 0; i < s.size() - t.size() + 1; i++) {
        int sum = 0;
        for(int j = 0; j < t.size(); j++) {
            if(s[i+j] != t[j]) sum++;
        }
        chmin(mv, sum);;
    }

    cout << mv << endl;

    return 0;
}

Measured memory_bytes: 3656
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}


int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;

      bool flag=false;

      string str;

      set<string>v;

      cin>>str>>k;

      n=str.size();

        for(i=0; i<n; i++)
        {
            string temp;

            for(j=i; j<=i+k && j<n; j++)
            {
                temp+=str[j];

                v.insert(temp);
            }
        }

       for(auto x : v)
       {
           cnt++;

          // cout<<x<<endl;

           if(cnt==k)
           {
               cout<<x<<endl;
              return 0;
           }
       }













}



Measured memory_bytes: 5136
#include <stdio.h>

int main(void)
{
	int n;
	int sum = 0;
	int i;
	
	scanf("%d", &n);
	
	for(i=n; i!=0; i/=10)
		sum += i%10;
	
	if(n%sum == 0)
		printf("Yes");
	else
		printf("No");
	
	return 0;
}


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

using namespace std;

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

    string s;
    cin >> s;
    s[1] = (s[1] == 'R' ? 'B' : 'R');
    cout << s << "\n";

    return 0;
}

Measured memory_bytes: 3620
#include <cstdio>

#define MAX 31

int main(){
  int dp[MAX] = {1,1,2};

  for(int i = 3 ; i < MAX ; i++){
    dp[i] = dp[i-1] + dp[i-2] + dp[i-3];
  }

  int n;
  while(scanf("%d" ,&n),n){
    printf("%d\n" ,dp[n]/3650+1);
  }

  return 0;
}

Measured memory_bytes: 1028
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main {
    static MyReader in = new MyReader();

    static long[][] nCr = new long[51][51];

    public static void main(String[] args) {
        int N = in.i();
        int K = in.i();
        int ans = N;
        boolean[] b = new boolean[N];
        for (int i = 0; i < K; i++) {
            int d = in.i();
            for (int j = 0; j < d; j++) {
                int a = in.i() - 1;
                if (!b[a]) {
                    b[a] = true;
                    ans--;
                }
            }
        }
        out.println(ans);
    }

    static long pow(long a, int b) {
        long c = 1;
        while (b > 0) {
            if ((b & 1) == 1) {
                c *= a;
            }
            a *= a;
            b >>= 1;
        }
        return c;
    }

    static long nCr(int n, int r) {
        if (n < r) return 0;
        if (nCr[n][r] > 0) return nCr[n][r];
        if (r == 0) return nCr[n][r] = 1;
        if (n - r < r) return nCr[n][r] = nCr(n, n - r);
        else return nCr[n][r] = nCr(n - 1, r - 1) + nCr(n - 1, r);
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    int i() {
        int k = next() - '0';
        boolean minus = k == -3;
        int n = minus ? 0 : k;
        while (0 <= (k = next() - '0') && k <= 9) n = 10 * n + k;
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    char[] s(final int N) {
        char[] s = new char[N];
        for (int i = 0; i < N; i++) {
            s[i] = next();
        }
        next();
        return s;
    }

    public int read(char[] cbuf) {
        int i;
        for (i = 0; i < cbuf.length; i++) {
            char c = next();
            if (c == ' ' || c == '\n') {
                break;
            }
            cbuf[i] = c;
        }
        if (i == cbuf.length) next();
        return i;
    }
}


Measured memory_bytes: 32680
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s, t;
  while(cin >> s){
    cin >> t;
    int ans = 0;
    for(int i = 0; i < s.length(); i++){
      string sub_s = s.substr(i, s.length() - i);
      int cnt = 0;
      for(int j = 0; j < min(sub_s.length(), t.length()); j++){
	if(sub_s[j] == t[j]){
	  cnt++;
	  if(cnt > ans) ans = cnt;
	}else{
	  cnt = 0;
	}
      }
    }
    for(int i = 0; i < t.length(); i++){
      string sub_t = t.substr(i, t.length() - i);
      int cnt = 0;
      for(int j = 0; j < min(sub_t.length(), s.length()); j++){
	if(sub_t[j] == s[j]){
	  cnt++;
	  if(cnt > ans) ans = cnt;
	}else{
	  cnt = 0;
	}
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3016
#include<iostream>
#include<string>

using namespace std;

int main() {

	char input[10001];
	int i = 0;
	int N = 0;

	cin >> N >> input;

	while (input[i] != '\0') {

		input[i] = input[i] + N <= 'Z' ? input[i] + N : input[i] + N - 26;
		i++;

	}

	cout << input << endl;

	return 0;

}

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

using namespace std;

int main(int argc, const char *argv[]) {
  int S;
  bool ymflag = true;
  bool myflag = true;
  vector<int> a(4);
  cin >> S;

  a[0] = S / 1000;
  a[1] = (S - a[0] * 1000) / 100;
  a[2] = (S - a[0] * 1000 - a[1] * 100) / 10;
  a[3] = S % 10;

  if ((a[0] * 10 + a[1]) > 12) {
    myflag = false;
  }
  if((a[0] * 10 + a[1]) == 0){
    myflag = false;
  }
  if((a[2] * 10 + a[3]) > 12){
    ymflag = false;
  }
  if((a[2] * 10 + a[3]) == 0){
    ymflag = false;
  }

  if(myflag == true && ymflag == true){
    cout << "AMBIGUOUS" << endl;
  }else if(myflag){
    cout << "MMYY" << endl;
  }else if(ymflag){
    cout << "YYMM" << endl;
  }else{
    cout << "NA" << endl;
  }

  return 0;
}


Measured memory_bytes: 888
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace regio
{
    class Class1
    {
        static void Main()
        {
            string str;
            string[] arr;

            int N, T, A;
            double Temp, SaM;
            int bangou=0;

            str = Console.ReadLine();
            N = int.Parse(str);

            int H;
            double Tem,Sa,Te;

            str = Console.ReadLine();
            arr = str.Split(' ');
            T = int.Parse(arr[0]);
            A = int.Parse(arr[1]);
            SaM = 1145141919;

            str = Console.ReadLine();
            arr = str.Split(' ');

            for (int i = 0; i < N; i++)
            {
                H = int.Parse(arr[i]);
                Temp = 0.006 * H;

                Tem =T - Temp;

                Te = Tem - A;

                Sa = Math.Abs(Te);

                if (Sa<SaM)
                {
                    SaM = Sa;
                    bangou = i+1;
                }
            }
            Console.WriteLine("{0}", bangou);
        }
        
    }
}


Measured memory_bytes: 13204
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    string s;
    cin>>s;
    for(int i=0;i<s.length();++i)
    {
        if(s[i]==',') cout<<' ';
        else cout<<s[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
from itertools import combinations_with_replacement
n,m,q=map(int,input().split())
l=[list(map(int,input().split())) for i in range(q)]
ans=0
for i in combinations_with_replacement([i for i in range(1,m+1)], n):
    tmp=0
    for a,b,c,d in l:
        if i[b-1]-i[a-1]==c:
            tmp+=d
    ans=max(ans,tmp)
print(ans)

Measured memory_bytes: 67848
#include <stdio.h>
int main()
{
	int S, h, m, s;
	scanf("%d", &S);

	if (0 <= S&&S <= 86400)
	{
		h = S / 3600;
		m = (S - h * 3600) / 60;
		s = S - (h * 3600 + m * 60);
		
		printf("%d:%d:%d\n", h, m, s);
	}
	

	return 0;
}

Measured memory_bytes: 592
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string str = Console.ReadLine();
		bool flag = true;
		int N = str.Length;
		for(var i=0;i<N;i++){
			if(str.Substring(i,1)!=str.Substring(N-1-i,1)){
				flag = false;
			}
		}
		for(var i=0;i<(N-1)/2;i++){
			if(str.Substring(i,1)!=str.Substring((N-1)/2-1-i,1)){
				flag = false;
			}
		}
		for(var i=(N+3)/2-1;i<N;i++){
			if(str.Substring(i,1)!=str.Substring(N-1-i,1)){
				flag = false;
			}
		}
		if(flag){
			Console.WriteLine("Yes");
		} else {
			Console.WriteLine("No");
		}
	}
}

Measured memory_bytes: 13140
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
////////////////////////////


int main(){fastio
    ll n,m;cin>>n>>m;
    if(n==m)cout<<"Yes";
    else cout<<"No";
    
    
    return 0;
}


Measured memory_bytes: 256
from functools import reduce
import fractions

N, X = map(int, input().split())
x = list(map(int, input().split()))

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

delta = []

for i in x:
    delta.append(abs(X-i))
    
print(gcd_list(delta))


Measured memory_bytes: 16308
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<algorithm>
#include<string>

using namespace std;

int main(){
  string S,T;
  map<char,char> m1,m2;
  bool ans = true;

  cin >> S >> T;

  for(int i = 0;i < S.length();i++){
    if(m1.count(S[i]) != 0 || m2.count(T[i]) != 0){
      if(m1.count(S[i]) == 0 || m2.count(T[i]) == 0){
        ans = false;
        break;
      }
      if(m1[S[i]] != T[i] && m2[T[i]] == S[i]){
        ans = false;
        break;
      }
    }

    m1[S[i]] = T[i];
    m2[T[i]] = S[i];
  }

  if(ans)cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,x;
  cin>>n>>x;
  vector<int >sweet(n,0);
  for(int i=0;i<n;i++)cin>>sweet[i];
  sort(sweet.begin(),sweet.end());
  int tot=0;
  for(int i=0;i<n;i++){
  	if(x>=sweet[i]){tot+=1;x-=sweet[i];}
  }
  if(x==0)cout<<min(tot,n);
  else if(x!=0 && tot==n)cout<<n-1;
  else cout<<tot;
}

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

using namespace std;
#define int long long
#define rep(i,n) for(int i = 0;i < (n) ;i++)
using P = pair<int,int>;

int n;
int q[100];
int p[100];
P dp[101][50000];

P operator+(P a, P b) {
    return P(a.first+b.first, a.second+b.second);
}

void init(void) {
    rep(i,n+1) {
        rep(j,50000) {
            dp[i][j] = P(-1,1);
        }
    }
}

P rec(int i, int r) {
    if (dp[i][r] != P(-1,1)) return dp[i][r];
    if (i >= n) return dp[i][r] = P(0,0);
    if (1 <= q[i] && q[i] <= 500) {
        P a = P(1,-p[i]) + rec(i + 1, r + 500 - q[i]);
        P b = rec(i + 1, r);
        return dp[i][r] = max(a,b);
    }
    int qq = q[i];
    if (qq == 0) qq = 1000;
    P a = P(-1,1), b;
    if (r >= qq - 500) {
        a = P(1, -p[i]) + rec(i + 1, r - qq + 500);
    }
    b = P(0, -p[i]) + rec(i + 1, r + 1000 - qq);
    P c = rec(i+1, r);
    return dp[i][r] = max(a, max(b,c));
}

void solve(void) {
    init();
    P ans = rec(0,0);
    cout << ans.first << " " << -ans.second << endl;
}

signed main (void) {
    while(true) {
        cin >> n;
        if (n == 0) break;
        rep(i,n) {
            cin >> p[i];
            q[i] = p[i] % 1000;
        }
        solve();
    }
}


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

using namespace std;

int main()
{
	string s;
	cin >> s;
	
	int L = 0, R = 0;
	bool cond1 = false, cond2 = false;
	
	for(int i = 0; i < s.size(); i++)
	{
		if(s[i] == 'A')
		{
			L = i;
			cond1 = true;
			break;
		}
	}
	for(int i = s.size()-1; i >= 0; i--)
	{
		if(s[i] == 'Z')
		{
			R = i;
			cond2 = true;
			break;
		}
	}
	
	if(cond1 && cond2)
		printf("%d\n", abs(R-L)+1);
	else
		printf("0\n");
	
	return 0;
}

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

int main(){
  string s;
  cin >> s;
  int cnt = 0;
  for(int i=0;i<s.size();i++){
    if(s.at(i)=='p')
      cnt++;
  }
  cout << s.size()/2-cnt << endl;
}

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


#define INF 1000000000000
int kaizyou(int n){
int ans=1;
  for(int i=1;i<=n;i++){
    ans*=i;
  }
  return ans;
}

signed main()
 {
  int n,m;
  cin>>n>>m;
  int a[n];
  rep(i,n){cin>>a[i];}
  vector<int>s(n+1);

  rep(i,n+1){
      if(i==0){s[i]=0;}
      else {s[i]=(s[i-1]+a[i-1])%m;}
  }
  sort(s.begin(),s.end());
  int ans=0,onaji=1;
  rep(i,n){
    if(s[i]==s[i+1]){
      onaji++;
    }
    else{
      ans+=((onaji-1)*onaji)/2;
      onaji=1;
    }
  }
  ans+=((onaji-1)*onaji)/2;
  cout<<ans;
 }


Measured memory_bytes: 1792
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        boolean[][] jdg = new boolean[h+1][w+1];
        for(int i = 0;i < h;i++){
            String str = sc.next();
            for(int j = 0;j < w;j++){
                if(str.charAt(j) == '#')
                jdg[i][j] = true;
                jdg[i][w] = jdg[i][w] || jdg[i][j];
                jdg[h][j] = jdg[h][j] || jdg[i][j];
            }
        }

        for(int i = 0;i < h;i++){
            if(jdg[i][w]){
                String str = "";
                for(int j = 0;j<w;j++){
                    if(jdg[h][j])
                    str += (jdg[i][j]?"#":".");
                }
                System.out.println(str);
            }
        }
    }
}

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

using namespace std;

int main() {
    int H,W; cin >> H >> W;
    vector<vector<char>> S(H+2, vector<char>(W+2, '#'));
    for(int i=1;i<=H;i++) {
        for(int j=1;j<=W;j++) {
            cin >> S[i][j];
        }
    }
    
    vector<vector<int>> count_row(H+2, vector<int>(W+2,0));
    vector<vector<int>> count_col(H+2, vector<int>(W+2,0));

    for(int j=1;j<=W;j++) {
        for(int i=1;i<=H;i++) {
            if(S[i][j] == '#') count_row[i][j] = 0;
            else if(S[i][j] == '.') count_row[i][j] = count_row[i-1][j] + 1;
        }
    }
    for(int j=1;j<=W;j++) {
        for(int i=H;i>=1;i--) {
            if(S[i][j] == '#') count_row[i][j] = 0;
            else if(S[i][j] == '.') count_row[i][j] = max(count_row[i+1][j], count_row[i][j]);
        }
    }

    for(int i=1;i<=H;i++) {
        for(int j=1;j<=W;j++) {
            if(S[i][j] == '#') count_col[i][j] = 0;
            else if(S[i][j] == '.') count_col[i][j] = count_col[i][j-1] + 1;
        }
    }
    for(int i=1;i<=H;i++) {
        for(int j=W;j>=1;j--) {
            if(S[i][j] == '#') count_col[i][j] = 0;
            else if(S[i][j] == '.') count_col[i][j] = max(count_col[i][j+1], count_col[i][j]);
        }
    }

    int ans = 0;
    for(int i=1;i<=H;i++) {
        for(int j=1;j<=W;j++) {
            if(S[i][j] == '#') continue;
            ans = max(ans, count_row[i][j] + count_col[i][j] - 1);
            // double count for (i,j) block. Substract 1
        }
    }

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


Measured memory_bytes: 35712
#include<iostream>
#include<string>
using namespace std;
string S, T; char U[11] = "0123456789"; int sum;
int main() {
	while (cin >> S) {
		S += ' ';
		for (int i = 0; i < S.size(); i++) {
			for (int j = 0; j < 10; j++) {
				if (U[j] == S[i]) {
					T += S[i]; goto E;
				}
			}
			if (T != "") { sum += stoi(T); }
			T = "";
		E:;
		}
	}
	cout << sum << endl;
}

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

int main(){
    string a;
    cin>>a;
    char b = a[2];
    char d = a[3];
    char e = a[4];
    char f = a[5];
    if(b==d&&e==f){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<int> l;
using ll = long long;
int n;
bool ok(int mid, int a, int b) {
    if (l[mid] < l[a] + l[b]) return true;
    else return false;
}
int main() {
    cin >> n;
    l.resize(n);
    for (int i = 0; i < n; i++) cin >> l[i];
    sort(l.begin(), l.end());
    l.push_back(1<<30);
    ll ans = 0;
    for (int a = 0; a < n - 2; a++) {
        for (int b = a + 1; b < n - 1; b++) {
            int bottom = b;
            int top = n;
            while (top - bottom > 1) {
                int mid = (top + bottom) / 2;
                if (ok(mid, a, b)) bottom = mid;
                else top = mid;
            }
            ans += bottom - b;
        }
    }
    cout << ans << endl;
    return 0;
}

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

namespace AtCoder
{
	// http://abc106.contest.atcoder.jp/tasks/abc106_a
	public class Abc106_a
	{
#if !Development
		public static void Main(string[] args)
		{
			Abc106_a.Solve(args);
		}
#endif

		public static void Solve(string[] args)
		{
			var line1 = ReadLineInt();
			var a = line1[0];
			var b = line1[1];

			var answer = a * b - a - b + 1;

			Console.WriteLine(answer);
		}

		public static List<string> ReadLineString() { return Console.ReadLine().Split(' ').ToList(); }
		public static List<int> ReadLineInt() { return Console.ReadLine().Split(' ').Select(str => int.Parse(str)).ToList(); }
		public static int ReadLineIntOne() { return Console.ReadLine().Split(' ').Select(str => int.Parse(str)).First(); }
		public static List<int> MultiReadLineInt(int lineNum) { return Enumerable.Range(0, lineNum).Select(_ => ReadLineIntOne()).ToList(); }
	}
}

Measured memory_bytes: 13268