akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main(){
	int n;	//価格の数
	long int max = -1000000000;	//最大の利益
	
	//価格の数を入力
	scanf("%d",&n);
	
	long int R;	//価格
	
	//最初の価格の入力
	scanf("%ld",&R);
	
	long int min = R;//価格の最小値
	
	for(int j = 0;j < (n - 1);j++){
		//2回目以降の価格の入力
		scanf("%ld",&R);
		
		/*最大の利益と次の価格-最小値の比較
		（大きい方が最大の利益になる）*/
		max = (max > (R - min)) ? max : R - min;
		
		/*最小値と次の価格の比較
		（小さい方が最小値になる）*/
		min = (min < R) ? min : R;
	}
	
	//結果の出力
	printf("%ld\n",max);
	
	return 0;
}



Measured memory_bytes: 2064
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
int main(){
    ll n;
    ll a[100010];
    std::cin >> n;
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        sum+=a[i];
    }
    ll z[100010];
    z[0] = 0;
    ll sumz = 0;
    for (int i = 1; i < n; i++) {
        z[i] = 2*a[i-1] -z[i-1];
        sumz += z[i];
        // std::cout << z[i] << std::endl;
        // std::cout << z[i] << std::endl;
    }
    // std::cout << z[n] << std::endl;
    // z[0]=z[n];
    ll ma = 1e16;
    ll mi = 0;
    for (int i = 0; i < n; i++) {
        
        if(i%2==0){
            mi = max(mi,-z[i]);
        }else{
            ma = min(ma,z[i]);
        }
    }
    
    // std::cout << sum <<" "<<sumz <<std::endl;
    for (int i = 0; i < n; i++) {
        mi = sum-sumz;
        if(i%2==0){
            std::cout << z[i]+mi;
        }else{
            std::cout << z[i]-mi;
        }
        if(i<n-1){
            std::cout << " ";
        }else{
            std::cout << std::endl;
        }
    }
}

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

int main() {
	//int n, m;

	//cin >> n >> m;

	string s;
	cin >> s;

	if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) {
		cout << "Bad" << endl;
	} else {
		cout << "Good" << endl;
	}

	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int L, R;
  int mini = 0;
  int maxi = N;
  for(int i = 0; i < M; i++){
    cin >> L >> R;
    mini = max(mini, L);
    maxi = min(maxi, R);
  }

  cout << max(0, maxi - mini + 1) << endl;
    
}

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

#define all(x) (x).begin(),(x).end()
#define fastio ios_base::sync_with_stdio(false)

typedef double db;
typedef long long ll;
typedef unsigned long long ull;

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

int main() {
	fastio;
	int x, y, z; cin >> x >> y >> z;
	swap(x, y);
	swap(x, z);
	cout << x << " " << y << " " << z << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b1,b2,b3;
  cin >> a ;
  b1 = a/100;
  b2 = (a%100)/10;
  b3 = (a%10)/1;
  cout << b1+b2+b3 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
   string s;
   int i=0, n, ans=0;
   cin >> n;
   cin >> s;
   while(i<=n-3){
       if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C') ans++;
       i++;
   }
   cout << ans <<endl;

    return 0;
}

Measured memory_bytes: 256
H,W=map(int,input().split())
S=[0]*H
for i in range(H):
  S[i]=list(input())
T=[[0 for _ in range(W)] for ss in range(H)]

def count(a,b,H,W):
  if S[a][b]=="#":
    return "#"
  else:
    cnt=0
    if a>0 and b>0:
      if S[a-1][b-1]=="#": cnt +=1     
    if a>0 and b+1<W:
      if S[a-1][b+1]=="#": cnt +=1     
    if a+1<H and b>0:
      if S[a+1][b-1]=="#": cnt +=1     
    if a+1<H and b+1<W:
      if S[a+1][b+1]=="#": cnt +=1     

    if a>0:  
      if S[a-1][b]=="#": cnt +=1
    if a+1<H:
      if S[a+1][b]=="#": cnt +=1
    if b>0:
      if S[a][b-1]=="#": cnt +=1
    if b+1<W:
      if S[a][b+1]=="#": cnt +=1
    return str(cnt)
    

for j in range(H):
  for k in range(W):
    T[j][k]=count(j,k,H,W)
    
for r in range(H):
  print("".join(T[r]))

Measured memory_bytes: 3188
#include <stdio.h>

int main(){
   int n,i,j,v[20],s;
    
   scanf("%d",&n);
   for (i=0;i<n;i++) scanf("%d",&v[i]);
   for (s=i=0;i<n;i++) {
      scanf("%d",&j);
      v[i]-=j;
      if (v[i]>0) s+=v[i];
   }
   printf("%d\n",s);
   return 0;
}


Measured memory_bytes: 128
import collections

n,m=map(int, input().split())
g=[[] for _ in range(n+1)]
for i in range(m):
	a,b=map(int,input().split())
	g[a].append(b)
	g[b].append(a)

q=collections.deque()
q.append(1)
visit=[-1]*(n+1)
visit[1] = 1
ans=[0]*(n+1)
while q:
	v=q.popleft()
	for i in g[v]:
		if visit[i] == -1:
			ans[i] = v
			visit[i] = 1
			q.append(i)
print('Yes')
for i in range(2,n+1):
	print(ans[i])

Measured memory_bytes: 34976
#include <algorithm>
#include <cstdio>
#include <queue>
#include <vector>

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

using namespace std;

int main(){
	int n; scanf("%d",&n);
	vector<vector<int>> a(n,vector<int>(n-1));
	rep(u,n){
		rep(i,n-1) scanf("%d",&a[u][i]), a[u][i]--;
		reverse(a[u].begin(),a[u].end());
	}

	queue<pair<int,int>> Q;
	rep(u,n){
		int v=a[u].back();
		if(a[v].back()==u) Q.emplace(u,v);
	}

	int ans=0,cnt=0;
	while(cnt<n){
		vector<int> U; // updated players
		while(!Q.empty()){
			int u=Q.front().first;
			int v=Q.front().second;
			Q.pop();

			if(!a[u].empty() && a[u].back()==v){
				a[u].pop_back();
				a[v].pop_back();
				if(a[u].empty()) cnt++;
				if(a[v].empty()) cnt++;
				U.emplace_back(u);
				U.emplace_back(v);
			}
		}

		if(U.empty()){ puts("-1"); return 0; }

		for(int u:U) if(!a[u].empty()) {
			int v=a[u].back();
			if(a[v].back()==u) Q.emplace(u,v);
		}

		ans++;
	}

	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define N 200010
#define MOD 1000000007
#define fn(i,n) for(int i=0;i<n;i+=1)
#define rep(i,l,r) for(int i=l;i<=r;i+=1)
#define INF 100000000000000
#define pii pair<int,int>
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


signed main()
{
    
    speed
    string s;cin>>s;
    if(s[2]==s[3] && s[4]==s[5])
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;




    
    


    return 0;
}


Measured memory_bytes: 256
#coding:utf-8
from __future__ import division,print_function
try:
    input = raw_input
    range = xrange
except NameError:
    pass
# 上記のコードはPython2とPython3の違いを一部吸収するためのもの

# http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=916014

# N * Mの表をつくる.すべての要素はvにする。
def make_matrix(N,M,v):
    # return [[v for i in range(M)] for j in range(N)]とも書ける。
    ret = []
    for i in range(N):
        l = []
        for j in range(M):
            l.append(v)
        ret.append(l)
    return ret


# gは行列(二次元配列)
def solve(n,m,g):
    # current_max[i][j] = 直前がjの場合のi日目の最大成長度
    # 負の数にはなりえない。
    current_max = make_matrix(m,n,-1)
    # 最初は何をあげても1.0のまま
    for i in range(n):
        current_max[0][i] = 1.0
    for i in range(1,m):
        # jは次にあげるもの
        for j in range(n):
            # 前に何をあげてたか
            # current_max[i][j] = max(current_max[i-1][k] * g[k][j]) for k in [0,n]
            for k in range(n):
                current_max[i][j] = max(current_max[i][j],
                                        current_max[i-1][k]*g[k][j])
    ret = max(current_max[m-1])
    ret = round(ret,3)
    print("%.2f" % ret)

def main():
    while True:
        # 受けとった文字列をintに変換する(リストの内包表記)
        n,m = [int(i) for i in input().split(" ")]
        if n == 0 and m == 0:
            return
        g = []
        for i in range(n):
            g.append([float(x) for x in input().split(" ")])

        solve(n,m,g)
main()

Measured memory_bytes: 4540
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
 
// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ---------------------------------------------------------------------------

int main(){
  int A,B;
  cin >> A >> B;
  for(int i=1; i<=10000; i++){
    int a,b;
    a = (i*108)/100;
    b = (i*110)/100;
    if(a-i == A && b-i == B){
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
#[allow(dead_code)]
pub struct Scanner<'a> {
    _buf: &'a str,
    iter: ::std::str::SplitWhitespace<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    pub fn new(buf: &'a str) -> Self {
        Scanner {
            _buf: buf,
            iter: buf.split_whitespace(),
        }
    }

    pub fn array<T>(&mut self, n: usize) -> Vec<T>
        where T: ::std::str::FromStr,
              T::Err: ::std::fmt::Debug,
    {
        let mut res = Vec::with_capacity(n);
        for _ in 0..n {
            res.push(self.value());
        }
        res
    }

    pub fn value<T>(&mut self) -> T
        where T: ::std::str::FromStr,
              T::Err: ::std::fmt::Debug,
    {
        self.next().parse().unwrap()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.next().chars().collect()
    }

    fn next(&mut self) -> &str {
        self.iter.next().unwrap()
    }
}

fn is_ok(n: i64, s: &str) -> bool {
    let mut found = [false; 3];
    for c in s.chars() {
        match c {
            '7' => found[0] = true,
            '5' => found[1] = true,
            '3' => found[2] = true,
            _   => panic!(),
        }
    }
    if !found.iter().all(|&e| e) { return false; }

    s.parse::<i64>().unwrap() <= n
}

fn dfs(n: i64, k: i64, s: &str) -> i64 {
    if k == 0 {
        return if is_ok(n, s) { 1 } else { 0 };
    }

    let mut res = 0;
    res += dfs(n, k-1, &(s.to_owned() + "7"));
    res += dfs(n, k-1, &(s.to_owned() + "5"));
    res += dfs(n, k-1, &(s.to_owned() + "3"));
    res
}

fn main() {
    let mut _input = String::new();
    {
        use ::std::io::Read;
        ::std::io::stdin().read_to_string(&mut _input).unwrap();
    }
    let mut sc = Scanner::new(&_input);

    let n = sc.value::<i64>();

    let mut ans = 0;
    for k in 3..10 {
        ans += dfs(n, k, "");
    }

    println!("{}", ans);
}


Measured memory_bytes: 4476
N, K = map(int, input().split())
MOD = 10**9 + 7
 
D = [[0]*(K+1) for i in range(N+1)]
D[0][0] = 1
for n in range(1, N+1):
    D0 = D[n-1]
    for k in range(1, K+1):
        D[n][k] = (D0[k-1] + k * D0[k]) % MOD
print(sum(D[N]) % MOD)


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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,a,mi=10000,b,c,d;
	cin>>n;
	a=pow(n,0.5)+2;
	for(ll i=1;i<a;i++){
			if(n%i==0){
				b=n/i;
				c=to_string(i).length();d=to_string(b).length();
				mi=min(mi,max(c,d));
			}
	}
	cout<<mi<<endl;
	return 0;
}


Measured memory_bytes: 640
n = gets.chomp.to_i

rooms = [
  [
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  ],
  [
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  ],
  [
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  ],
  [
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  ]
]

n.times do
  b, f, r, v = gets.chomp.split.map(&:to_i)
  rooms[b-1][f-1][r-1] += v
end

4.times do |i|
  3.times do |j|
    puts " #{ rooms[i][j].join(" ") }"
  end
  puts "#" * 20 if i != 3
end

Measured memory_bytes: 8712
#include<cstdio>

#define Fast register
inline char Getchar(){
	static char BUF[16384],*S=BUF,*T=BUF;
	return(S==T)&&(T=(S=BUF)+fread(BUF,1,16384,stdin),S==T)?EOF:*S++;
}
inline int Getint(){
	Fast int s=0;Fast char c;
	while(c=Getchar(),c<48||c>57);
	while(s=s*10+c-48,c=Getchar(),c>47&&c<58);
	return s;
}

int c[4][4];

int main(){
	Fast int sum1=0,sum2=0;
	for(Fast int i=1;i<=3;++i){
		for(Fast int j=1;j<=3;++j){
			sum1+=(c[i][j]=Getint());
		}
		sum2+=c[i][i];
	}
	if(sum1!=sum2*3)return(puts("No"),0);
	return(puts("Yes"),0);
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int n;
long long l0=2,l1=1,dd;
int main(){
	cin>>n;
	for(int i=1;i<n;i++){
		dd=l0+l1;
		l0=l1;
		l1=dd;
		
	}
	cout<<l1<<endl;
	return 0;
}

Measured memory_bytes: 256
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
la, lb = [0], [0]
for i in range(n):
    la.append(la[i] + a[i])
for i in range(m):
    lb.append(lb[i] + b[i])
ans, j = 0, m
for i in range(n + 1):
    if la[i] > k:break
    while lb[j] > k - la[i]:j -= 1
    ans = max(ans, i + j)
print(ans)

Measured memory_bytes: 47452
import java.util.Scanner;


public class Main {

	public static void main(String[] args)  {

		Scanner sc = new Scanner(System.in);
		int k =  Integer.parseInt(sc.next());
		int a =  Integer.parseInt(sc.next());
		int b =  Integer.parseInt(sc.next());
		
		String ans = "NG";
		for(int i = a ; i <= b ; i++) {
			if(i % k == 0) {
				ans = "OK";
				break;
			}
			
		}
		
		System.out.println(ans);
		
	}
	
}

Measured memory_bytes: 26968
#mAx average set
n,a,b=map(int,input().split())
lists=list(map(int,input().split()))
lists=sorted(lists)
P=sum(lists[-a:])
print(P/a)
#Bことって総和がminiになっている
from collections import Counter
J=dict(Counter(lists))
K=dict(Counter(lists[-a:]))
import math
ans=1
sums=0
if J[max(lists)]<a:
    for some in K.keys():
        ans*=(math.factorial(J[some])//((math.factorial(K[some]))*math.factorial(J[some]-K[some])))
    print(ans)
elif J[max(lists)]>a:
    for i in range(a,min(b,J[max(lists)])+1):
        sums+=math.factorial(J[max(lists)])//(math.factorial(J[max(lists)]-i)*math.factorial(i))
    print(sums)
else:
    print(1)

Measured memory_bytes: 3316
import copy,heapq

N,K=map(int,input().split())
V=list(map(int,input().split()))

ans=0
left=copy.copy(V)
for i in range(1,N):
    left[i]+=left[i-1]
right=copy.copy(V)
for i in range(1,N):
    right[-i-1]+=right[-i]
for i in range(0,N+1):
    for j in range(0,N-i+1):
        dispose=K-i-j
        if 0>dispose:
            continue
        test=0
        q=[]
        if i>0:
            test+=left[i-1]
            q+=V[:i]
        if j>0:
            test+=right[-j]
            q+=V[N-j:N]

        heapq.heapify(q)
        while dispose>0 and q:
            x=heapq.heappop(q)
            if 0>x:
                test-=x
                dispose-=1
            else:
                break
        ans=max(ans,test)

print(ans)


Measured memory_bytes: 50268
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		List<Integer> l = new ArrayList<Integer>();
		int n = sc.nextInt();
		boolean addFirst = false;
		while (n-->0) {
			if (addFirst) l.add(0, sc.nextInt());
			else l.add(sc.nextInt());
			addFirst = !addFirst;
		}	
		if (addFirst) Collections.reverse(l);
		for (int a : l) System.out.print(a+" ");
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

}

Measured memory_bytes: 65732
// 以下のライブラリを使ってみる.
// 素集合データ構造(Union-Find)
// https://ei1333.github.io/luzhiled/snippets/structure/union-find.html
#include <bits/stdc++.h>
using namespace std;

struct UnionFind{

    vector<int> data;
    UnionFind(int sz){ data.assign(sz, -1); }
    
    // 頂点 x, y の 結合.
    bool unite(int x, int y){
        // cout << " unite start x=" << x << " y=" << y << endl;
        x = find(x), y = find(y);
        // cout << " unite check(x == y) x=" << x << " y=" << y << endl;
        if(x == y)            return false;
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        // cout << " unite swap(x, y) data[" << x << "]=" << data[x] << " data[" << y << "]=" << data[y] << endl;
        return true;
    }
    
    // 頂点 k を 探索.
    int find(int k){
        if(data[k] < 0) return k;
        return data[k] = find(data[k]);
    }
    
    // 頂点 k を含む集合 の 大きさ.
    int size(int k){ return (-data[find(k)]); }
};

int main(){

    // 1. 入力情報取得.
    int N, Q;
    scanf("%d %d", &N, &Q);
    UnionFind uf(N);
    
    // 2. 各判定クエリに対し, 出力を行う.
    for(int i = 0; i < Q; i++){
        int t, x, y;
        scanf("%d %d %d", &t, &x, &y);
        if(t == 0) uf.unite(x, y);
        else        printf("%d\n", uf.find(x) == uf.find(y));
    }

    // 3. 後処理.
    return 0;

}


Measured memory_bytes: 3260
#include <iostream>
#include <cstring>
using namespace std ;
const int N = 400,M = N+10,mod = 998244353 ;
inline int add(int a,int b){ return a+b >= mod ? a+b-mod : a+b ; }
inline int sub(int a,int b){ return a >= b ? a-b : a-b+mod ; }
inline int mul(int a,int b){ return 1ll*a*b%mod ; }
inline int power(int a,int b){
    int res = 1 ;
    for( ; b ; b >>= 1){
        if(b&1) res = mul(res,a) ;
        a = mul(a,a) ; 
    }
    return res ; 
}
int fac[M],inv[M],S ; 
inline void prework(void){
    fac[0] = inv[0] = 1 ;
    for(int i = 1 ; i <= N ; i++) fac[i] = mul(fac[i-1],i) ;
    for(int i = 1 ; i <= N ; i++) inv[i] = power(fac[i],mod-2) ;
}
inline void Mul(int *a,int *b,int *c,int len){
    for(int i = 0 ; i <= S ; i++)
        for(int j = 0 ; i+j <= S && j < len ; j++)
           c[i+j] = add(c[i+j],sub(mod,mul(a[i],b[j]))) ; 
}
inline void Plus(int *a,int *b){
    for(int i = 0 ; i <= S ; i++) b[i] = add(b[i],a[i]) ;
}
int n,a[M],b[M],c[M],f[M][M],g[M][M],Inv,ans ; 
int main(){
    //freopen("in.txt","r",stdin) ; 
    prework() ; 
    cin >> n ;
    for(int i = 1 ; i <= n ; i++) scanf("%d%d",&a[i],&b[i]),S += a[i] ;
    Inv = power(S,mod-2) ; f[0][0] = 1 ;
    for(int i = 1 ; i <= n ; i++){
        memcpy(g,f,sizeof g) ;
        memset(f,0,sizeof f) ;
        c[0] = 1 ; 
        for(int j = 1 ; j < b[i] ; j++)
            c[j] = mul(c[j-1],mul(a[i],Inv)) ; 
        for(int j = 1 ; j < b[i] ; j++)
            c[j] = mul(c[j],inv[j]) ;
        for(int j = 0 ; j <= S-a[i] ; j++)
            Mul(g[j],c,f[j],b[i]),Plus(g[j],f[j+a[i]]) ; 
    }
    for(int d = 0 ; d < S ; d++){
        int e = mul(d,Inv),L = power(sub(1,e),mod-2) ;
        ans = add(ans,mul(L,f[d][0])) ;
        for(int i = 1 ; i <= S ; i++){
            L = mul(power(sub(1,e),mod-2),mul(i,L)) ;
            ans = add(ans,mul(L,f[d][i])) ; 
        }
    }
    cout << sub(mod,ans) << endl ; 
    return 0 ; 
}

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

namespace AtCoderExamCS
{
    class Program
    {
        static void Main(string[] args)
        {
            char a;

            a = char.Parse(Console.ReadLine());
            if (a < 91)
            {
                Console.WriteLine("A");
            }
            else
            {
                Console.WriteLine("a");
            }
        }
    }
}


Measured memory_bytes: 25796
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <istream>
#include <map>
#include <set>
#include <queue>
#define rep0(i,n) for (int i = 0; i <= (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define REP(a,b) for (int i = a; i <= (b); ++i) 
#define mREP(a,b) for (int i = a; i == (b); --i)
#define mod 1e9 + 7
typedef long long ll;
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	/*
	　　　　　 　 _... ..._
	　　　　　 , ´⌒ ⌒ヽ
	　　　 　 ﾉｨ（ノﾉ）ﾉ）ﾉ）
	　　　 　 （（q|.ﾟ ヮﾟﾉ|ﾊ
	　　　　　　△ﾑ,8ﾑﾌつ
	　　　　　/(ﾝ_/＿ヽ＼
	　　　　 ～～i_ﾌ_ﾌ～´
	*/
	int n;
	cin >> n;
	cout << ((n >= 1000) ? "ABD" : "ABC") << endl;
	return 0;
}
 

Measured memory_bytes: 256
from collections import Counter
import sys
from math import isinf


def warshall_floyd(v_count: int):
    """ ワーシャルフロイド　(user:htkb)
    :param v_count: 頂点数
    :param matrix:  隣接行列(到達不能はfloat("inf"))
    """
    # 到達不能をfloat("inf")にしておけば余計なチェックを入れなくても
    # inf > inf+(-1) のような到達不能＋負辺が繋がってしまうことはない
    global matrix
    for i in range(v_count):
        for j, c2 in enumerate(row[i] for row in matrix):
            for k, (c1, c3) in enumerate(zip(matrix[j], matrix[i])):
                if c1 > c2+c3:
                    matrix[j][k] = c2+c3  # min(c1, c2+c3)


H, W = map(int, input().split())
V = 10
matrix = [[float('inf')]*V for _ in range(V)]
for i in range(10):
    c = map(int, input().split())
    for j, cj in enumerate(c):
        matrix[i][j] = cj

warshall_floyd(V)
costs = [matrix[i][1] for i in range(10)]

l = []
for _ in range(H):
    l.extend(list(map(int, input().split())))
c = Counter(l)
ans = 0


for k, v in c.items():
    if k == -1:
        continue
    ans += costs[k]*v
print(ans)


Measured memory_bytes: 3840
mycode = r'''
# distutils: language=c++
# cython: language_level=3
# cython: boundscheck=False
# cython: wraparound=False
# cython: infer_types=True
# cython: cdivision=True
# False:Cython はCの型に対する除算・剰余演算子に関する仕様を、(被演算子間の符号が異なる場合の振る舞いが異なる)Pythonのintの仕様に合わせ、除算する数が0の場合にZeroDivisionErrorを送出します。この処理を行わせると、速度に 35% ぐらいのペナルティが生じます。 True:チェックを行いません。

ctypedef long long LL

import numpy as np

# 読み込みはpython側で行う
import sys
readline = sys.stdin.buffer.readline
read = sys.stdin.readline #文字列読み込む時はこっち

cdef LL a_int(): return int(readline())

def ints(): return np.fromstring(readline(), sep=' ', dtype=np.int64)

cdef read_matrix(LL H,LL W):
    #return np.ndarray shape=(H,W) matrix
    lines=[]
    cdef LL _
    for _ in range(H): 
        lines.append(read())
    lines=' '.join(lines) #byte同士の結合ができないのでreadlineでなくreadで
    return np.fromstring(lines, sep=' ',dtype=np.int64).reshape(H,W)


N=a_int()
D=read_matrix(N,1)[:,0]
print(len(np.unique(D)))


'''

import sys
if sys.argv[-1] == 'ONLINE_JUDGE':  # コンパイル時
    import os
    with open('mycode.pyx', 'w') as f:
        f.write(mycode)
    os.system('cythonize -i -3 -b mycode.pyx')

import mycode


Measured memory_bytes: 27256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001




int main (){
    int N, Q; cin >> N >> Q;
    string S; cin >> S;

    vector<int> V(N+1);
    for(int i=0; i<N; i++){
        if(S[i]=='A' && S[i+1]=='C') V[i+1] = V[i] + 1;
        else V[i+1] = V[i];
    }

    

    while(Q--){
        int L, R; cin >> L >> R;
        L--; R--;
        cout << -(V[L] - V[R]) << endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
int SIZE(string s){return (int)s.size();}
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    int n,m; cin >> n >> m;
    vi a(n);
    vi ans(n,1);
    rep(i,n){
        cin >> a[i];
    }
    rep(i,m){
        int x,y; cin >> x >> y;
        x--; y--;
        if(a[x] < a[y]){
            ans[x] = 0;
        }
        if(a[x] > a[y]){
            ans[y] = 0;
        }
        if(a[x] == a[y]){
            ans[y] = 0;
            ans[x] = 0;
        }
    }
    cout << accumulate(all(ans),0) << endl;
    return 0;
}


Measured memory_bytes: 4060
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	int n;
	cin >> n;
	int x = n/2;
	if (n %2 ==1) {
		x++;
	}
	cout << (double)x/n << endl;
	return 0;
}


Measured memory_bytes: 888
def gcd(a, b):
    if a<b: a, b = b, a
    while a%b:
        a, b = b, a%b
    return b

def main():
    a, b, c, d = map(int, input().split())
    ans = b - a + 1
    if a%c: ans -= b//c-a//c
    else: ans -= b//c+1-a//c

    if a%d: ans -= b//d-a//d
    else: ans -= b//d+1-a//d

    sks = (c*d) // gcd(c, d)
    if a%sks: ans += b//sks-a//sks
    else: ans += b//sks+1-a//sks
    print(ans)

if __name__=="__main__": main()

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

int main() {
  double data[7][2] = {{35.50, 71.0},
		       {37.50, 77.0},
		       {40.0 , 83.0},
		       {43.0 , 89.0},
		       {50.0 , 105.0},
		       {55.0 , 116.0},
		       {70.0 , 148.0}};
  string level[7] = {"AAA", "AA", "A", "B", "C", "D", "E"};
  double t500, t1000;
  while(cin >> t500 >> t1000) {
    for(int i = 0; i < 7; i++) {
      if(t500 < data[i][0] && t1000 < data[i][1]) {
	cout << level[i] << endl;
	break;
      }
      if(i+1 == 7) cout << "NA" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
h, w, k = map(int, input().split())
dp = [1] + [0] * (w - 1)
mod = 1000000007
for _ in range(h):
    newdp = [0] * w
    for b in range(1 << (w - 1)):
        valid = True
        for i in range(w - 1):
            if (b >> i) & 3 == 3:
                valid = False
        if valid:
            for i in range(w):
                if (b >> i) & 1 != 0:
                    newdp[i + 1] = (newdp[i + 1] + dp[i]) % mod
                elif i > 0 and (b >> (i - 1)) & 1 != 0:
                    newdp[i - 1] = (newdp[i - 1] + dp[i]) % mod
                else:
                    newdp[i    ] = (newdp[i    ] + dp[i]) % mod
    dp = newdp
print(dp[k - 1])


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

int main() {
	int N, M, X;
	cin >> N >> M >> X;
	vector<int> C(N);
	vector<vector<int>> A(N, vector<int>(M));
	rep(i, N) {
		cin >> C[i];
		rep(j, M) cin >> A[i][j];
	}

	int ans = 1e9;
	rep(bit, 1 << N) {
		int amount = 0;
		vector<int> cnt(M, 0);
		rep(i, N) {
			if(!(bit & (1 << i))) continue;

			amount += C[i];
			rep(j, M) cnt[j] += A[i][j];
		}

		bool res = true;
		rep(j, M) {
			if(cnt[j] < X) res = false;
		}

		if(res) ans = min(ans, amount);
	}

	if(ans == 1e9)
		cout << -1 << endl;
	else
		cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <tuple>
#include <iomanip>


using namespace std;

typedef long long ll;

const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
	return f.second > s.second;
}

int gcd(int a, int b){
	if (b == 0)return a;
	return gcd(b, a % b);
}


int main(void){
	int n, m;

	cin >> n >> m;

	int k[40];
	int a[40][40];

	for (int i = 0; i < n; i++){
		cin >> k[i];
		for (int j = 0; j < k[i]; j++){
			cin >> a[i][j];
		}
	}

	int ans = 0;
	for (int i = 1; i <= m; i++){
		bool allok = true;
		for (int j = 0; j < n; j++){
			bool ok = false;
			for (int x = 0; x < k[j]; x++){
				if (a[j][x] == i){
					ok = true;
					break;
				}
			}
			if (!ok){
				allok = false;
				break;
			}
		}
		if (allok)ans++;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

// AOJ 0067
public class Main {
	static Scanner sc = new Scanner(System.in);
	static boolean[][] iv = new boolean[12][12];
	static char[][] cs = new char[12][12];
	public static void main(String[] args) {
		while (sc.hasNext()) {
			String s = sc.next();
			if (s.equals("")) continue;
			
			cs[0] = s.toCharArray();
			for (int i = 1; i < 12; i++) 
				cs[i] = sc.next().toCharArray();
			
			int res = 0;
			for (int i = 0; i < 12; i++) fill(iv[i], false);
			for (int i = 0; i < 12; i++) 
				for (int j = 0; j < 12; j++) 
					if (!iv[i][j] && cs[i][j] == '1') {
						bfs(j, i);
						res++;
					}

			System.out.println(res);
		}
	}
	
	static int[] dx = {0, 1, 0, -1}, dy = {1, 0, -1, 0};
	static void bfs(int x, int y) {
		if (x < 0 || x >= 12 || y < 0 || y >= 12 || iv[y][x] || cs[y][x] == '0') return;
		iv[y][x] = true;
		for (int k = 0; k < 4; k++) bfs(x + dx[k], y + dy[k]);
	}
}

Measured memory_bytes: 12000
package main

import ("fmt")

func main(){
	var N int
	var H [100000]int
	var top,count int

	count = 0
	top = 0

	fmt.Scan(&N)
	
	for i := N ; i < 100000 ; i++{
		H[i] = 0
	}
	
	for i := 0 ; i < N ; i++{
		fmt.Scan(&H[i])
	}

	//maxtop = 0
	
	for i := 0 ; i < N-1 ; i++ {
		if H[i] < H[i+1] {
			count = 0
		}else if H[i] >= H[i+1]{
			count += 1
		}
		if top < count{
			top = count

		}
	}
	fmt.Println(top)
}

Measured memory_bytes: 5504
n=int(input())
def md(x,y):
    return abs(x)+abs(y)
def isOdd(a,b):
    if a%2==b%2:
        return False
    else:
        return True 
pt=0
px=0
py=0
for _ in range(n):
    t,x,y=map(int,input().split())
    dt=t-pt
    dx=x-px
    dy=y-py
    pt=t
    px=x
    py=y
    if dt<md(dx,dy) or isOdd(dt,md(dx,dy)):
        print('No')
        break
else:
    print('Yes')


Measured memory_bytes: 3064
#include <stdio.h>

int main() {
  int count = 0;
  char* p;
  char s[101], w[101];
  scanf("%s", s);
  while(scanf("%s", w), strcmp(w, "END_OF_TEXT")) {
    for(p = w; *p; ++p) *p = tolower(*p);
    if(!strcmp(s, w)) ++count;
  }
  printf("%d\n", count);
  return 0;
}

Measured memory_bytes: 552
def main():
  a, b = map(int, input().split())
  ans = 0
  if a == b:
    for i in range(a):
      ans += a * pow(10,i)
  elif a < b:
    for i in range(b):
      ans += a * pow(10,i)
  else:
    for i in range(a):
      ans += b * pow(10,i)
  print(ans)


if __name__ == '__main__':
  main()


Measured memory_bytes: 3060
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

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

#define MAX_N 200000

class UnionFind {
private:
  // 親と木の深さ
  int par[MAX_N];
  int rank[MAX_N];
  int s[MAX_N];
public:
  void init(int n);
  int find(int x);
  void unite(int x, int y);
  bool same(int x, int y);
};

// 要素数nで初期化
void UnionFind::init (int n) {
  for(int i=0; i<n; i++) {
    par[i] = i;
    rank[i] = 0;
    s[i] = 1;
  }
}

// 要素xの親を求める
int UnionFind::find(int x) {
  if(par[x] == x) return x;
  else return par[x] = find(par[x]);
}

// xとyの属する集合を併合
void UnionFind::unite(int x, int y) {
  // xとyの親
  x = find(x);
  y = find(y);
  if(x == y) return;

  // yのほうが深さが深い　xの親はyの親
  if(rank[x] < rank[y]) {
    par[x] = y;
    s[y] = s[x] + s[y];
  }
  else {
    par[y] = x;
    s[x] = s[x] + s[y];
    if( rank[x] == rank[y] ) rank[x]++;
  }
}

// xとyが同じ集合に属するか
bool UnionFind::same(int x, int y) { return find(x) == find(y);}

UnionFind uf;
PII x[100010], y[100010];
struct edge{int u, v, cost;};
bool comp(const edge& e1, const edge& e2) {
  return e1.cost < e2.cost;
}
edge es[400010];
signed main(void)
{
  int n;
  cin >> n;
  REP(i, n) {
    int a, b;
    cin >> a >> b;
    x[i] = {a, i};
    y[i] = {b, i};
  }

  //辺を張る
  sort(x, x+n);
  sort(y, y+n);
  FOR(i, 1, n) {
    es[i-1] = (edge){x[i].second, x[i-1].second, abs(x[i].first - x[i-1].first)};
    es[n+i-1] = (edge){x[i-1].second, x[i].second, abs(x[i].first - x[i-1].first)};
  }
  FOR(i, 1, n) {
    es[2*n+i-2] = (edge){y[i].second, y[i-1].second, abs(y[i].first - y[i-1].first)};
    es[3*n+i-3] = (edge){y[i-1].second, y[i].second, abs(y[i].first - y[i-1].first)};
  }

  sort(es, es+n*4-4, comp);
  uf.init(n);
  int res = 0;
  REP(i, 4*n-4) {
    edge e = es[i];
    if(!uf.same(e.u, e.v)) {
      uf.unite(e.u, e.v);
      res += e.cost;
    }
  }
  cout << res << endl;
  return 0;
}


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

int main() {
  string x;
  cin >> x ;
  if (x.at(0)==x.at(1)&&x.at(1)==x.at(2)){
    cout << "Yes" << endl;
  }
  else if (x.at(1)==x.at(2)&&x.at(2)==x.at(3)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<climits>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<queue>


int main(){
	int p,q,r;
	std::cin>>p>>q>>r;

	std::cout<<std::min(p+q, std::min(q+r, p+r))<<std::endl;


	return 0;
	
}

Measured memory_bytes: 256
input = gets.strip.split.map!(&:to_i)
n = input[0]
l = input[1]
i = 1 - l

if(i < 1)
  i = 1
elsif(i > n)
  i = n
end

puts (l - 1) * (n - 1) + n * (n + 1) / 2 - i


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

int pledges(int a, int b) {
	int tmp, r;

	if (a<b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

int main() {
	int N, X, x[100000], i, dif[100000];

	scanf("%d %d", &N, &X);
	for (i = 0; i < N; i++) {
		scanf("%d", &x[i]);
		dif[i] = abs(X - x[i]);
	}
	
	for (i = 1; i < N; i++) {
		dif[i] = pledges(dif[i - 1], dif[i]);
	}

	printf("%d", dif[N - 1]);

	return 0;
}

Measured memory_bytes: 896
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
  Scanner sc;

  Main() {
    sc = new Scanner(System.in);
  }

  int ni() {
    return sc.nextInt();
  }

  void run() {
    for(;;){
      int N = ni();

      if( N == 0 ) {
        break;
      }

      int W, H;
      W = ni();
      H = ni();
      int[][] field = new int[W][H];
      for(int i = 0; i < N; ++i) {
        int x = ni() - 1;
        int y = ni() - 1;

        field[x][y] |= 1;
      }

      int S, T;
      S = ni();
      T = ni();

      int max = 0;
      for(int i = 0; i <= W - S; ++i) {
        for(int j = 0; j <= H - T; ++j) {
          int cnt = 0;
          for(int x = 0; x < S; ++x) {
            for(int y = 0; y < T; ++y ) {
              cnt += field[i + x][j + y];
            }
          }
          max = Math.max(cnt, max);
        }
      }

      System.out.println(max);
    }
  }

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

  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }
}

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

map<string,int> m;

int main()
{
	int n;
	cin>>n;
	
	string s;
	for(int i=1;i<=n;i++)
	{
		cin>>s;
		m[s]++;
	}
	
	cout<<"AC x "<<m["AC"]<<endl;
	cout<<"WA x "<<m["WA"]<<endl;
	cout<<"TLE x "<<m["TLE"]<<endl;
	cout<<"RE x "<<m["RE"]<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  int n;
  cin >> n;
  vector<ll> h(n);
  for(int i = 0; i < n; i++){
    cin >> h[i];
  }
  h.push_back(1001001001001);
  for(int i = 0; i < n; i++) {
    if(h[i] < h[i+1]){
      h[i + 1]--;
    }
  }
  for(int i = 0; i < n; i++){
    if(h[i] > h[i + 1]){
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";

  return 0;
}

Measured memory_bytes: 1792
#include<iostream>

using namespace std;

//AからWまで
int h_map[6][2];


//値設定関数
void f_set()
{
	//Aから
	h_map[0][0] = 1;
	h_map[0][1] = 4;

	h_map[1][0] = -1;
	h_map[1][1] = 2;

	h_map[2][0] = 5;
	h_map[2][1] = 3;

	h_map[3][0] = 4;
	h_map[3][1] = 1;

	h_map[4][0] = 1;
	h_map[4][1] = -1;

	h_map[5][0] = 3;
	h_map[5][1] = 4;
}



int main(void)
{
	//入力文字列
	char str_input[110] = {NULL};

	
	//終了条件
	while (cin >> str_input && str_input[0] != '#')
	{
		//値をセット
		f_set();

		int count = 0;

		int tosi = 0;

		//ナル文字まで
		while (str_input[count] != '\0')
		{
			if (str_input[count] == '0')
			{
				tosi = h_map[tosi][0];
			}
			else if (str_input[count] == '1')
			{
				tosi = h_map[tosi][1];
			}

			//-1の時はbreak
			if (tosi == -1)
			{
				break;
			}

			count++;
		}

		if (tosi == 3)
		{
			cout << "Yes" << endl;
		}
		else
		{
			cout << "No" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1132
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

int main(){
  int m1,d1,m2,d2; cin >> m1 >> d1 >> m2 >> d2;
  if(m1 != m2) cout << 1 << endl;
  else cout << 0 << endl;
}

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

namespace Contest20191030
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            int n = int.Parse(s[0]);
            int m = int.Parse(s[1]);
            int l = 0;
            int r = 100000;
            
            for (int i = 0; i < m; i++)
            {
                string[]t = Console.ReadLine().Split();
                int num = int.Parse(t[0]);
                int num2 = int.Parse(t[1]);

                if (l < num)
                    l = num;

                if (r > num2)
                    r = num2;
               
            }

            int count = 0;
            for (int i = 0; i < n; i++) 
            {
                bool success = true;
               
                    if(i + 1 < l || i+ 1 > r)
                    {
                        success = false;
                        
                    }

                if (success)
                    count++;
            }


            Console.WriteLine(count);


        }
    }
}


Measured memory_bytes: 15300
import collections
k,n = map(int, raw_input().split(' '))


cc = {'AC': collections.Counter(), 'WA': collections.Counter()}
for _ in range(n):
	i,res = raw_input().split(' ')
	i = int(i)
	if res == 'AC':
		cc['AC'][i] += 1
	elif res == 'WA':
		if cc['AC'][i] == 0:
			cc['WA'][i] += 1
s = 0
for p in cc['AC']:
	s += cc['WA'][p]
print len(cc['AC']), s #len(penalties)

Measured memory_bytes: 43164
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;



int main()
{
	int n;
	cin >> n;
	vector<int> a(n+1);
	for (int i = 1; i < n + 1; i++) {
		cin >> a[i];
	}

	vector<int> b = a;
	sort(b.begin(), b.end());
	int med1 = b[n / 2], med2 = b[n / 2 + 1];
	for (int i = 1; i < n + 1; i++) {
		if (a[i] <= med1) {
			cout << med2 << endl;
		}
		else {
			cout << med1 << endl;
		}
	}


	
	return 0;
}

Measured memory_bytes: 3712
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <cstdio>
#include <functional>
#include <vector>

using namespace std;

// Combination Table
// C[n][k] -> nCk
array<array<long long int, 51>, 51> C;

void comb_table(int N)
{
    for (int i = 0; i <= N; i++)
    {
        for (int j = 0; j <= i; j++)
        {
            if (j == 0 || j == i) C[i][j] = 1LL;
            else C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]);
        }
    }
}

int main()
{
    int N, A, B;
    if (scanf("%d%d%d", &N, &A, &B) < 3) return 0;

    vector<long long int> v;
    v.resize(N);

    for (int i = 0; i < N; i++)
    {
        long long int tmp = 0;
        scanf("%lld", &tmp);
        v[i] = tmp;
    }

    sort(v.begin(), v.end(), greater<long long int>());

    double avg = 0.0;
    for (int i = 0; i < A; i++) avg += v[i];
    avg /= A;

    int val = 0;
    int pos = 0;
    for (int i = 0; i < N; i++)
    {
        if (v[i] == v[A - 1])
        {
            val++;
            if (i < A) pos++;
        }
    }

    long long int cnt = 0LL;

    // Combination Table
    comb_table(N);

    if (pos == A) for (; pos <= B; pos++) cnt += C[val][pos];
    else cnt += C[val][pos];

    printf("%.6f\n", avg);
    printf("%lld\n", cnt);
    return 0;
}


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

using namespace std;

int main(){

    string input = "";

    cin >> input;

    int digit_sum = 0;

    for(char x : input){

        digit_sum += x - '0';

    }

    if(digit_sum%9 == 0){
        cout <<"Yes\n";
    }else{
        cout <<"No\n";
    }

    
    return 0;
}

Measured memory_bytes: 3368
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

const i64 MOD = 998244353;

struct mint {
  long long x;
  mint(long long x = 0) : x((x % MOD + MOD) % MOD) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, S;
  cin >> N >> S;
  vector<int> A(N);
  for (auto& x : A) cin >> x;
  vector<mint> poly(S + 1), tmp(S + 1);
  mint ans = 0;
  REP(i, N) {
    poly[0] += 1;
    std::copy(poly.begin(), poly.end(), tmp.begin());
    for (int j = 0; j + A[i] <= S; ++j) {
      poly[j + A[i]] += tmp[j];
    }
    ans += poly[S];
  }
  cout << ans << endl;
}


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

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

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

queue<P> que;
int H, W;
string S[100];
int dist[60][60];

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

    std::cin >> H >> W;

    int cnt = 0;
    for(int i=0;i<H;++i){
        std::cin >> S[i];
        for(int j=0;j<W;++j){
            if(S[i][j] == '#'){
                ++cnt;
            }
        }
    }

    for(int i=0;i<60;++i){
        for(int j=0;j<60;++j){
            dist[i][j] = 1001001001;
        }
    }
    {
        que.emplace(0, 0);
        dist[0][0] = 0;
        while(!que.empty()){
            int x, y;
            tie(x, y) = que.front();
            que.pop();

            for(int i=0;i<4;++i){
                int nx = x + dx[i], ny = y + dy[i];
                if(nx < 0 || nx >= W || ny < 0 || ny >= H){
                    continue;
                }
                if(S[ny][nx] == '#'){
                    continue;
                }

                if(dist[ny][nx] > dist[y][x] + 1){
                    dist[ny][nx] = dist[y][x] + 1;
                    que.emplace(nx, ny);
                }
            }
        }
    }

    if(dist[H-1][W-1] == 1001001001){
        std::cout << -1 << std::endl;
    }else{
        int res = (W * H - (dist[H-1][W-1] + 1)) - cnt;
        std::cout << res << std::endl;
    }
}


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

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().ToCharArray().ToList();
            var first = s.IndexOf('A');
            var last = s.LastIndexOf('Z');
            Console.WriteLine(last - first + 1);
        }
    }
}


Measured memory_bytes: 13152
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

long long int gcd(long long int a,long long int b){
	long long int tmp;
	while(b != 0ll){
		a -= b * (long long int)(a / b);
		tmp = a;
		a = b;
		b = tmp;
	}
	return a;
}

int lcm(int a,int b){
	long long int la = (long long int)a,lb = (long long int)b;
	return la / gcd(la,lb) * lb;
}

struct bou{
	int left,right;
	int lbou,rbou;
};

int main(){
	int n,res = 1;
	vector<bou> tree;
	int si[100],bo[100],par[100];
	while(cin >> n,n){
	tree.clear();
	res = 1;
	for(int i = 0;i < n;i++) {
		par[i] = -1;
		si[i] = 1;
		bo[i] = 1;
	}
	for(int i = 0;i < n;i++){
		long long int a,b;
		int c,d;
		cin >> a >> b >> c >> d;
		tree.push_back({a / gcd(a,b),b / gcd(a,b),c - 1,d - 1});
		if(c >= 1) par[c - 1] = i;
		if(d >= 1) par[d - 1] = i;
	}
	queue<int> que;
	for(int i = 0;i < n;i++) if(par[i] == -1) que.push(i);
	while(!que.empty()){
		int q = que.front();que.pop();
		//cout << q;
		bou now = tree[q];
		long long int bun[4];
		bun[0] = si[q] * now.right;
		bun[1] = bo[q] * (now.left + now.right);
		bun[2] = si[q] * now.left;
		bun[3] = bun[1];
		int g1 = gcd(bun[0],bun[1]),g2 = gcd(bun[2],bun[3]);
		bun[0] /= g1;
		bun[1] /= g1;
		bun[2] /= g2;
		bun[3] /= g2;
		if(now.lbou != -1){
			si[now.lbou] = (int)bun[0];
			bo[now.lbou] = (int)bun[1];
			que.push(now.lbou);
		}else{
			res = lcm(res,(int)bun[1]);
		}
		//cout << "k" << endl;
		if(now.rbou != -1){
			si[now.rbou] = (int)bun[2];
			bo[now.rbou] = (int)bun[3];
			que.push(now.rbou);
		}else{
			res = lcm(res,(int)bun[3]);
		}
	}
	cout << res << endl;
	}
	return 0;	
}

Measured memory_bytes: 3080