akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int ans = 0;
    int a = 0;
    int b = 0;
    int c = 0;
    for(int i = 0; i < n ;i++) {
      String s = sc.next();
      for(int j = 0; j < s.length() - 1; j++) {
        if((s.charAt(j) == 'A') && (s.charAt(j + 1) == 'B')) ans++;
      }
      if(s.charAt(s.length() - 1) == 'A') {
        if(s.charAt(0) == 'B') {
          c++;
        } else {
          a++;
        }
      } else if(s.charAt(0) == 'B') {
        b++;
      }
    }
    int r = 0;
    if(c == 0) {
      r = Math.min(a, b);
    } else {
      if(a == 0) {
       if(b == 0) {
         r = c - 1;
       } else {
         r = c;
       }
      } else if(b == 0) {
        r = c;
      } else {
        r = c + Math.min(a - 1, b - 1) + 1;
      }
    }
    ans += r;
    System.out.println(ans);
  }
}

Measured memory_bytes: 31076
MOD = 10**9+7
N, M = map(int, input().split())
A = set([int(input()) for _ in range(M)])
dp = [0] * (N+3)
dp[0] = 1
for i in range(N):
    if i+1 not in A:
        dp[i+1] += dp[i]
        dp[i+1] %= MOD
    if i+2 not in A:
        dp[i+2] += dp[i]
        dp[i+2] %= MOD
print(dp[N])

Measured memory_bytes: 13216
# いやいやいやいやいやいやいや

# え何 もしかして色って最大8色とはどこにもかいてありませ〜〜〜んとかいうオチ？
# > 4人目が「紫色」を選び、5人目が「黒色」を選んだ時、色の種類数は5であり、これは最大値を取る一つの例である
# まじかよ...

n = int(input())
arr = list(map(int, input().split()))
over = 0
collection = [False for _ in range(8)]
for a in arr:
    c = a // 400
    if c >= 8:
        over += 1
    else:
        collection[c] = True
maximum = sum(filter(lambda x: x is True, collection)) + over
minimum = max(1, sum(filter(lambda x: x is True, collection)))
print(minimum, maximum)


Measured memory_bytes: 3060
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
#define FAST  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int 
#define ar array
#define pb push_back
//hash base 177013

double dist(pair<double,double> p)
{
	return sqrt((p.first)*(p.first)+(p.second*p.second));
}

int main()
{
	FAST;
	//#ifndef ONLINE_JUDGE
	//	freopen("input.txt","r",stdin);
	//	freopen("output.txt","w",stdout);
	//#endif
	//ll testcase;
	//cin>>testcase;
	//for(ll t=0;t<testcase;t++)
	{
		int n;double d;
		cin>>n>>d;
		vector<pair<double,double>> points(n);
		int ans=0;
		for(int i=0;i<n;i++)
		{
			cin>>points[i].first>>points[i].second;
			if(d-dist(points[i])>=0.000)
				ans++;
		}
		
		cout<<ans<<'\n';
							
	}
}


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

int main() {
  string record;
  int a_score, b_score;

  while(1) {
    a_score = 0;
    b_score = 0;
    cin >> record;
    if(record == "0") break; 
    
    for(int i = 1; i < 10; i++) {
      if(record[i] == 'A')
	a_score += 1;
      else
	b_score += 1;
    }
    for(int i = 10; i < record.length(); i++) {
      if(record[i] == 'A')
	a_score += 1;
      else
	b_score += 1;
      }
    if(a_score > b_score)
      cout << a_score+1 << ' ' << b_score << endl;
    else
      cout << a_score << ' ' << b_score+1 << endl;
  }
  return 0;
}


Measured memory_bytes: 3024
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 25
int a[MAXN],nxt[MAXN],n,Adj,cnt,pow[MAXN];
int main()
{
	scanf("%d",&n);
	pow[0]=1;
	for(int i=1;pow[i-1]<n;i++)
		pow[i]=pow[i-1]*2;
	while(n)
	{
		a[++a[0]]=n&1;
		if(n&1)
		{
			nxt[a[0]]=Adj;
			Adj=a[0];
			cnt++;
		}
		n>>=1;
	}
	printf("%d %d\n",a[0],cnt+2*(a[0]-1)-1);
	for(int i=1;i<a[0];i++)
	{
		printf("%d %d 0\n",i,i+1);
		printf("%d %d %d\n",i,i+1,pow[a[0]-i-1]);
	}
	for(int i=a[0],pre=0;nxt[i];i=nxt[i])
	{
		pre=pre+pow[i-1];
		printf("1 %d %d\n",a[0]-nxt[i]+1,pre);
	}
}

Measured memory_bytes: 256
#pragma GCC optimize (3, "Ofast", "inline")
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n, k;
int main() {
	cin >> n >> k;
	if(n <= k)
		cout << min(n, k - n) << endl;
	else {
		n %= k;
		cout << min(n, k - n) << endl;
	}
	return 0;
}

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

using namespace std;
using ll = long long;

#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define REP(i,n) FOR(i, 0, n)
#define FORD(i,a,n) for(int i=(a); i>=(n); i--)
#define REPD(i,n) FOR(i, n, 0)

#define ALL(o) (o).begin(), (o).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;

const ll MOD = 1000000007;

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

	while(a > 0 && c > 0) {
		c -= b;
		if(c <= 0) {
			cout << "Yes" << endl;
			break;
		}
		a -= d;
		if(a <= 0) {
			cout << "No" << endl;
			break;
		}
	}
}



Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

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

int GCD(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   if(_a % _b == 0){
      return _b;
   }
   else{
      return GCD(_b, _a % _b);
   }
}

int LCM(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   return (_a*_b)/(GCD(_a, _b));
}

int main(){
   string s;
   cin >> s;

   int ans = 0;
   for(int i = 0; i < 3; i++){
      if(s[i] == '1'){ans++;}
   }
   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 256
s = list(input())
t = list(input())
a = [[]*26]
#print(s)
#print(t)
cnt = 0
li = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
for i in range(26):
    s.append(li[i])
    #print(s)
    if s == t:
        cnt = cnt + 1
    del s[-1]
if cnt == 0:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 9080
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
const int Maxn=100;
vector<pair<int,int> > A,B;
bool used[Maxn+5];
int x[Maxn+5];
int N;
bool find(int i) {
	for(int k=0;k<B.size();k++)
		if(A[i].first<B[k].first&&A[i].second<B[k].second&&!used[k]) {
		used[k]=1;
		if(x[k]==-1||find(x[k])) {
			x[k]=i;
			return true;
		}
	}
	return false;
}
int main() {
	#ifdef LOACL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	scanf("%d",&N);
	for(int i=1;i<=N;i++) {
		int x,y;
		scanf("%d %d",&x,&y);
		A.push_back(make_pair(x,y));
	}
	for(int i=1;i<=N;i++) {
		int x,y;
		scanf("%d %d",&x,&y);
		B.push_back(make_pair(x,y));
	}
	int ans=0;
	memset(x,-1,sizeof x);
	for(int i=0;i<A.size();i++) {
		memset(used,0,sizeof used);
		if(find(i))ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

		static void solve() {
			Scanner sc = new Scanner(System.in);
			int n = sc.nextInt();
			String ans = "Yes";
			int check = 0;
			String[] array = new String[n];
			for(int i = 0;i<n;i++) {
				array[i] = sc.next();
			}
			sc.close();
			for(int i = 0;i<n-1;i++) {
				if(array[i].charAt(array[i].length()-1)!=array[i+1].charAt(0)) {
					ans = "No";
					break;
				}
						for(int j = i+1;j<n;j++) {
							if(array[i].equals(array[j])) {
								ans = "No";
								break;
							}
						}
						if("No".contentEquals(ans)) {
							break;
						}
				}
			System.out.println(ans);
			
		}
	public static void main(String[] args) {
		solve();

	}

}


Measured memory_bytes: 23764
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const S = (arg[0].split(" ")[0]).split("");
    const T = (arg[1].split(" ")[0]).split("");
    
    T.pop();
    
    console.log(S.join("") === T.join("") ? "Yes" : "No");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29624
#![allow(unused_macros)]

// cf. [Rustで競技プログラミングの入力をスッキリ記述するマクロ - Qiita](https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8)
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        N: usize,
    }
    let mut n = N;
    let mut sn = 0;
    while n > 0 {
        sn += n % 10;
        n /= 10;
    }
    println!("{}", if N % sn == 0 { "Yes" } else { "No" });
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }

ll mpow(ll x, ll n){ //x^n(mod mo) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % mo;
        x = x*x % mo;
        n = n >> 1;
    }
    return ans;
}

ll combi(ll n, ll r) {
  if(n < r || n < 0 || r < 0) return 0;
  if ( r * 2 > n ) r = n - r;
  ll dividend = 1;
  ll divisor  = 1;
  for ( ll i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    dividend %= mo;
    divisor  *= i;
    divisor %= mo;
  }
  return (dividend * mpow(divisor, mo-2)) % mo;
}

int main(){
    ll N, K;
    cin >> N >> K;
    for(ll i=1; i<=K; i++){
        /*if(i>N-K+1){
            cout << 0 << endl;
            continue;
        }*/
        cout << (combi(N-K+1, i)*combi(K-1,i-1)) % mo << endl;
    }

}


Measured memory_bytes: 256
func readIntList() -> [Int] {
    return readLine()!.split(separator: " ").map{Int($0)!}
}

func readInt() -> Int {
    return Int(readLine()!)!
}

func main() {
    let nk = readIntList()
    let aList = readIntList()
    for i in nk[1]+1...nk[0] {
        let diff = aList[i-1] - aList[i-nk[1]-1]
        print(diff > 0 ? "Yes" : "No")
    }
}

main()


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

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

int main() {
  int n, m, c;
  cin >> n >> m >> c;
  vector<int> b(m);
  rep(i, m) {
    int t;
    cin >> t;
    b[i] = t;
  }
  int ans = 0;
  rep(i, n) {
    int sum = c;
    rep(j, m) {
      int t;
      cin >> t;
      sum += t * b[j];
    }
    if (sum > 0) {
      ans++;
    }
  }
  cout << ans;
}

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

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
//#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	int n;
	cin >> n;
	vector<int>x, y, h;
	x = y = h = vector<int>(n);
	rep(i, n) {
		cin >> x[i] >> y[i] >> h[i];
	}
	bool findtop = false;
	rep(i, 101) {
		if (findtop)break;
		rep(j,101) {
			if (findtop)break;
			int maxheight = 0;
			int maxk = 0;
			rep(k, n) {
				if (h[k] > 0) {
					maxheight = h[k] + abs(x[k] - i) + abs(y[k] - j);
					maxk = k;
					break;
				}
			}
			rep(k, n) {
				if (h[k] != max((maxheight - abs(x[k] - i) - abs(y[k] - j)), 0))break;
				if (k == n - 1) {
					cout << i <<" "<< j<<" "<<  h[maxk] + abs(x[maxk] - i) + abs(y[maxk] - j);
					findtop = true;
				}
			}
		}
	}
}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int nx[26][400000];
int main(){
	int n;string s;cin>>n>>s;
	rep(i,10){
		nx[i][n]=n;
		for(int j=n-1;j>=0;j--){
			if(s[j]-'0'==i)nx[i][j]=j;
			else nx[i][j]=nx[i][j+1];
		}
	}
	int cnt=0;
	rep(i,10)rep(j,10)rep(k,10){
		int a=nx[i][0];
		if(a==n)continue;
		int b=nx[j][a+1];
		if(b==n)continue;
		int c=nx[k][b+1];
		if(c==n)continue;
		cnt++;
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 12928
#include<bits/stdc++.h>
using namespace std;
#define I_O		ios::sync_with_stdio(false),cin.tie(0)
#define ll		long long
#define ff		first
#define ss		second
#define mod 		1000000007
#define rep(i,n)	for(ll i=1;i<=n;i++)
#define repv(i,a,n)	for(ll i=a;i<=n;i++)
#define pb 		push_back
#define newl		'\n'
#define deb(x)		cout<<x<<" "
int main() 
{  
	I_O;
	int n;	cin>>n;
	ll a[n+1];	int l = 0;
	rep(i,n)
	{
		cin>>a[i];
		l = l^a[i];
	}
	rep(i,n)	cout<<(l^a[i])<<" ";
} 


Measured memory_bytes: 5180
def g(X):
    Y = 1 << 45
    ans = 0
    if ((X+1) // 2) % 2:
        ans ^= 1
    while Y > 1:
        if X >= Y:
            ans += ((X - Y + 1) & 1) * Y
            X -= Y
        Y >>= 1
    return ans
A, B = map(int, input().split())
print(g(B) ^ g(A-1))

Measured memory_bytes: 3064
N, = map(int, input().split())
tt, aa, bb = 0, 0, 0
for i in range(N):
    t, a, b = map(int, input().split())
    if abs(a-aa) + abs(b-bb) > t - tt or (abs(a-aa) + abs(b-bb) + t - tt) % 2 != 0:
        print("No")
        break
    tt, aa, bb = t, a, b
else:
    print("Yes")


Measured memory_bytes: 46568
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
LL a, b, c, d, n, up, dw;
bool flag;
int main(){
	scanf("%lld%lld%lld%lld%lld", &n, &a, &b, &c, &d);
	for(int i = 1; i <= n - 1; i++){
		up = a + i * d;
		dw = a + i * c;
		up = up - (n - i - 1) * c;
		dw = dw - (n - i - 1) * d;
	if(b <= up && b >= dw)flag = 1;
	}
	if(flag)printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 128
n = int(input())
abc = [tuple(map(int, input().split())) for _ in range(n)]
ans = [[0, 0, 0] for _ in range(n+1)]

for i in range(n):
    ans[i+1][0] = abc[i][0] + max(ans[i][1],ans[i][2])
    ans[i+1][1] = abc[i][1] + max(ans[i][0],ans[i][2])
    ans[i+1][2] = abc[i][2] + max(ans[i][1],ans[i][0])
print(max(ans[-1]))

Measured memory_bytes: 40236
#include <cstdio>
#include <cstring>
#include <queue>

using namespace std;

#define CHECK(X) (0<=(X)&&(X)<=9)

struct Pyon {
	int x,y;
	int next;
	Pyon(int _x,int _y,int _next);
};

Pyon::Pyon(int _x,int _y,int _next) {
	x=_x,y=_y,next=_next;
}

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

int main() {
	int park[10][10];
	int px,py,n;
	while(scanf("%d %d",&px,&py),px||py) {
		scanf("%d",&n);
		memset(park,0,sizeof(park));
		for(int i=1;i<=n;i++) {
			int sx,sy;
			scanf("%d %d",&sx,&sy);
			park[sx][sy]=i;
		}
		if(n==0) {printf("OK\n");continue;}
		queue<Pyon> que;
		que.push(Pyon(px,py,1));
		bool ok=false;
		while(!que.empty()) {
			Pyon p(que.front());que.pop();
			for(int i=0;i<12;i++) {
				int nx=p.x+dx[i],ny=p.y+dy[i];
				if(p.next==(n+1)) {ok=true;break;}
				for(int j=-1;j<=1;j++) {
					for(int k=-1;k<=1;k++) {
						if((j||k)&&CHECK(nx+j)&&CHECK(ny+k)) {
							if(park[nx+j][ny+k]==p.next) que.push(Pyon(nx,ny,p.next+1));
						}
					}
				}
			}
		}
		printf(ok?"OK\n":"NA\n");
	}
	return 0;
}

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

using namespace std;

#define PB push_back
#define MP make_pair
#define f first
#define s second
#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define RFOR(i, b, a) for (int i = b-1; i>=a; --i)
#define FILL(a, b) memset(a, b, sizeof a)
#define ALL(a) a.begin(), a.end()
#define SZ(a) ((int)a.size())

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

const int INF = 1000 * 1000 * 1000;
const LL LINF = 1LL * INF*INF;
const int MAX = 1e5;
const double PI = acos(-1.);
const double EPS = 1e-8;

int main()
{
	ios_base::sync_with_stdio(0);
	int a, b, k;
	cin >> a >> b >> k;

	FOR(IT, 0, k)
	{
		if (IT % 2 == 0)
		{
			if (a % 2)
			{
				--a;
			}
			b += a / 2;
			a /= 2;
		}
		else
		{
			if (b % 2)
			{
				--b;
			}
			a += b / 2;
			b /= 2;
		}
	}

	cout << a << " " << b << endl;

	return 0;
}













Measured memory_bytes: 256
def main(input):
    N = int(input())
    S = input().rstrip()
    ansE = [0] * N
    ansW = [0] * N

    if S[0] == "E":
        ansE[0] += 1
    for i in range(1, N):
        if S[i] == "E":
            ansE[i] = ansE[i-1] + 1
        else:
            ansE[i] = ansE[i-1]

    if S[-1] == "W":
        ansW[-1] += 1
    for i in range(N-2, -1, -1):
        if S[i] == "W":
            ansW[i] = ansW[i+1] + 1
        else:
            ansW[i] = ansW[i+1]
    ans = N - max(x + y for x, y in zip(ansE, ansW))
    print(ans)


import sys; sys.setrecursionlimit(50000)
if __name__ == "__main__":
    if len(sys.argv) > 1 and sys.argv[1] == "local":
        with open("stdin.txt") as stdin:
            main(stdin.readline)
    else:
        main(sys.stdin.readline)


Measured memory_bytes: 17608
/*
 * @Date: 2020-03-12 16:23:17
 * @LastEditors: BeckoninGshy
 * @LastEditTime: 2020-03-12 16:35:46
 */
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
const int maxn = 1e5+10;

int dp[maxn];
int arr[maxn];
int main(){
  int n,k;
  cin >> n >> k;
  arr[0] = 0x3f3f3f3f;
  memset(dp,0x3f3f3f3f,sizeof(dp));
  dp[1] = 0;
  for(int i = 1; i <= n; i++){
    cin >> arr[i];
  }
  for(int i = 2; i <= n; i++){
    for(int j = 1; j <= k; j++){
      if(i-j <= 0) continue;
      dp[i] = min(dp[i],abs(arr[i-j]-arr[i])+dp[i-j]);
    }
  }
  cout << dp[n];
  return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
#define iter(v,ite) for(auto ite=(v).begin();ite!=(v).end();ite++)
#define mimunum(v,x) distance((v).begin(),lower_bound((v).begin(),(v).end(),x))

int n,m,qn;

int vs[505][505]={};
int gone[505];

bool dfs(int no,int gl){
	if(no==gl)return true;
	gone[no]=1;
	reg(to,1,n){
		if(gone[to])continue;
		if(vs[no][to]>0){
			if(dfs(to,gl)){
				vs[no][to]--;
				vs[to][no]++;
				return true;
			}
		}
	}
	return false;
}

int main(void){
	scanf("%d%d%d",&n,&m,&qn);
	rep(i,m){
		int a,b;
		scanf("%d%d",&a,&b);
		vs[a][b]=vs[b][a]=1;
	}
	
	int nf=0;
	for(;;){
		memset(gone,0,sizeof(gone));
		if(dfs(1,n))nf++;
		else break;
	}
	rep(q,qn){
		int t,a,b;
		scanf("%d%d%d",&t,&a,&b);
		if(t==1){
			vs[a][b]=vs[b][a]=1;
			memset(gone,0,sizeof(gone));
			if(dfs(1,n))nf++;
		}
		else{
			int fr=-1,to;
			if(vs[a][b]==0){
				fr=a; to=b;
			}
			else if(vs[b][a]==0){
				fr=b; to=a;
			}
			vs[a][b]=vs[b][a]=0;
			if(fr>=0){
				memset(gone,0,sizeof(gone));
				if(!dfs(fr,to)){
					bool ok=true;
					memset(gone,0,sizeof(gone));
					ok &= dfs(n,to);
					memset(gone,0,sizeof(gone));
					ok &= dfs(fr,1);
					nf--;
				}
				memset(gone,0,sizeof(gone));
				if(dfs(1,n))nf++;
			}
			/*
			if(fr>=0){
				bool ok=true;
				memset(gone,0,sizeof(gone));
				ok &= dfs(n,to);
				memset(gone,0,sizeof(gone));
				ok &= dfs(fr,1);
				if(!ok){
					printf("%d (%d %d %d)\n",q,t,a,b);
					reg(i,1,n){
						reg(j,1,n)printf("%d%c",vs[i][j],j==n?'\n':' ');
					}
					if(!ok)return -1;
				}
				nf--;
				memset(gone,0,sizeof(gone));
				if(dfs(1,n))nf++;
			}
			*/
		}
		printf("%d\n",nf);
	}
	return 0;
	
}

Measured memory_bytes: 2200
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<functional>
using namespace std;

int main(void){

  int a,b,c,x;
  cin>>a>>b>>c>>x;
  int count=0;

  for(int i=0;i<=50;i++){
    for(int j=0;j<=50;j++){
      for(int k=0;k<=50;k++){
        if(500*i+100*j+50*k==x){
          if(i<=a && j<=b && k<=c){
            count++;
          }
        }
      }
    }
  }
 
  cout<<count<<endl;
}

Measured memory_bytes: 256
while True:
	a, op, b = list(input().split())
	a = int(a)
	b = int(b)
	if op == '+':
		r = a + b
	elif op == '-':
		r = a - b
	elif op == '*':
		r = a * b
	elif op == '/':
		r = a / b
	else :
		break
	print("%d"%r)


Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int N;
    cin >> N;
    V(P) towns(N);
    rep(i, N) {
        double x, y;
        cin >> x >> y;
        towns[i] = P(x, y);
    }

    vi a(N);
    rep(i, N) a[i] = i;

    double res = 0;
    double cnt = 0;
    do {
        cnt ++;
        double dis = 0;
        FOR(i, 1, N) {
            int p = a[i-1], n = a[i];
            dis += sqrt(pow(towns[n].fi-towns[p].fi, 2)+pow(towns[n].se-towns[p].se, 2));
        }
        res += dis;
    } while(next_permutation(ALL(a)));
    
    res /= cnt;
    cout << fixed << setprecision(8);
    cout << res << 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++)
using ll = long long;

int main(){
    int n, k;
    cin >> n >> k;
    int a[n],x=0,b[n];
    rep(i, n){
        b[i] = 0;
        cin >> a[i];
    }
    sort(a, a + n);
    rep(i, n)
    {
        if (i == 0)
            x++;
        if (a[i] > a[i - 1])
            x++;
        b[a[i]-1]++;
    }
    sort(b, b + n);
    //0 conti n-x times
    
    if (x<=k)
        cout << 0 << endl;
    else{
        int y = 0;
        rep(i,x-k){
            y += b[n - x + i];
        }
        cout << y << endl;
    }
}

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

int main(){
  int h,w;
  int n;
  vector<int> a(n);

  cin>>h>>w>>n;
  rep(i,n)
    cin>>a[i];
  
  vector<vector<int>> ans(h,vector<int>(w));
  int p = 0;
  rep(i,h)rep(j,w){
    if(!a[p]) p++;
    ans[i][j] = p + 1;
    a[p]--;
  }

  rep(i,h){
    if (i % 2 == 0)
      reverse(ans[i].begin(),ans[i].end());
  }

  rep(i,h){
    rep(j,w){
      cout<<ans[i][j];
      if(j != w-1)
        cout << " ";
    }
    cout <<endl;
  }
}

Measured memory_bytes: 3764
h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
ans = [[0 for x in range(w)] for y in range(h)]

def getx(i):
    return i // h
def gety(i):
    if (i % (2 * h)) < h:
        return i % h
    else:
        return h - i % h - 1

aa=[]
for i in range(n):
    aa += [i + 1 for _ in range(a[i])]

for i in range(h * w):
    ans[gety(i)][getx(i)] = aa[i]

for y in range(h):
    for x in range(w):
        if x > 0: print(' ', end='')
        print(ans[y][x], end='')
    print()

Measured memory_bytes: 4852
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




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

  int n,m;
  cin>>n>>m;
  
  vector<vector<int>> g(n);
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--;b--;
    g[a].pb(b);
  }

  int x=n+1;
  vector<int> ans;

  rep(i,n){
    vector<int> pre(n,-1);
    vector<int> dist(n,-1);
    deque<int> que;
    dist[i]=0;
    que.pb(i);

    while(!que.empty()){
      int v=que.front();
      que.pop_front();

      for(int nv : g[v]){
        if(dist[nv]!=-1) continue;
        dist[nv]=dist[v]+1;
        que.pb(nv);
        pre[nv]=v;
      }
    }

    rep(j,n){
      if(i==j||dist[j]==-1) continue;
      for(int k : g[j]) {
        if(k==i) {
          vector<int> ko={i};
          int z=j;
          while(z!=i){
            ko.pb(z);
            z=pre[z];
          }
          if(ko.size()<x){
            x=ko.size();
            ans=ko;
          }
        }
      }
    }
  }

  if(x==n+1) cout << -1 << endl;
  else {
    cout << x << endl;
    rep(i,ans.size()){
      cout << ans[i]+1 << endl;
    }
  }

}

Measured memory_bytes: 3684
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>

using namespace std;

//配列多めに確保しないと終わる！

int main(void)
{
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		int x, y;
		cin >> x >> y;
		int mata;
		cin >> mata;
		//[][][1]は左
		//[][][2]は下
		 vector<vector<vector<int> > > zahyo(x+2, vector<vector<int> >(y+2, vector<int>(3, 0)));
		 zahyo[1][1][0] = 1;

		int ax,ay,bx,by;
		for (int j = 0; j < mata; ++j)
		{
			cin >> ax >> ay>> bx >> by;
			if(ax == bx)	//x座標が等しい
			{
				if(by > ay)	//bがaよりy座標が大きい
					zahyo[bx+1][by+1][2]++;
				else	//aがbよりy座標が大きい
					zahyo[ax+1][ay+1][2]++;
			}else	//y座標が等しい
			{
				if(bx > ax)	//bがaよりx座標が大きい
					zahyo[bx+1][by+1][1]++;
				else	//aがbよりx座標が大きい
					zahyo[ax+1][ay+1][1]++;
			}
		}

		for (int k = 1; k <= x+1; ++k)
		{
			for (int l = 1; l <= y+1; ++l)
			{
				if(!(k == 1 && l == 1))
				{
					if(zahyo[k][l][1] > 0 && zahyo[k][l][2] > 0)
						zahyo[k][l][0] = 0;
					else if(zahyo[k][l][1] > 0 && zahyo[k][l][2] == 0)
						zahyo[k][l][0] = zahyo[k][l-1][0];
					else if(zahyo[k][l][2] > 0 && zahyo[k][l][1] == 0)
						zahyo[k][l][0] = zahyo[k-1][l][0];
					else
						zahyo[k][l][0] = zahyo[k-1][l][0] + zahyo[k][l-1][0];
				}
			}
		}

		if(zahyo[x+1][y+1][0] == 0)
			cout << "Miserable Hokusai!" << endl;
		else
			cout << zahyo[x+1][y+1][0] << endl;
	}

	return 0;
}


Measured memory_bytes: 3176
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, string
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
mod = 10**9+7
ans = 0 ;count = 0 ;pro = 1

n,m=map(int,input().split())
def factorial(n):
    result=1
    for ni in range(n,0,-1):
        result=result*ni%mod
    return result
    
if abs(n-m)>=2:
    print(0)
    exit()
if abs(n-m)==1:
    print(factorial(n)*factorial(m)%mod)
else:
    print(factorial(n)*factorial(m)*2%mod)


Measured memory_bytes: 38768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=3e5+13;
const int mod=1e9+7;
int a[maxn];
ll b[maxn];
int main()
{
   int n;
   scanf("%d",&n);
   for(int i=1;i<=n;i++)
   {
   	scanf("%d",&a[i]);
   }
   for(int i=1;i<=n;i++)
   {
   	b[i]=(b[i-1]+1ll*a[i])%mod;
   }
   ll ans=0;
   for(int i=1;i<=n;i++)
   {
   	ans+=1ll*a[i]*(b[n]-b[i]+mod)%mod;
   	ans%=mod;
   }
   printf("%lld",ans%mod);
 } 

Measured memory_bytes: 6120
# coding: utf-8
# Your code here!

A, B, K = map(int, input().split())
a1 = [_ for _ in range(A, min(A + K, B + 1))]
a2 = [_ for _ in range(max(A, B - K + 1), B + 1)]
s = sorted(set(a1 + a2))

for i in s: print(i)

Measured memory_bytes: 38384
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

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

const int N = 1e5 + 10, MX = 1e9;

int main() {
	fast_cin();
	int n, k, s;
	cin >> n >> k >> s;
	int t = (s == MX ? 1 : s + 1);
	for (int i = 0; i < n; ++i) {
		if (i < k) {
			cout << s << ' ';
		} else {
			cout << t << ' ';
		}
	}
	cout << endl;
}

Measured memory_bytes: 1280
#include <stdio.h>
#include <math.h>
int main(void){
    int n;
    double xa,ya,ra,xb,yb,rb,dis;
    scanf("%d",&n);
    while(n-- > 0){
        scanf("%lf %lf %lf %lf %lf %lf",
               &xa, &ya, &ra, &xb, &yb, &rb);
        dis = sqrt( (xa - xb)*(xa - xb) + (ya - yb)*(ya - yb) );
        if( dis + ra < rb ){
            puts("-2");
        }else if( dis + rb < ra ){
            puts("2");
        }else if( ra + rb >= dis ){
            puts("1");
        }else{
            puts("0");
        }
    }
    return 0;
}

Measured memory_bytes: 620
def main():
    S = input()
    N = len(S)

    for i in range(0,N):
        if S[i] != S[N-1-i]:
            print('No')
            return
    
    for i in range(0,int((N-1)/2)):
        if S[i] != S[int((N-1)/2)-1-i]:
            print('No')
            return

    for i in range(int((N+3)/2)-1,N):
        if S[i] != S[N-1-i]:
            print('No')
            return

    print('Yes')

main()

Measured memory_bytes: 38384
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <sstream>
#include <fstream>
#include <climits>
#include <map>
#include <numeric>
#include <functional>
#include <utility>

using namespace std;

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

bool isok(const vector<vector<int> > & tbl, const vector<int> & men) {
  for (int i = 0; i < men.size(); ++i) {
    if (men.at(i)) {
      for (int j = 0; j < men.size(); ++j) {
        if (tbl.at(i).at(j) == 0 && men.at(j) == 1 || tbl.at(i).at(j) == 1 && men.at(j) == 0) {
          return false;
        }
      }
    }
  }

  return true;
}

void dfs(const vector<vector<int> >& tbl, vector<int> men, int idx, int* pMax) {
  if (idx == men.size()) {
    if (isok(tbl, men)) {
      int num = accumulate(men.begin(), men.end(), 0);
      *pMax = max(*pMax, num);
    }
    return;
  }

  men.at(idx) = 0;
  dfs(tbl, men, idx + 1, pMax);

  men.at(idx) = 1;
  dfs(tbl, men, idx + 1, pMax);
}

int main(void) {
  const int nmax = 15;
  int n;
  cin >> n;

  vector<vector<int> > tbl(nmax);
  for (int i = 0; i < nmax; ++i) {
    for (int j = 0; j < nmax; ++j) {
      tbl.at(i).push_back(-1);
    }
  }

  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    for (int j = 0; j < a; ++j) {
      int x, y;
      cin >> x >> y;
      tbl.at(i).at(x - 1) = y;
    }
  }

  vector<int> men(n, 0);

  int ans = 0;
  dfs(tbl, men, 0, &ans);
  cout << ans << endl;

  return 0;
}

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

int main() {
 int A, B, C, D;
 cin >> A >> B >> C >> D;
 if (C < B ){
   cout << "Yes" << endl;
 } 
 else if (C /B == A /D +1 && C%B ==0){
   cout << "Yes" << endl;
 }
  else if (C /B > A /D  ||( C /B == A /D +1 && C%B !=0)){
   cout << "No" << endl;
 }
 else if(C /B < A /D){
   cout << "Yes" << endl;
 }
  else if (C /B == A /D && A % D==0 && C%B!=0){
 cout << "No" << endl;
  } else {cout << "Yes" << endl;}
   
}




Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define ll long long
int main()
{
	std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	// ll tt;	cin>>tt;	while(tt--)
	{
		ll n,i;
		cin>>n;
		
		bool flag=false;
		while(n)
		{
			if(n%10==7)	flag=true;
			n/=10;
		}

		cout<<(flag ? "Yes" : "No")<<endl;
 	
 	}
	cerr<<" Execution : "<<(1.0*clock())/CLOCKS_PER_SEC<<"s \n";
		
		
return 0;
}

Measured memory_bytes: 3792
#include <iostream>
#include <cstdio>
#include <algorithm>
#define M 2009
using namespace std;
int n,x,y,d[M];
inline int abss(int a){return a>=0?a:-a;}
int main(){
  scanf("%d%d%d",&n,&x,&y);
  for(int i = 1; i <= n; i++)
    for(int j = i+1; j <= n; j++){
      int a = abss(i-j), b = abss(i-x), c = abss(j-y);
      int tmp = min(a,b+1+c);
      d[tmp]++;
    }
  for(int i = 1; i < n; i++) printf("%d\n",d[i]);
  return 0;
}

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

int main(){
	int N;
	int a=0,b=0,c=0;

	cin >> N ;

	for(int i=0;i<N;i++){

		cin >> a >> b >> c;

		if (a*a + b*b == c*c || b*b + c*c == a*a || c*c + a*a == b*b){
			cout << "YES" << endl;
		}	
		else{
			cout << "NO" << endl;
		}
	}

}

Measured memory_bytes: 0
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<limits>
#include<string.h>
#include<vector>
#include<stack>
#include<queue>
using namespace std;

int main()
{
    int a;
    cin>>a;
    if (a>=30)
    {
        cout<<"Yes"<<endl;
    }else
    {
        cout<<"No"<<endl;
    }
    
    

    return 0;
}

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

int N;

struct edge{
  int to,c;
  bool operator<(const edge& e ) const{
    return c > e.c;
  }
};
vector<edge> G[111];
string S[111];
string X[111];
int dijk(){
  priority_queue<edge> q;
  int H[111];
  fill( H,H+N+1, (1<<29) );
  q.push( (edge){0,0} );
  H[0] = 0;
  while( !q.empty() ){
    edge p = q.top(); q.pop();
    for(int i=0;i<(int)G[p.to].size();i++){
      edge e = G[p.to][i];
      if( H[e.to] > p.c + e.c ){
        H[e.to] = p.c+e.c;
        q.push( (edge){e.to,p.c+e.c} );
      }
    }
  }
  return H[N];
}
int main(){
  cin >> N;
  for(int i=0;i<N;i++){
    string s1,s2;
    cin >> s1;
    if( s1 == "goto" ) {
      cin >> s2;
      X[i] = s2.substr(0,s2.size()-1);
    }
    else S[i] = s1.substr(0,s1.size()-1);
  }
  for(int i=0;i<N;i++){
    if( X[i] != "" ){
      for(int j=0;j<N;j++){
        if( X[i] == S[j] ) G[i].push_back( (edge){j,0} );
      }
      G[i].push_back( (edge){i+1,1} );
    } else
      G[i].push_back( (edge){i+1,0} );
  }

  cout << dijk() << endl;
  
}

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

int main(){
  int x,a,b;
  cin >> x >> a >> b;
  
  int xa=x-a, xb=x-b;
  if(abs(xa) < abs(xb)){
    cout << "A" << endl;
  }else{
    cout << "B" << endl;
  }
}

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

ll digit(ll a) {
  string s = to_string(a);
  return (ll)s.length();
}

int main(){
  ll n;
  cin >> n;
  ll ans = INF;
  for(ll i = 1; i*i <= n; i++) {
    if(n % i == 0) {
      ans = min(ans,max(digit(i),digit(n/i)));
    } 
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import math


def isPrime(num):
    if num < 2:
        return False
    elif num == 2:
        return True
    elif num % 2 == 0:
        return False

    for i in range(3, math.floor(math.sqrt(num))+1, 2):
        if num % i == 0:
            return False

    return True


def callIsPrime(input_num=1000):
    numbers = []
    for i in range(1, input_num):
        if isPrime(i):
            numbers.append(i)

    return numbers


n = int(input())
pms = callIsPrime(55555)

ret = []

for item in pms:
    if item % 5 == 1:
        ret.append(item)

print(" ".join(map(str, ret[:n])))


Measured memory_bytes: 3188
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

int n,cyc,nxt[500111],nxt2[500111];
char s[500111];
void getnext(int *nxt)
{
	int j=0;
	for(int i=2;i<=n;i++)
	{
		while(j&&s[i]!=s[j+1])j=nxt[j];
		if(s[i]==s[j+1])j++;
		nxt[i]=j;
	}
}
bool check(int*nxt,int x)
{
	if(nxt[x]==0)return false;
	return (x%(x-nxt[x])==0);
}
int main()
{
	scanf("%s",s+1);n=strlen(s+1);
	getnext(nxt);
	if(!check(nxt,n))puts("1\n1");
	else if(nxt[n]==n-1)printf("%d\n1\n",n);
	else
	{
		reverse(s+1,s+n+1);
		getnext(nxt2);
		int ans=0;
		for(int i=1;i<n;i++)ans+=(check(nxt,i)|check(nxt2,n-i))^1;
		printf("2\n%d\n",ans);
	}
	return 0;
}

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

int main() {
    ll x,n,d,y;
    string str;
    cin>>n;
    cin>>str;
    ll cntr=0;
    for(int i=0;i<n;i++){
        if(str[i]=='R') cntr++;
    }
    ll cntw=0;
    for(int i=0;i<cntr;i++){
        if(str[i]=='W') cntw++;
    }
    cout<<cntw;
}

Measured memory_bytes: 3748
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <cmath>
using namespace std;

int main() {
	int N;
	cin >> N;
	
	if (N % 2 == 1) {
		N++;
	}

	cout << N / 2 << endl;

	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>
//#include<bits/stdc++.h>


using namespace std;




int main() {
	
	int n;
	cin>>n;
	cout<<(1+n)*n/2<<endl;


    return 0;
}

	
	


	

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

using namespace std;

int main(){
  int n;
  vector<int> v,c;

  cin >> n;
  for(int i=0; i<n; i++){
    int temp;
    cin >> temp;
    v.push_back(temp);
  }

  for(int i=0; i<n; i++){
    int temp;
    cin >> temp;
    c.push_back(temp);
  }

  int ans = 0;
  for(int i=0; i<n; i++){
    if(v.at(i) - c.at(i) > 0){
      ans += v.at(i) - c.at(i);
    }
  }

  cout << ans;
}


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

const int INF = 1e9;

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, k;
	while (cin >> n >> k, n | k) {
		vector<vector<int>> d(n, vector<int>(n, INF));
		for (int i = 0; i < n; i++) d[i][i] = 0;
		while (k--) {
			int t, a, b;
			cin >> t >> a >> b; a--, b--;
			if (t == 0) {
				printf("%d\n", d[a][b] == INF ? -1 : d[a][b]);
			}
			else {
				int e;
				cin >> e;
				d[a][b] = d[b][a] = min(d[a][b], e);
				for (int i = 0; i < n; i++) {
					for (int j = 0; j < n; j++) {
						d[i][j] = min(d[i][j], d[i][a] + d[a][j]);
					}
				}
				for (int i = 0; i < n; i++) {
					for (int j = 0; j < n; j++) {
						d[i][j] = min(d[i][j], d[i][b] + d[b][j]);
					}
				}
			}
		}
	}
	return 0;
}



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

#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))

#define DIVUP(x, y) (((x) + ((y) - 1)) / (y))
#define DIVOFF(x, y) (((x) + ((y) / 2)) / (y))
#define REMAINDER(x, y) ((x) % (y))

char S[50][50 + 1];

int nx[] = { 0, -1,  1,  0};
int ny[] = {-1,  0,  0,  1};

int main() {
  int H, W; scanf("%d%d", &H, &W);
  for (int i{}; i < H; ++i) scanf("%50s", &S[i]);



  for (int x{}; x < H; ++x) {
    for (int y{}; y < W; ++y) {
      if (S[x][y] != '#') continue;
      bool found{};
      for (int i{}; i < 4; ++i) {
        int xx = x + nx[i];
        int yy = y + ny[i];
        if (xx < 0 || yy < 0) continue;
        if (S[xx][yy] == '#') {
          found = true;
          break;
        }
      }
      if (!found) {
        printf("No\n");
        return 0;
      }
    }
  }

  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 256
H, W, D = map(int, input().split())
Aindex = [0] * (H*W)
for h in range(H):
    w = 0
    for A in input().split():
        Aindex[int(A)-1] = (h,w)
        w += 1 

import numpy as np
v, h = int(np.ceil(H*W/D)), D
Mp = np.zeros((v, h), dtype='int64') #MpをMod D別に計算する予定
mp = lambda X, Y: abs(X[0]-Y[0]) + abs(X[1]-Y[1]) #魔力計算する関数
for x in range(D,H*W):
    i, j = divmod(x, D)
    Mp[i,j] = mp(Aindex[x], Aindex[x-D])
#縦軸方向に累積和を取っておき、後のクエリにO(1)で対応
Mp = Mp.cumsum(axis=0)

#クエリ処理
Q = int(input())
Query = [tuple(map(int, input().split())) for _ in range(Q)]
for l,r in Query:
    ans = Mp[divmod(r-1, D)] - Mp[divmod(l-1, D)]
    print(ans)

Measured memory_bytes: 48664
#include<bits/stdc++.h>
using namespace std;
int main()
{
        ios_base::sync_with_stdio(false);
        char ch[101];
        cin>>ch;
        int i,j=0,l,c=0;
        l=strlen(ch);
        char str[l],s[l];
        strcpy(str,ch);
        for(i=l-1;i>=0;i--)
        {
            s[j]=str[i];
            j++;
        }
        for(i=0;i<l;i++)
        {
            if(str[i]!=s[i])
                c++;
        }
        cout<<c/2<<endl;
    return 0;
}



Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#include <math.h>
int main(void){
	int a,b,i,j,k,c;
	while(1){
		c=0;
		scanf("%d %d",&a,&b);
		if(a==0&&b==0) return 0;
		for(i=1;i<=a-2;i++){
			for(j=i+1;j<=a-1;j++){
				for(k=j+1;k<=a;k++){
					if(i+j+k==b){
						c++;
						//printf("%d %d %d\n",i,j,k);
					}
				}
			}
		}
		printf("%d\n",c);
	}
	return 0;
}


Measured memory_bytes: 2104
#include<iostream>
#include<cmath>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define int64 long long
#define yokuwaruprime (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  int64 n;
  cin>>n;
  int64 a[n];
  rep(i,n){
    cin>>a[i];
  }
  sort(a,a+n);
  int64 pos=0,maximum=a[n-1];
  rep(i,n-1){
    if(a[i]<=maximum/2 && a[i+1]>maximum/2){
      pos=i;
    }
  }
  int64 ans;
  if(pos!=n-2){
  if(abs(a[pos]-maximum/2)>=abs(a[pos+1]-maximum/2)){
    ans=a[pos+1];
  }else{
    ans=a[pos];
  }
  cout<<maximum<<" "<<ans<<endl;
  }else{
  cout<<maximum<<" "<<a[n-2]<<endl;
  }
}


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

int main() {
    string S;
    cin >> S;
    if(stoi(S.substr(0,4))<2019) cout << "Heisei\n";
    else if (stoi(S.substr(0,4))==2019) {
        if (stoi(S.substr(5,2))<4) cout << "Heisei\n";
        else if (stoi(S.substr(5,2))==4) {
            if (stoi(S.substr(8,2))<=30) cout << "Heisei\n";
            else cout << "TBD\n";
        }
        else cout << "TBD\n";
    }
    else cout << "TBD\n";
}

Measured memory_bytes: 256
import numpy as np
 
n, m = map(int, input().split(' '))
a = []; b = []
for nn in range(n):
    ls = list(map(int, input().split(' ')))
    a.append(ls[0])
    b.append(ls[1])

a = np.array(a)
b = np.array(b)

ind = np.argsort(a)
a = a[ind]
b = b[ind]
    
amount = 0
count = 0
for i in range(len(a)):
    amount += min(b[i], m - count) * a[i]
    count += b[i]
    if count >= m:
        break
 
print(amount)

Measured memory_bytes: 20796
#include<stdio.h>
int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if((a==b&&a!=c)||(a==c&&a!=b)||(b==c&&b!=a))
		printf("Yes");
	else
		printf("No");
	return 0;
}

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

int main() {
  int N,i,r,count=0;
  cin >> N;
  
  int k=0;
  while(k<N){
    cin >> i >> r ;
    
    for(int j=i ; j<=r ; j++){
    count +=1;
    }
    k++;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
//
int main() {
	while(true){
		int L,a[10];
		cin >> L ;
		if(L==0) break;
		for(int i=0;i<9;i++){
			cin >> a[i];
		}
		for(int i=0;i<9;i++){
			L=L-a[i];
		}
		cout << L << endl;
		// your code goes here
	}
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<algorithm>
using namespace std;
int N_MAX=100;
int main()
{
  int n,i,s=0,t=0,res;
  int a[N_MAX],b[N_MAX];
  cin >> n;
  for(i=0;i<n;i++){
    cin >> a[i];
    s+=a[i];
    if(i>0)
      t+=a[i];
  }
  for(i=0;i<n;i++){
    cin >> b[i];
    s+=b[i];
  }
  res=t;
  for(i=1;i<n;i++){
    t+=b[i-1]-a[i];
    res=min(res,t);
  }
  res=s-res;
  cout << res << endl;
  return 0;
}

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

using namespace std;
using ll = long long;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long H, long long W, long long D, std::vector<std::vector<long long>> A, long long Q, std::vector<long long> L, std::vector<long long> R){
  vector<pair<ll, ll>> m(H*W+1);
  vector<ll> f(H*W+1);
  for(ll i=0; i<H; i++) {
    for(ll j=0; j<W; j++) {
      m[A[i][j]] = make_pair(i, j);
    }
  }
  for(ll i=1; i<=D; i++) {
    for(ll j=1; j*D+i<=H*W; j++) {
      ll now = j*D+i;
      ll prev = (j-1)*D+i;
      f[now] = f[prev]+abs(m[prev].first-m[now].first)+abs(m[prev].second-m[now].second);
    }
  }
  for(ll i=0; i<Q; i++) {
    std::cout << f[R[i]]-f[L[i]] << std::endl;
  }
}

int main(){
  long long H;
  scanf("%lld",&H);
  long long W;
  scanf("%lld",&W);
  long long D;
  scanf("%lld",&D);
  std::vector<std::vector<long long>> A(H, std::vector<long long>(W));
  for(int i = 0 ; i < H ; i++){
    for(int j = 0 ; j < W ; j++){
      scanf("%lld",&A[i][j]);
    }
  }
  long long Q;
  scanf("%lld",&Q);
  std::vector<long long> L(Q);
  std::vector<long long> R(Q);
  for(int i = 0 ; i < Q ; i++){
    scanf("%lld",&L[i]);
    scanf("%lld",&R[i]);
  }
  solve(H, W, D, std::move(A), Q, std::move(L), std::move(R));
  return 0;
}


Measured memory_bytes: 5504