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

using namespace std;

const int MAX_N = 100000;

int N;
int happy[MAX_N+1][3];
int a[MAX_N+1], b[MAX_N+1], c[MAX_N+1];


void solve() {
    for (int i = 1; i < N + 1; i++) {
        happy[i][0] = a[i] + max(happy[i-1][1], happy[i-1][2]);
        happy[i][1] = b[i] + max(happy[i-1][0], happy[i-1][2]);
        happy[i][2] = c[i] + max(happy[i-1][0], happy[i-1][1]);
    }
    cout << max({happy[N][0], happy[N][1], happy[N][2]}) << endl;
}

int main() {
    cin >> N;
    for (int i = 1; i <= N; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }
    solve();
}

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

typedef long long				ll;
typedef unsigned long long		ull;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	ll n, m;
	cin >> n >> m;
	cout << (n == m? "Yes": "No") << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int i,n,x=0;
	int a[100001];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(i=0;i<n;i++){
		if(a[i]%2!=0){
			x++;
		}
	}
	if(x%2==0){
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 512
M=10**9+7;B,W=map(int,input().split());F=[1];I=[1];p=q=0;C=lambda n,k:F[n]*pow(F[k]*F[n-k],M-2,M)if n>=k else 0
for i in range(1,B+W+1):F+=[F[-1]*i%M];I+=[I[-1]+I[-1]%2*M>>1];print((1-p+q)*I[1]%M);p+=C(i-1,B-1)*I[i];q+=C(i-1,W-1)*I[i]

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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

string S;
signed main() {
  cin>>S;
  if(S.length()==2)cout<<S<<endl;
  else cout<<S[2]<<S[1]<<S[0]<<endl;
}


Measured memory_bytes: 256
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <functional>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define	MIN_QWORD				((QWORD)0x0000000000000000)
#define	MAX_SQWORD				((SQWORD)0x7FFFFFFFFFFFFFFF)
#define	MIN_SQWORD				((SQWORD)0x8000000000000000)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long			DWORD;
typedef unsigned long long int	QWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
/* 最大公約数 */
QWORD gcd(QWORD a, QWORD b) 
{
	if (b == 0) return a;
	return gcd(b, a % b);
}

/* 最小公倍数 */
QWORD lcm(QWORD a, QWORD b) 
{
	QWORD gcdRes = gcd(a, b);
	return (a * (b / gcdRes));
}

// メイン
int main()
{
	// 入力
	int N;
	cin >> N;
	vector<QWORD> T(N);
	REP(i, N) {
		cin >> T[i];
	}

	// 最小公倍数
	QWORD ans = T[0];
	REPN(i, 1, N) {
		ans = lcm(ans, T[i]);
	}

	// 結果
	cout << ans << endl;
	return 0;
}


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


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

    string N;
    cin >> N;

    int x=N.size();
    int sum=0;
    int ans=0;
    int K=N.at(0)-'0';
    rep(i,x){
        sum+=N.at(i)-'0';
    }
    ans=max(sum,K-1+(x-1)*9);

    cout << ans << endl;

}

Measured memory_bytes: 256
N = int(input())

ans = 0
top_b = 0
last_a = 0
top_b_and_last_a = 0

for _ in range(N):
    s = input()
    ans += s.count("AB")
    if s[0] == "B" and s[-1] == "A":
        top_b_and_last_a += 1
    elif s[0] == "B":
        top_b += 1
    elif s[-1] == "A":
        last_a += 1

ans += max(0, top_b_and_last_a - 1)
if top_b_and_last_a and top_b:
    top_b -= 1
    ans += 1
if top_b_and_last_a and last_a:
    last_a -= 1
    ans += 1
ans += min(top_b, last_a)

print(ans)

Measured memory_bytes: 3064
# https://juppy.hatenablog.com/entry/2019/05/02/%E8%9F%BB%E6%9C%AC_python_%E3%82%BB%E3%82%B0%E3%83%A1%E3%83%B3%E3%83%88%E6%9C%A8_%E7%AB%B6%E6%8A%80%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0_Atcoder

def main():
    import sys
    from fractions import gcd
    input = sys.stdin.readline

    def init(init_val):
        #set_val
        for i in range(n):
            seg[i+num-1]=init_val[i]    
        #built
        for i in range(num-2,-1,-1) :
            seg[i]=gcd(seg[2*i+1],seg[2*i+2]) 
        
    def update(k,x):
        k += num-1
        seg[k] = x
        while k:
            k = (k-1)//2
            seg[k] = gcd(seg[k*2+1],seg[k*2+2])
        
    def query(p,q):
        if q<=p:
            return ide_ele
        p += num-1
        q += num-2
        res=ide_ele
        while q-p>1:
            if p&1 == 0:
                res = gcd(res,seg[p])
            if q&1 == 1:
                res = gcd(res,seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = gcd(res,seg[p])
        else:
            res = gcd(gcd(res,seg[p]),seg[q])
        return res



    n = int(input())
    a = tuple(map(int,input().split()))

    #####単位元######
    ide_ele = 0

    #num:n以上の最小の2のべき乗
    num =2**(n-1).bit_length()
    seg=[ide_ele]*(2*num)
    init(a)

    ans = 0
    # i番目を書き換える -> 考慮しない
    for i in range(n):
        ans = max(ans,gcd(query(0,i),query(i+1,n)))
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 16264
#include <iostream>

using namespace std;

#define MAX 100005
#define NIL -1


//采用左子右兄弟表示法
struct Node {
    int p, l, r;
};

Node T[MAX];

int n, D[MAX];

void printNode(int u) {
    int i, c;
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "depth = " << D[u] << ", ";

    if (T[u].p == NIL) cout << "root, ";
    else if (T[u].l == NIL) cout << "leaf, ";
    else cout << "internal node, ";

    cout << "[";
    for (i = 0, c = T[u].l; c != NIL; i++, c = T[c].r) {
        if (i) cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
}

void rec(int u, int p) {
    D[u] = p;
    if (T[u].r != NIL) rec(T[u].r, p);
    if (T[u].l != NIL) rec(T[u].l, p + 1);
}

int main() {
    int d, v, c, l, r;

    cin >> n;
    for (int i = 0; i < n; i++) {
        T[i].p = T[i].l = T[i].r = NIL;
    }

    for (int i = 0; i < n; i++) {
        cin >> v >> d;
        for (int j = 0; j < d; j++) {
            cin >> c;
            if (j == 0) {
                T[v].l = c;
            } else T[l].r = c;
            l = c;
            T[c].p = v;
        }
    }
    for (int i = 0; i < n; i++) {
        if (T[i].p == NIL) r = i;
    }
    rec(r, 0);
    for (int i = 0; i < n; i++) {
        printNode(i);
    }
    return 0;
}


Measured memory_bytes: 7748
import java.io.*;
import java.math.*;
import java.util.*;
 
public class Main {
	static final long MOD = 1000000007L;
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter pw = new PrintWriter(System.out);
		
		int N = sc.ni();
		int ans = 1;
		int num = 7%N;
		while (ans < 2000000) {
			if (num==0)break;
			num = (10*num+7)%N;
			ans++;
		}
		if (ans==2000000)
			pw.println(-1);
		else
			pw.println(ans);
		pw.close();
	}
	
    static class FastScanner { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastScanner() { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() { 
            while (st == null || !st.hasMoreElements()) { 
                try { 
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        }
        
        int ni() { 
            return Integer.parseInt(next()); 
        }
  
        long nl() { 
            return Long.parseLong(next()); 
        } 
  
        double nd() { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() {
            String str = ""; 
            try { 
                str = br.readLine(); 
            } catch (IOException e) {
                e.printStackTrace(); 
            } 
            return str;
        }
    }
}

Measured memory_bytes: 32780
#include<vector>
#include<string>
#include<iostream>
using namespace std;
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);

int main(){
    fast;
    long long a,b,c,k;
    cin >> a >> b >>c >> k;
    if(k<=a) cout << k;
    else if(k<=(a+b)) cout << a;
    else cout << (2*a + b - k);
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
// dp[i][j] == max value put in knapsack upto i th element with weight j;
int main(){
  int n,w;
  cin>>n>>w;
  std::vector<int> wt(n+1),val(n+1);
  for(int i=1;i<=n;i++)
    cin>>wt[i]>>val[i];
  ll dp[n+1][w+1];
  for(int i=0;i<=n;i++)
  for(int j=0;j<=w;j++){
    if(i==0 || j==0)  dp[i][j] = 0;
    else if(wt[i] > j)  dp[i][j] = dp[i-1][j];
    else dp[i][j] = max(dp[i-1][j],val[i]+dp[i-1][j-wt[i]]);
  }
  cout<<dp[n][w]<<endl;
}


Measured memory_bytes: 79104
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <string.h>

using namespace std;

int main()
{
int a,s;
cin>>a>>s;
int u=a;
int b=0;
int m=1;
if(s==1){
    cout<<0;
    goto here;
}
if(a<s){
for(int l=0;a<s;l++){
            a=(a+u)-1;
            b++;
}
b++;
cout<<b;
goto here;
}

       if(a>=s){
            cout<<1;
        }

here:


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FASTIO ios_base::sync_with_stdio(false);cout.tie(NULL);cout.tie(NULL);
#define fr(a,b) for(long long i=a;i<b;i++)
#define vi vector<ll>
const ll MAX=1e4;
const ll mod=1e9+7;
const ll INF=1e18+12;
set< pair<ll,ll> >ss;
ll dp[MAX][MAX];

                                    //SAMEER KUMAR SINGH//
// ==========================================================================================================//

ll fun(ll a[],ll i,ll j){
   if(i>j)
   return 0;
   if(dp[i][j]!=0)
    return(dp[i][j]);
   ll f1=a[i]+min(fun(a,i+2,j),fun(a,i+1,j-1));
   ll f2=a[j]+min(fun(a,i+1,j-1),fun(a,i,j-2));
   dp[i][j]=max(f1,f2);
   return(dp[i][j]);
}
int main(){
   FASTIO;
   ll tt=1;
   //cin>>tt;

   while(tt--){
     ll n;cin>>n;

     ll a[n];
     ll sum=0;
     fr(0,n){
     cin>>a[i];
     sum+=a[i];
     }

     //cout<<dp[3][3]<<" "<<dp[4][5]<<"\n";
     cout<<2*fun(a,0,n-1)-sum;
   }
}


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

const int INF = 1<<27;
int G[10][10];

int main() {
  int n;
  while(cin >> n && n) {
    fill(G[0],G[10],INF);
    for(int i = 0; i < 10; ++i) G[i][i] = 0;

    for(int i = 0; i < n; ++i) {
      int a, b;
      cin >> a >> b;
      cin >> G[a][b];
      G[b][a] = G[a][b];
    }
    for(int k = 0; k < 10; ++k) {
      for(int i = 0; i < 10; ++i) {
	for(int j = 0; j < 10; ++j) {
	  if(G[i][k] == INF || G[k][j] == INF) continue;
	  G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
	}
      }
    }

    int mini, minCost;
    minCost = INF;
    for(int i = 0; i < 10; ++i) {
      int sum = 0;
      for(int j = 0; j < 10; ++j) {
	if(G[i][j] == INF) continue;
	sum += G[i][j];
      }
      if(sum == 0) continue;
      if(sum < minCost) {
	mini = i;
	minCost = sum;
      }
    }
    cout << mini << " " << minCost << endl;
  }
  return 0;
}

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

int main(){
  int N;
  cin>>N;
  int M;
  cin>>M;
  int b[N+1];
  int temp;
  //b[i]　こわれているかどうか　1/0
  
  for (int i=0;i<N+1;i++){
    b[i]=1;
  }
  
  for (int i=0;i<M;i++){
    cin>>temp;
    b[temp]=0;
  }
  
  int dp[N+1];
  for (int i=0;i<0;i++){
    dp[i]=0;
  }
  
  dp[0]=1;
  if(b[1]==1){
    dp[1]=1;
  }
  if(b[1]==0){
    dp[1]=0;
  }
  
  for(int i=2;i<N+1;i++){
    if(b[i]==0){
      dp[i]=0;
    }
    if(b[i]==1){
      dp[i]=(dp[i-1]+dp[i-2])%1000000007;
      //cout<<i<<" "<<dp[i]<<endl;
    }
  }
  
  cout<<dp[N]<<endl;
  return 0;
}

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

void solve(){
	int n;
	cin >> n;
	vector<long long> a(n);
	for(auto &it : a) cin >> it;
	long long x = 0;
	for(auto i : a) x ^= i;
	for(auto i : a) cout << (x ^ i) << ' ';
	cout << '\n';
}

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

Measured memory_bytes: 4776
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define ll long long
#define rn(i,n) for(int i=1;i<=n;i++)

int main(){
  ll n,y;
  cin>>n>>y;

  for(ll i=0;i<=n;i++){
    for(ll j=0;j<=n-i;j++){
      if(10000*i+5000*j+1000*(n-i-j)==y){
        cout<<i<<" "<<j<<" "<<(n-i-j)<<endl;
        return 0;
      }
    }
  }
  cout<<-1<<" "<<-1<<" "<<-1<<endl;
return 0;}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string S, T;
    cin >> S >> T;
    
    int lS, lT;
    // 文字列の長さ
    lS = S.length();
    lT = T.length();
    // 候補文字列
    vector<string> ans;
    string tmp;
    int num = 0;
    bool flag;
    for(int i=0;i<=lS-lT;i++){
        flag = 0;
        for(int j=0;j<lT;j++){
            if(S[i+j] != T[j] && S[i+j] != '?')
                flag = 1;
        }
        if(flag == 0){
            num++;
            for(int j=0;j<lS;j++){
                if(i<=j && j<i+lT){
                    tmp.push_back(T[j-i]);
                }else{
                    if(S[j] == '?')
                        tmp.push_back('a');
                    else
                        tmp.push_back(S[j]);
                }
            }
            ans.push_back(tmp);
            tmp.erase();
        }
    }
    if(num == 0){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    // 昇順ソート
    sort(ans.begin(), ans.end());
    
    cout << ans[0] << endl;
    return 0;
}

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

int main(){

    int x, y;
    cin >> x >> y;
    while(!(x == 0 && y == 0)){
        if(x<y) cout << x << " " << y << endl;
        else cout << y <<" "<< x << endl;
        cin >> x >> y;
    }

    return 0;

}


Measured memory_bytes: 3040
#include<bits/stdc++.h>
#define INFTY 10000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const int MOD=1000000007;
const int di[4] = {-1,0,1,0};
const int dj[4] = {0,-1,0,1};
const int INF = 1e9;
const int A = 1000005;
int main(){
    string s,t={};cin>>s;
    int sz = s.size();
    int i = sz-1;
    while(i>=4)
    {
        //cout<<i<<t<<endl;
        if(i>5&&s.substr(i-6,7)=="dreamer"){t = "dreamer"+t;i-=7;}
        else if(i>4&&s.substr(i-5,6)=="eraser"){t = "eraser"+t;i-=6;}
        else if(s.substr(i-4,5)=="erase"){t = "erase"+t;i-=5;}
        else if(s.substr(i-4,5)=="dream"){t = "dream"+t;i-=5;}
        else{
            cout<<"NO"<<endl;
            return 0;
        }
            
    }
    
    if(s==t)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 3832
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sysin = new Scanner(System.in);
		final String s = sysin.next();
		sysin.close();

		Map<Character, Integer> chars = new HashMap<>();
		for (char c : s.toCharArray()) {
			int i = chars.containsKey(c) ? chars.get(c) : 0;
			chars.put(c, i + 1);
		}


		System.out.println(
			chars.entrySet().stream()
			.mapToInt(Entry<Character, Integer>::getValue)
			.allMatch(i -> i == 2) ? "Yes" : "No"
		);
	}
}


Measured memory_bytes: 28500
//============================================================================
// Name        : GreatestCommonDivisor.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
	int num1, num2, remainder;
	cin >> num1 >> num2;

	while(num1!=0 and num2!=0){
		if(num1>=num2){
			num1 = num1%num2;
		}else{
			num2 = num2%num1;
		}
	}

	if(num1!=0){
		cout << num1 << "\n";
	}else{
		cout << num2 << "\n";
	}

	return 0;
}



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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	string s;
	cin >> s;
	int ans[28], m[28];
	REP(i, 0, 28) ans[i] = m[i] = -1;
	REP(i, 0, (int)s.size()){
		int a = s[i] - 'a';
		ans[a] = max(i - m[a], ans[a]);
		m[a] = i;
	}
	int ss = s.size();
	REP(i, 0, 28){ 
		if(ans[i] != -1) ans[i] = max(ans[i], ss-m[i]);
	}
	
	int mans = INT_MAX;
	REP(i, 0, 28){
		if(ans[i] != -1) mans = min(mans, ans[i]);
	}
	
	cout << mans-1;
	
		
		

		
		
				
	

}


Measured memory_bytes: 256
def dist(c1, c2):
    return ((c1[0]-c2[0])**2+(c1[1]-c2[1])**2)**.5


def kruskal(edges, size):
    uf = UnionFind(size)
    edges = sorted(edges, key=lambda e: e[2])[::-1]
    ret = 0
    for u, v, weight in edges:
        if not uf.same(u, v):
            uf.unite(u, v)
            ret += weight
    return ret


class UnionFind:
    def __init__(self, size):
        self.parent = list(range(size))
        self.rank = [0] * size

    def find(self, x):
        if self.parent[x] != x:
            self.parent[x] = self.find(self.parent[x])
        return self.parent[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)


N, M = map(int, input().split())
coords = [tuple(map(int, input().split())) for i in range(N)]
edges = []
for i in range(M):
    p, q = map(lambda x: int(x) - 1, input().split())
    edges.append((p, q, dist(coords[p], coords[q])))
print(sum(e[2] for e in edges) - kruskal(edges, N))



Measured memory_bytes: 12660
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static MyUtil;

class MyUtil
{
    public static long[] ReadLongArray()
    {
        return ReadLine().Split().Select(x => long.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
        int n = int.Parse(ReadLine());
        var a = ReadLongArray();

        long ans = 0;
        long sum = 0;
        for (int i = 0, j = 0; i < n; i++)
        {
            while (j < n && (sum + a[j]) == (sum ^ a[j]))
            {
                sum += a[j];
                j++;
            }
            ans += j - i;
            sum -= a[i];
        }

        WriteLine(ans);
    }
}


Measured memory_bytes: 33244
def solve(N, Y):
    for x in range(N+1):
        for y in range(N+1):
            z = N - x - y
            if z < 0:
                continue
            elif 10000 * x + 5000 * y + 1000 * z == Y:
                return x, y, z
    return -1, -1, -1

N, Y = list(map(int, input().split()))
x, y, z = solve(N, Y)
print('{} {} {}'.format(x, y, z))


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <utility>
#include <functional>
#include <map>

using namespace std;

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

  int a, b, c;
  cin >> a >> b >> c;

  if (b / a > c) {
    cout << c << endl;
  }
  else {
    cout << b / a << endl;
  }
}

Measured memory_bytes: 256
function Main(input) {
	var str = input;
	var ans = "";
	var str = str.split("\n");
	var num1 = str[0].split(" ");
	var num2 = str[1].split(" ");
	var num3 = str[2].split(" ");
	var a = Number(num1[0]);	
	var v = Number(num1[1]);
	var b = Number(num2[0]);	
	var w = Number(num2[1]);	
	var t = Number(num3[0]);	
 	var k = Math.abs(b-a);
 	if(v > w){//追いつく
 		var m = v-w;	
 			if(t >= k/m){
 				ans = "YES";
		 	}else{
		 		ans = "NO";
		 	}
 		}else{//追いつかない
 			ans = "NO";
		} 		
	console.log(ans);
	}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main() {
  int n; string s; cin >> n >> s;
  
  int  x = 0, y = 0;
  for(int i=0; i<n; i++){
    if(s[i] == 'I') x++;
    else x--;
    y = max(y, x);
  }
  
  cout << y << endl;
  
    return 0;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(string s) {
    int ans = 0;
    int len = 0;
    foreach (c; s) {
        if ("ACGT".canFind(c)) len++;
        else len = 0;
        ans = max(ans, len);
    }
    return ans;
}

void main() {
    string s = read!string;
    writeln(calc(s));
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Count(vec, x) count(vec.begin(), vec.end(), x)
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define PI acos(-1)

int main() {
    ll N;
    cin >> N;
    vector<pair<ll, ll>> primes;
    for (int i = 2; i <= sqrt(N); i++) {
        if (N % i) continue;
        int cnt = 0;
        while (N % i == 0) {
            cnt += 1;
            N /= i;
        }
        primes.push_back(make_pair(i, cnt));
    }
    if (N != 1) primes.push_back(make_pair(N, 1));
    // Rep(i, primes.size()) cout << primes[i].first << " " << primes[i].second << endl;
    int ans = 0;
    Rep(i, primes.size()) {
        int p = 1;
        while (primes[i].second >= p) {
            primes[i].second -= p;
            ans += 1;
            p += 1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3716
#include<bits/stdc++.h>
#define mo 1000000007
using namespace std;
int f[23333333];
int d,ans;
int power(int x,int y){
	int s=1;
	for (;y;y/=2,x=1ll*x*x%mo)
		if (y&1) s=1ll*s*x%mo;
	return s;
}
void work(int v){
	if (v<8) return;
	int tmp=(power(10,v)+mo-power(10,v-1))%mo;
	tmp=(tmp+mo-d/v+1)%mo;
	ans=(ans+tmp)%mo;
}
int main(){
	scanf("%d",&d);
	int rrange=23333331;
	for (int i=1;i<=rrange;i++)
		f[i]=f[i/10]+1;
	for (int i=1;i<=rrange;i++)
		f[i]+=f[i-1];
	for (int i=1,r=0;i<=rrange;i++){
		for (;f[i]-f[r]>d;r++);
		if (r>=9999999) break;
		ans+=(f[i]-f[r]==d);
	}
	for (int i=1;i*i<=d;i++)
		if (d%i==0){
			work(i);
			if (i*i!=d) work(d/i);
		}
	for (int i=8;i<=d;i++){
		int tmp=d%i;
		tmp=(tmp==0?i+1:tmp);
		if (d/i<=tmp) continue;
		int now=d/i-tmp;
		ans=(ans+(now-1)/(i+1)+1)%mo; 
	}
	printf("%d",ans);
}

Measured memory_bytes: 91392
# coding:utf-8

import sys


input = sys.stdin.readline
INF = float('inf')
MOD = 10 ** 9 + 7


def inpl(): return list(map(int, input().split()))


L, N = inpl()
X = [int(input()) for _ in range(N)]

if N == 1:
    print(max(X[0], L - X[0]))
    exit()

# 累積和
Xcc = [0]  # 反時計回り
Xc = [0]  # 時計回り
for i in range(N):
    Xcc.append(Xcc[-1] + X[i] * 2)
    Xc.append(Xc[-1] + (L - X[-(1 + i)]) * 2)

# print(Xcc)
# print(Xc)

ans = 0
if N % 2:
    for i in range(1, N):
        # 反時計回り
        t_ccw = (N + i) // 2
        t_cw = N - t_ccw
        ans_ccw = Xcc[t_ccw] - Xcc[i - 1] + Xc[t_cw]
        ans_ccw -= X[t_ccw - 1] if i % 2 else (L - X[-t_cw])

        # 時計回り
        t_cw = (N + i) // 2
        t_ccw = N - t_cw
        ans_cw = Xc[t_cw] - Xc[i - 1] + Xcc[t_ccw]
        ans_cw -= (L - X[-t_cw]) if i % 2 else X[t_ccw - 1]

        ans = max(ans, ans_ccw, ans_cw)


else:
    for i in range(1, N):
        # 反時計回り
        t_ccw = (N + i) // 2
        t_cw = N - t_ccw
        ans_ccw = Xcc[t_ccw] - Xcc[i - 1] + Xc[t_cw]
        ans_ccw -= (L - X[-t_cw]) if i % 2 else X[t_ccw - 1]

        # 時計回り
        t_cw = (N + i) // 2
        t_ccw = N - t_cw
        ans_cw = Xc[t_cw] - Xc[i - 1] + Xcc[t_ccw]
        ans_cw -= X[t_ccw - 1] if i % 2 else (L - X[-t_cw])

        ans = max(ans, ans_ccw, ans_cw)

print(ans)


Measured memory_bytes: 30068
/************************************************************
	> File Name: a.cpp
	> Author: TSwiftie
	> Mail: 2224273204@qq.com 
	> Created Time: Sat 28 Dec 2019 08:02:18 PM CST
************************************************************/

#pragma GCC optimize(2)
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <iomanip>
//#include <unordered_map>
#define lowbit(x) (x&-x)
#define lc (o<<1)
#define rc (o<<1|1)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e5+5;
const int MAXM = 2e5+5;
const int MOD = 1e9+7;
const int dir[4][2] = {1,0,-1,0,0,1,0,-1};
const double PI = acos(-1.0);
const double EXP = 1e-8;
int main(void){
	ll n, a, b;
	cin >> n >> a >> b;
	if((b-a)%2==0)
		cout << (b-a)/2 << endl;
	else
		cout << min((n-b)+(b-a)/2+(b-a)%2,(a-1)+(b-a)/2+(b-a)%2) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
int main() {
  string s;
  cin>>s;
  int n=s.size();
  bool use[26][26];
  for(int i=0;i<26;i++){
    for(int j=0;j<26;j++){
      use[i][j]=true;
    }
  }
  vector<bool>ok(26,true);
  for(int i=0;i<n;i++){
    ok[s[i]-'a']=false;
    for(int j=0;j<26;j++){
      use[i][j]=ok[j];
    }
  }
  string t=s;
  if(t.size()<26){
    char y;
    bool r=false;
    for(int j=0;j<26;j++){
      if(use[n-1][j]){y=(char)(j+'a');r=true;break;}
    }
    if(r){t.push_back(y);cout<<t<<endl;return 0;}
  }
  
  for(int i=n-1;i>=0;i--){
    for(int j=s[i]-'a';j<26;j++){
      if(use[i][j]){t[i]=(char)(j+'a');cout<<t.substr(0,i+1)<<endl;return 0;}
    }
  }
  cout<<-1<<endl;
  return 0;
}

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using static AtCoder.Io;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var n = ReadNextInt();
            var m = ReadNextInt();
            var counts = new int[n];
            for (int i = 0; i < m * 2; i++)
            {
                counts[ReadNextInt() - 1]++;
            }

            Console.WriteLine(string.Join("\n", counts));
        }
    }

    public static class Io
    {
        public static string ReadString() => Console.ReadLine();
        public static string[] ReadStringArray() => ReadString().Split(' ');
        public static int ReadInt() => int.Parse(ReadString());
        public static long ReadLong() => long.Parse(ReadString());
        public static BigInteger ReadBigInteger() => BigInteger.Parse(ReadString());
        public static int[] ReadIntArray() => ReadStringArray().ParseInt().ToArray();
        public static long[] ReadLongArray() => ReadStringArray().ParseLong().ToArray();
        public static BigInteger[] ReadBigIntegerArray() => ReadStringArray().ParseBigInteger().ToArray();
        public static IEnumerable<int> ParseInt(this IEnumerable<string> source) => source.Select(int.Parse);
        public static IEnumerable<long> ParseLong(this IEnumerable<string> source) => source.Select(long.Parse);
        public static IEnumerable<BigInteger> ParseBigInteger(this IEnumerable<string> source) => source.Select(BigInteger.Parse);

        public static string[] Buffer = new string[] { };
        public static int Index;
        public static string ReadStringNext()
        {
            if (Buffer.Length == 0 || Buffer.Length <= Index)
            {
                Buffer = ReadStringArray();
                Index = 0;
            }
            return Buffer[Index++];
        }
        public static int ReadNextInt() => int.Parse(ReadStringNext());
        public static long ReadNextLong() => long.Parse(ReadStringNext());
        public static BigInteger ReadNextBigInteger() => BigInteger.Parse(ReadStringNext());
    }
}


Measured memory_bytes: 13268
#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 <climits>

using namespace std;
typedef long long unsigned int ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

// #define amari(x) ((x) % 1000000007)
#define amari(x) ((x) % 998244353)

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<int>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)

#define rep(i,n) for(long i=0; i<(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

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

long gcd( long a, long b )
{
    if (a < b) {
      return gcd(b, a);
    } else if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

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

  long r, g, b, n;
  cin >> r >> g >> b >> n;

  long cnt = 0;
  rep(i, n+1) {
    rep(j, n+1) {
      if ((n-i*r-j*g)%b == 0 && (n-i*r-j*g) >= 0) cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;
const int mod = 1e9+7;

int main() {
    string s; cin >> s;
    int n = s.size();
    ll ans = 0;
    rep(bit,1<<(n-1)) {
        int i = bit + (1<<(n-1));
        int ct = 1; 
        vint tmp;
        rep(j,n) {
            if (i>>j&1) {
                tmp.push_back(ct);
                ct = 1;
            }
            else ct++;
        }
        ll sum = 0;
        int id = 0;
        rep(j,tmp.size()) {
            string s_tmp = s.substr(id,tmp[j]);
            id += tmp[j];
            sum += stoll(s_tmp);
        }
        ans += sum;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    cycle = []
    visited = [False for _ in range(n)]
    now = 0

    while True:
        cycle.append(now)
        visited[now] = True
        now = a[now]-1
        if (visited[now]):
            break


    t = len(cycle)
    cstart = 0
    for i in range(t):
        if cycle[i] == now:
            cstart = i
            break

    c = t - cstart

    if k < cstart:
        print(cycle[k]+1)
    else:
        print(cycle[cstart + (k - cstart) % c]+1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 32376
def dfs(i,r,g,b):
    global ans
    if i == k:
        if r < g and g < b:
            ans += 1
        return
    dfs(i+1,r*2,g,b)
    dfs(i+1,r,g*2,b)
    dfs(i+1,r,g,b*2)

a,b,c = map(int,input().split())
k = int(input())
ans = 0
dfs(0,a,b,c)
if ans > 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 67332
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int height = sc.nextInt();
    int width = sc.nextInt();
    String[] square = new String[height];
    char[][] grid = new char[height + 2][width + 2];
    for (int i = 0; i < height; i++) {
      square[i] = sc.next();
     }
    for (int i = 0; i < height + 2; i++) {
      for (int j = 0; j < width + 2; j++) {
         if (i == 0 || j == 0 || i == (height + 1) ||  j == (width + 1)) {
           grid[i][j] = '.';
         } else {
           char[] c = square[i -1].toCharArray();
           grid[i][j] = c[j - 1];
         }

      }
    }
    boolean flag = true;
    for (int i = 1; i < height + 1; i++) {
      for (int j = 1; j < width + 1; j++ ) {
        if (grid[i][j] == '#' && grid[i - 1][j] == '.' && grid[i + 1][j] == '.' && 
                                                                         grid[i][j - 1] == '.' && grid[i][j + 1] == '.') {
          flag = false;
          break;
        }

      }
      if (!flag) break;
    }
    if (flag) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }

  

  }
}

Measured memory_bytes: 21844
# -*- coding: utf-8 -*-

def main(H,W,A):
    print("#"*(W+2))
    for i in range(H):
        print("#"+A[i]+"#")
    print("#"*(W+2))
    
if __name__ == '__main__':
    H, W = map(int, input().split())
    A = [input() for i in range(H)]
    
    main(H,W,A)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;    
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<template<class...> class ContT, class ValueT, size_t Dim>
struct vec_type
{
    using type = ContT<typename vec_type<ContT, ValueT, Dim-1>::type>;
};

template<template<class...> class ContT, class ValueT>
struct vec_type<ContT, ValueT, 0>
{
    using type = ValueT;
};

template<class ValueT, size_t Dim = 1>
using vec_t = typename vec_type<std::vector, ValueT, Dim>::type;


template<class ValueT, size_t Dim, class = typename std::enable_if<Dim == 0>::type>
auto make_vec(ValueT value = ValueT()) -> ValueT
{
    return value;
}

template<class ValueT, size_t Dim, class... Rest>
auto make_vec(size_t size0, Rest... rest)
{
    auto vec = make_vec<ValueT, Dim-1>(rest...);
    return std::vector(size0, vec);
}

int diffabs(int l, int r)
{
    if (l < r) return r-l;
    else return l-r;    
}


///////////////////////////////////////////////////

int main()
{
    int A, B;
    cin >> A >> B;
    cout << (A * B) << endl;
}

Measured memory_bytes: 3636
from collections import deque
h,w=map(int,input().split())
S=[input() for _ in range(h)]
ans=0
inf=float("inf")
for i in range(h):
   for j in range(w):
      if S[i][j]=="#":
         continue
      else:
         DP=[[inf for _ in range(w)]for _ in range(h)]
         DP[i][j]=0
         que=deque([(i,j)])
         while que:
            si,sj=que.popleft()
            for ni,nj in [(si+1,sj),(si-1,sj),(si,sj+1),(si,sj-1)]:
               if 0<=ni<h and 0<=nj<w and S[ni][nj]!="#":
                   if DP[ni][nj]>DP[si][sj]+1:
                      DP[ni][nj]=DP[si][sj]+1
                      ans=max(ans,DP[si][sj]+1)
                      que.append((ni,nj))
print(ans)

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

int main() {
  int H, W;
  cin >> H >> W;
  string S[H];
  int a[H+2][W+2]={};
  for (int i=0; i<H; i++) {
    cin >> S[i];
    for (int j=0; j<W; j++)
      if (S[i][j] == '#')
        for (int k=0; k<3; k++)
          for (int l=0; l<3; l++)
            a[i+k][j+l]++;
  }
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) 
      if (S[i][j] == '#') cout << '#';
      else cout << a[i+1][j+1];
    cout << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool isPalindrome(int x){
	string sx = to_string(x);
	int i =0, j = (int) sx.size() - 1;
	while (i<j){
		if (sx[i++] != sx[j--]) return false;

	}
	return true;
}

int main(){
	int a,b, count = 0;
	cin >> a >> b;
	for (; a<=b;a++){
		if (isPalindrome(a)) count++;
	}
	cout << count;
}


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

const int MAX_N = 1120;
const int MAX_K = 14;

// is_p[i] := i が素数のとき true
bool is_p[MAX_N+1] = {false,false};
int dp[MAX_K+1][MAX_N+1] = {0};

// エラトステネスのふるい
void sieve(){
	for(int i = 2 ; i <= MAX_N ; i++ )
		is_p[i] = true;
	for(int i = 2 ; i*i <= MAX_N ; i++ ){
		if( is_p[i] ){
			for(int j = i+i ; j <= MAX_N ; j += i ){
				is_p[j] = false;
			}
		}
	}
}

int main(){
	sieve();
	dp[0][0] = 1;
	for(int i=2 ; i <= MAX_N ; i++ ){
		if( is_p[i] ){
			for(int j = MAX_K; j > 0; j-- ){
				for(int k = i ; k <= MAX_N ; k++ ){
					dp[j][k] += dp[j-1][k-i];
				}
			}
		}
	}
	int n, k;
	while( cin >> n >> k , n || k ){
		cout << dp[k][n] << endl;
	}
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N;
  cin >> N;
  cout << (N<1000?"ABC":"ABD") << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 100010;
const LL mod = 1e9+7;
typedef long long LL;
LL H,W,A,B;
LL fac[MAXN*2],inv[MAXN*2];

LL modPow(LL a, LL b)
{
    LL ret = 1;
    while(b)
    {
        if(b&1) ret = ret*a%mod;
        a = a*a%mod;
        b >>= 1;
    }
    return ret;
}

void init()
{
    fac[0] = 1;
    inv[0] = 1;
    for(LL i = 1; i <= H+W; ++i)
        fac[i] = fac[i-1]*i%mod;
    inv[H+W] = modPow(fac[H+W],mod-2);
    for(LL i = H+W-1; i >= 1; --i)
        inv[i] = (inv[i+1]*(i+1))%mod;
}

LL C(LL n, LL m)
{
    LL ret = (fac[n]*inv[m]%mod)*inv[n-m]%mod;
    return ret;
}

int main()
{
    cin >> H >> W >> A >> B;
    init();
    LL res = C(H+W-2,H-1);
    LL minu = 0;
    for(int i = 1; i <= B; ++i)
        minu = (minu + C(H-A+i-2, H-A-1)*C(A+W-i+1-2,A-1)%mod)%mod;
    cout << ((res-minu)%mod+mod)%mod << endl;
    return 0;
}



Measured memory_bytes: 3328
S = input()
n = len(S)
li = list(S)

ans = 0
lians = []
for i in range(n):
  if li[i] == "A" or li[i] =="G" or li[i] =="C" or li[i] =="T":
    ans += 1
  else:
    lians.append(ans)
    ans = 0
lians.append(ans)
print(max(lians))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin>>N>>M;
  if(2<=abs(N-M))
    cout<<0<<endl;
  else{
  if(N!=M){
   long long ans=1;
    for(long long i=1;i<=N;i++)
    ans=(i*ans)%1000000007;
  for(long long i=1;i<=M;i++)
    ans=(i*ans)%1000000007;
    cout<<ans<<endl;
  }else{
    long long ans=2;
    for(long long i=1;i<=N;i++)
    ans=(i*((i*ans)%1000000007))%1000000007;
     cout<<ans<<endl;
  }
  
   }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long MX=1e18;
const long long MD=1e9+7;
const int N=1e5+5;
long long n,k,a[100005],dp[100005];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        dp[i]=1e17;
    }
    dp[0]=0;
    for(int i=1;i<n;i++)
    {
        for(int j=i;j>=max((long long)0,(i-k));j--)
        {
            dp[i]=min(dp[j]+abs(a[j]-a[i]),dp[i]);
        }
    }
    cout<<dp[n-1];
}


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

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

	if (a >= 13) cout << b << endl;
	else if (a >= 6 && a <= 12) cout << b / 2 << endl;
	else cout << 0 << endl;

	return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    int lmax=1;
    int rmax = n;
    REP(i,m){
        int l,r;
        cin >> l >> r;
        lmax = max(l,lmax);
        rmax = min(r,rmax);
    }
    if(lmax>rmax){
        cout << 0 << endl;
    }else{
        cout << rmax-lmax+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
fun main() {
    val n = nextInt()
    println(n * (n + 1) / 2)
}

// # Utils
// ## Input
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map(String::toInt)
fun nextLongList() = next().split(" ").map(String::toLong)
fun nextDoubleList() = next().split(" ").map(String::toDouble)

// ## Array
inline fun <reified T> sizedArray(size: Int, default: T) = Array(size) { default }
inline fun <reified T> sized2DArray(row: Int, column: Int, default: T) = Array(row) { Array(column) { default } }

// ## mod^-1
//    [NOTE] CANNOT use this for 0, mod, 2mod, 3mod ...(return wrong value)
fun modinv(num: Long, mod: Long): Long {
    var a = num
    var b = mod
    var u = 1L
    var v = 0L
    while (b > 0) {
        val t = a.div(b)
        a -= t * b
        a = b.also { b = a } // swap a and b
        u -= t * v
        u = v.also { v = u } // swap u and v
    }
    u %= mod
    if (u < 0) u += mod
    return u
}

fun gcd(x: Int, y: Int): Int {
    fun innerGcd(x: Int, y: Int): Int {
        return if (x % y == 0) y else innerGcd(y, x % y)
    }
    return if (x >= y) innerGcd(x, y) else innerGcd(y, x)
}

fun gcd(x: Long, y: Long): Long {
    fun innerGcd(x: Long, y: Long): Long {
        return if (x % y == 0L) y else innerGcd(y, x % y)
    }
    return if (x >= y) innerGcd(x, y) else innerGcd(y, x)
}

// classes
class UnionFindTree(val size: Int) {
    private val r = sizedArray(size, -1)
    fun root(x: Int): Int {
        if (r[x] < 0) return x
        return root(r[x])
    }

    fun unite(x: Int, y: Int) {
        var rx = root(x)
        var ry = root(y)
        if (rx == ry) return
        if (r[rx] > r[ry]) {
            rx = ry.also { ry = rx }
        }
        r[rx] += r[ry]
        r[ry] = rx
    }

    fun size(x: Int) = -r[root(x)]

    override fun toString(): String {
        return r.joinToString(separator = ", ")
    }
}

Measured memory_bytes: 34348
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <iostream>
using namespace std;

int main()
{
	char s[109];
	int i, j, k, n, count, max = 0;
	int a[30], b[30];


	scanf("%d", &n);
	getchar();
	scanf("%s", s);

	memset(a, 0, sizeof(a));

	for (i = 0; i < n; i++)
	{
		count = 0;
		memset(b, 0, sizeof(b));
		a[s[i] - 'a'] = 1;
		for (j = i + 1; j < n; j++)
			b[s[j] - 'a'] = 1;
		for (k = 0; k < 30; k++)
			if (a[k] && b[k])
				count++;
		if (count > max)
			max = count;
	}
	cout << max << endl;

	return 0;
}

Measured memory_bytes: 256
W,H,X,Y = map(int,input().split())
xwari = min(X*H,(W-X)*H)
ywari = min(Y*W,(H-Y)*W)
if W/2 == X and H/2 == Y:
    f = 1
else:
    f = 0
print(W*H/2, f)


Measured memory_bytes: 61748
#include<bits/stdc++.h>
#include<atcoder/all>
#define int long long
using namespace std;
using namespace atcoder;
int mn=1000000000000000000;
void a(int x,int y){
  if(gcd(x,y)!=1)return;
  int A=inv_mod(x,y);
  mn=min(mn,(A*x>1?A*x:A*x+x*y)-1);
}
signed main(){
  int N;
  cin>>N;
  N*=2;
  for(int i=1;i*i<=N;i++){
    if(N%i==0){
      a(i,N/i);
      if(i*i!=N)a(N/i,i);
    }
  }
  cout<<mn<<endl;
}

Measured memory_bytes: 3664
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <set>
using namespace std;


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int l, n;
    cin >> n >> l;
    string s[110], t[110];
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }

    sort(s, s+n);


    for (int i = 0; i < n; i++) {
        cout << s[i];
    }
    cout << endl;
	return 0;
}

Measured memory_bytes: 256