akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main(){
	int N;
	int a, b, c, d;
	cin >> N;
	a = N / 1000;
	b = (N / 100) % 10;
	c = (N / 10) % 10;
	d = N % 10;
	if(((a==b)&&(b==c))||(b==c)&&(c==d)) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


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

int main(){
	int W,H,x,y,r;
	cin >> W >> H >> x >> y >> r;
	if(0+r<=x && x<=W-r && 0+r<=y && y<=H-r)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 1160
n=int(input())
h=[0]+list(map(int,input().split()))+[0]
ans=0
while h!=[0]*(n+2):
  for i in range(1,n+2):
    if h[i-1]==0 and h[i]!=0:ans+=1
    if h[i-1]:h[i-1]-=1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10;
char m[MAXN][MAXN];
int h, w;
int dx[] = {0,1};
int dy[] = {1,0};
void dfs( int x, int y ){
    m[x][y] = 'V';
    for( int i = 0 ; i < 2 ; ++i ){
        if( x+dx[i] >= 0 && x+dx[i] < h && y+dy[i] >= 0 && y+dy[i] < w && m[x+dx[i]][y+dy[i]] == '#' ){
            dfs( x+dx[i], y+dy[i] );
            break;
        }
    }
}
int main(){

    cin >> h >> w;

    for( int i = 0 ; i < h ; ++i ){
        for( int j = 0 ; j < w ; ++j ){
            cin >> m[i][j];
        }
    }

    dfs(0,0);
    bool x = true;
    for( int i = 0 ; i < h ; ++i ){
        for( int j = 0 ; j < w ; ++j ){
            if( m[i][j] == '#' ) x = false;
        }
    }
    cout << ( x ? "Possible\n" : "Impossible\n" ) ;

}


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

using namespace std;
using namespace __gnu_cxx;

typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;

#define F          first
#define S          second
#define pnl        printf("\n")
#define sz(x)      (int)x.size()
#define sf(x)      scanf("%d",&x)
#define pf(x)      printf("%d\n",x)
#define all(x)     x.begin(),x.end()
#define rall(x)    x.rbegin(),x.rend()
#define rep(i, n)  for(int i = 0; i < n; ++i)

const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;

int n, m;
vector<int> adj[100005];
int dp[100005];

int solve(int u) {
    int &ret = dp[u];
    if (~ret) return ret;
    ret = 0;
    for (auto v : adj[u])
        ret = max(ret, solve(v) + 1);
    return ret;
}

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; ++i) {
        int u, v;
        scanf("%d%d", &u, &v);
        adj[u].push_back(v);
    }
    memset(dp, -1, sizeof dp);
    int ans = 0;
    for (int i = 1; i <= n; ++i)
        ans = max(ans, solve(i));
    printf("%d\n", ans);
    return 0;
}


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

#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex <ld> cd;
typedef vector <cd> vcd;
typedef vector <int> vi;

template<class T> using v2d = vector <vector <T> >;
template<class T> bool uin(T &a, T b)
{
    return a > b ? (a = b, true) : false;
}
template<class T> bool uax(T &a, T b)
{
    return a < b ? (a = b, true) : false;
}

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 1;

int n;
vi adj[maxN];

pair <int, int> dg[maxN];

map <pair<int, int>, int> mp;

int flag[maxN];

int rs = 0;

void DFS(int u)
{
    flag[u] = 1;
    int idx = 0;
    for (auto &v: adj[u])
    {
        if (mp[make_pair(u, v)] || mp[make_pair(v, u)])
        {
            idx = mp[make_pair(u, v)];
        }
    }
    int id = 1;
    for (auto &v: adj[u])
    {
        if (id == idx)
        {
            ++id;
        }
        if (!flag[v])
        {
            mp[make_pair(u, v)] = mp[make_pair(v, u)] = id;
            uax(rs, id);
            ++id;
            DFS(v);
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    for1(i, n - 1)
    {
        int u, v;
        cin >> u >> v;
        adj[u].eb(v);
        adj[v].eb(u);
        dg[i] = make_pair(u, v);
    }
    DFS(1);
    cout << rs << '\n';
    for1(i, n - 1)
    {
        cout << mp[dg[i]] << '\n';
    }
    return 0;
}


Measured memory_bytes: 20736
// Problem : A - Two Abbreviations
// Contest : AtCoder Grand Contest 028
// URL : https://atcoder.jp/contests/agc028/tasks/agc028_a
// Memory Limit : 1024.000000 MB 
// Time Limit : 2000.000000 milisec 
// Powered by CP Editor (https://github.com/coder3101/cp-editor2)

//Dragon_warrior7(IITK)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define deb(x) cout << #x << " " << x << "\n"
#define pll pair<ll, ll> 
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}

void print(vector<ll> v)
{
	for (int i = 0; i < v.size(); i++)
		cout << v[i] << " ";
}
ll n,m,a,b,temp,x,y;
string str;
set<ll> s;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
   cin>>n>>m;
   string s,t;
   cin>>s>>t;
   rev(s);
   rev(t);
   s.pb('@');
   t.pb('@');
   rev(s);
   rev(t);
   if(n==m)
   {
      if(s==t)
      {
         cout<<n;
      }
      else
      cout<<-1;
      return 0;
   }
   if(s.size()>t.size())
   swap(s,t);
   n=s.size();
   m=t.size();
   n--;
   m--;
   for(int i=1;i<=n;i++)
   {
      if((m*(i-1))%n!=0)
      continue;
      if(s[i]!=t[(m*(i-1))/n+1])
      {cout<<-1;return 0;}
   }
   cout<<((m)*(n))/__gcd(m,n);
	
}

Measured memory_bytes: 640
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n,m=INTM()
    if n==m:
        print('Yes')
    else:
        print('No')
if __name__ == '__main__':
    do()

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

int main() {
  long long n, a, b;
  cin >> n >> a >> b;
  long long c = n / (a + b);
  long long d = n % (a + b);
  long long blue = c * a;
  if(d < a) blue += d;
  else blue += a;
  cout << blue << endl;
}

Measured memory_bytes: 3636
use std::collections::HashSet;
use std::collections::VecDeque;

fn main() {
  fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
  }
  fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
  }
  fn solve(k: usize, mut sushis: Vec<(u32, u32)>) -> u64 {
    let mut ans = 1;
    sushis.sort_by(|a, b| b.1.cmp(&a.1));

    let mut point: u64 = 0;
    let mut types: u64 = 0;
    let mut type_set:HashSet<u32> = HashSet::new();
    let mut kabri_stack: Vec<u32> = Vec::new();
    let mut kouho_que: VecDeque<u32> = VecDeque::new();

    for i in 0..k {
      point += sushis[i].1 as u64;
      if type_set.contains(&sushis[i].0) {
        kabri_stack.push(sushis[i].1);
      } else {
        type_set.insert(sushis[i].0);
        types += 1;
      }
    }
    ans = point + types * types;
    for i in k..sushis.len() {
      if !type_set.contains(&sushis[i].0) {
        kouho_que.push_back(sushis[i].1);
        type_set.insert(sushis[i].0);
      }
    }
    while !kabri_stack.is_empty() && !kouho_que.is_empty() {
      point -= kabri_stack.pop().unwrap() as u64;
      point += kouho_que.pop_front().unwrap() as u64;
      types += 1;
      let temp = point + types * types;
      if temp > ans {
        ans = temp;
      }
    }
    ans
  }

  let line: Vec<usize>  = read_vec::<usize>();
  let (n, k) = (line[0], line[1]);
  let mut sushis = Vec::new();
  for _ in 0..n{
    let line: Vec<u32>  = read_vec::<u32>();
    sushis.push((line[0], line[1]));
  }
  println!("{}", solve(k, sushis));
}



Measured memory_bytes: 8444
#include<stdio.h>
#include<math.h>
#include<string.h>
int main(){
    int a[6],flag=0;
    for(int i=0;i<7;i++){
        scanf("%d",&a[i]);
    }
    for (int i=0;i<4;i++){
        for(int k=1;k<5;k++){
            if((a[k]-a[i])>a[5])flag=1;
        }
    }
    if(flag==1)printf(":(");
    else printf("Yay!");
return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,l;
  string s[256];
  cin>>n>>l;
  for(int i=0;i<n;i++){
    cin>>s[i];
  }
  sort(s,s+n);
  for(int i=0;i<n;i++){
    cout<<s[i];
  }
  return 0;
}


Measured memory_bytes: 256
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n)cin >> a[i];
  int res = 0;
  bool flag = true;
  while(flag){
    flag = false;
    for(int j = n - 1; j > 0; j--){
      if(a[j] < a[j-1]){
        flag = true;
        res++;
        swap(a[j], a[j-1]);
      }
    }
  }
  rep(i, n){
    cout << a[i];
    if(i + 1 == n)cout << endl;
    else cout << " ";
  }
  cout << res << endl;
	return 0;
}



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

int main() {
    int N, A, B;
    cin >> N >> A >> B;

    if ((B - A) % 2 == 0) {
        cout << "Alice" << endl;
    }
    else if ((B - A) % 2 == 1) {
        cout << "Borys" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef long long ll;
const int N = 505, M = 3e4;
ll n, k, a[N], sum, ans;
bool check(ll x)
{
	vector<ll> vec;
	for(int i=0; i<n; i++) vec.push_back(a[i]%x);
	sort(vec.begin(), vec.end());
	ll l = 0, r = vec.size()-1, cnt = 0;
	while(l < r)
	{
		if(!vec[l]) {l++; continue;}
		int q = vec[l], p = x-vec[r];
		if(q == p) cnt += q, l++, r--;
		if(q > p) cnt += p, vec[l] -= p, r--;	
		if(q < p) cnt += q, vec[r] += q, l++;
	}
	if(cnt <= k) return 1;
	return 0;
}
		
int main() 
{
	cin >> n >> k;
	for(int i=0; i<n; i++) cin >> a[i], sum += a[i];
	vector<ll> vec;
	for(ll i=1; i*i<=sum; i++)
	{
		if(sum % i == 0)
		{
			vec.push_back(i);
			if(sum/i != i) vec.push_back(sum/i);
		}
	}
	for(auto fac : vec) if(check(fac)) ans = max(ans, fac);
	cout << ans << endl;
}

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

int main() {
  int H, W;
  int D = 0;
  unsigned long int x =0;
  string S;
  cin >> H >> W;
  
  for (int i=0; i<H; i++) {
    cin >> S;
    cout << S << endl;
    cout << S << endl;
  }
  
}

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

int a, b, c;

int main() {
	cin >> a >> b >> c;
	if ((a == b && b != c) || (a == c && c != b) || (b == c && c != a)) {
		puts("Yes");
	}
	else {
		puts("No");
	}

	return 0;
}

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

int main() {
	int n, k;
	while (cin >> n >> k) {
		if (n == 0 && k == 0) break;
		vector<ll> a(n + 1);
		rep(i, n) {
			int x;
			cin >> x;
			a[i + 1] = a[i] + x;
		}
		ll mx = 0;
		for (int i = 0; i <= n - k; i++) mx = max(mx, a[k + i] - a[i]);
		cout << mx << endl;
	}
	return 0;
}


Measured memory_bytes: 3648
str = input()
abc = ['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','aa']
i = 0
while abc[i] in str:
    if i < 26:
        i += 1
    else:
        break

if i < 26:
    print(abc[i])

else:
    print("None")


Measured memory_bytes: 3188
#include<iostream>
using namespace std;
int main(){
	int n, cnt;
	bool prime[1000000] = {false};
	prime[1] = true; //1???????????\	
	
	while(cin >> n){	
		// ??¨??????????????????????????????
		for(int j = 2; j*j <= n; j++){
			if(prime[j] == false){
				for(int k = j; k*j <= n; k++){
					prime[j*k] =true;
				}
			}
		}
		cnt = 0;
		for(int i = 1; i <= n; i++){
			if(prime[i] == false) cnt++;
		}
		
		cout << cnt << endl;
	}
}

Measured memory_bytes: 4060
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<ll> v(n,0);
    rep(i,n) cin >> v[i];
    ll ans = 0;
    rep(i,2){
        ll now = 0;
        ll sum = 0;
        rep(j,n){
            if(i == 0){
                sum += v[j];
                if(j%2 == 0){
                    //正にしたい
                    if(sum <= 0){
                        now += 1 - sum;
                        sum = 1;
                    }
                }else{
                    //負にしたい
                    if(sum >= 0){
                        now += sum + 1;
                        sum = -1;
                    }
                }
            }else{
                sum += v[j];
                if(j%2 == 0){
                    if(sum >= 0){
                        now += sum + 1;
                        sum = -1;
                    }
                }else{
                    if(sum <= 0){
                        now += 1 - sum;
                        sum = 1;
                    }
                }
            }
        }
        if(i == 0) ans = now;
        else ans = min(ans,now);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4028
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que) priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int>> Matrix;
const int MOD = 1e9 + 7;
const int MAX = 1e7;
const int INF = numeric_limits<int>::max();


int main(){
 string s,t,u;
 int a, b;
 cin >> s >> t >>a>>b>>u;
 if(u==s)
   a--;
  else
    b--;

 cout << a << ' ' << b << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	  
	public static void main(String args[]) {
		    Scanner scanner = new Scanner(System.in);
		   
		    String a = scanner.next();
		    String b = scanner.next();
		    int c = Integer.parseInt(a + b);
		    
		    if( (int)Math.sqrt(c) * (int)Math.sqrt(c) == c ) 
		    {
		    	System.out.println("Yes");
		    }
		    else 
		    {
		    	System.out.println("No");
		    }
		    
		    scanner.close(); }
		  }

Measured memory_bytes: 23764
import java.util.*;

public class Main {

    static final int MOD = 1000000007;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        char[] str = sc.next().toCharArray();
        char[] ACGT = {'A','C','G','T'};
        for(int i=0;i<str.length;i++){
            for(Character d:ACGT){
                if(str[i]==d){
                    str[i]='A';
                    break;
                }
            }
        }

        int ans = 0;
        int now = 0;
        for(Character c:str){
            if(c=='A'){
                now++;
                ans = Math.max(ans,now);
            }
            else{
                ans = Math.max(ans,now);
                now = 0;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21972
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int n = int.Parse(s);

            for (int i = 1; i <= n; i++)
            {
                if (i % 3 == 0)
                {
                    Console.Write(" " + i);
                }
                else
                {
                    for (int x = i; x > 0; x /= 10)
                    {
                        if (x % 10 == 3)
                        {
                            Console.Write(" " + i);
                            break;
                        }
                    }
                }

            }
            Console.Write("\n");

        }
    }
}

Measured memory_bytes: 5816
# coding: utf-8
# Here your code !
N = int(input())
data = list(map(int, input().split()))
M = int(input())
drink = [list(map(int, input().split())) for i in range(M)]
S = 0
for i in range(N):
    S += data[i]
for i in range(M):
    print(S - (data[drink[i][0] - 1] - drink[i][1]))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  vector<int>B(N);
  for(int i=0;i<N;i++)
    cin>>B.at(i);
  vector<int>A;
  bool ans=true;
  for(int i=0;i<N;i++){
  int M=B.size();
    bool x=false;
    
    for(int j=M-1;0<=j;j--)
    if(B.at(j)-j==1){
    x=true; A.push_back(B.at(j));
      B.erase(B.begin()+j);
      break;
    }
    
     if(!x){ans=false; break;}
  }if(!ans)
    cout<<-1<<endl;
  else{
  int n=A.size();
    for(int i=n-1;0<=i;i--)
      cout<<A.at(i)<<endl;
  
  }
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define pb push_back
#define lp(i,a,b) for(int i = a;i<b;i++)
#define ll long long
#define pii pair<int,int>
#define ff first
#define ss second
#define mk make_pair
#define sz size()
 
const int MAXN = 1e5+10 ; 
 
using namespace std ;

int n ,  k , q ;
int cnt[MAXN] ;

int main()
{
	
	scanf("%d%d%d", &n , &k, &q) ;
	
	lp(i,0,q)
	{
		int x ;
		scanf("%d", &x);
		cnt[x] ++ ;
	}
	
	lp(i,1,n+1)
		printf("%s\n" , ( k - q + cnt[i]) > 0 ? "Yes" : "No" ) ;
	
}









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

AB_list = [ list(map(int, input().split())) for i in range(N)]
AB_list.sort(key = lambda x : x[1])


time = 0
for i in range(N):
  time += AB_list[i][0]
  if time > AB_list[i][1]:
    print('No')
    exit()
print('Yes')

Measured memory_bytes: 54896
N = int(input())
S = input()
dp = [0] * N
for s in S[1:]:
    if s == 'E':
        dp[0] += 1
for i in range(1, N):
    dp[i] = dp[i-1]
    if S[i] == 'E':
        dp[i] -= 1
    if S[i-1] == 'W':
        dp[i] += 1
print(min(dp))

Measured memory_bytes: 15436
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a) n = a;
    if (n > b) n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

std::vector<ll> enum_div(ll n) {
    std::vector<ll> ret;
    for (ll i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) { ret.push_back(n / i); }
        }
    }
    return ret;
}

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

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

struct ToUpper {
    char operator()(char c) {
        return toupper(c);
    }
};

struct ToLower {
    char operator()(char c) {
        return tolower(c);
    }
};

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

    ll N;
    cin >> N;

    ll ans = 0;
    vector<ll> E = enum_div(N);
    for (auto&& e : E) {
        ll a = (N / e) - 1;
        if (a == 0)continue;
        ll r = N / a;
        ll c = N % a;
        if (r == c)ans += a;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int K, S;
    cin >> K >> S;

    int ans = 0;
    for (int X = 0; X <= K; X++) {
        for (int Y = 0; Y <= K; Y++) {
            int Z = S - X - Y;
            if (0 <= Z && Z <= K) ans++;
        }
    }

    cout << ans << endl;
}

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

int n;
int depth[MAX_N];
int parent[MAX_N];
vector<int> child[MAX_N];

void BFS() {
	int rt;
	for (int i = 0; i < n; i++) {
		if (parent[i] == -1) {
			rt = i;
		}
	}
	queue<int> q;
	q.push(rt);
	depth[rt] = 0;
	while (!q.empty()) {
		for (auto& c : child[q.front()]) {
			q.push(c);
			depth[c] = depth[parent[c]] + 1;
		}
		q.pop();
	}
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
		parent[i] = -1;

	for (int i = 0, id, k; i < n; i++) {
		cin >> id >> k;
		for (int j = 0, c; j < k; j++) {
			cin >> c;
			child[id].push_back(c);
			parent[c] = id;
		}
	}

	BFS();

	for (int i = 0; i < n; i++) {
		cout << "node " << i << ':';
		cout << " parent = " << parent[i] << ',';
		cout << " depth = " << depth[i] << ',';
		cout << (parent[i] == -1 ? " root" : (child[i].empty() ? " leaf" : " internal node")) << ',';
		if (child[i].empty()) {
			cout << " []";
		}
		else {
			cout << " [" << child[i][0];
			for (size_t j = 1; j < child[i].size(); j++) {
				cout << ", " << child[i][j];
			}
			cout << ']';
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 7196
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
typedef long long ll;
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<ll>  A(N);
  rep(i,N) cin >> A[i];
  rep(i,N) A[i] -= (i+1);
  sort(A.begin(),A.end());
  ll ans = 0;
  if((int)A.size()%2==1){
    rep(i,N){
      ans += abs(A[i] - A[N/2]);
    }
  }
  else{
    ll pre1, pre2, pre3, pre4;
    pre1 = pre2 = pre3 = pre4 = 0;
    rep(i,N){
      pre1 += abs(A[i] - A[N/2-1]);
      pre2 += abs(A[i] - A[N/2]);
      pre3 += abs(A[i] - (A[N/2-1]+A[N/2])/2);
      pre4 += abs(A[i] - ((A[N/2-1]+A[N/2])/2+1));
    }
    ans = min({pre1,pre2,pre3,pre4});
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int A,B;
  cin>>A>>B;
  if(A==1 && B==2){cout<<3<<endl;}
  if(A==1 && B==3){cout<<2<<endl;}
  if(A==2 && B==1){cout<<3<<endl;}
  if(A==2 && B==3){cout<<1<<endl;}
  if(A==3 && B==1){cout<<2<<endl;}
  if(A==3 && B==2){cout<<1<<endl;}
}




Measured memory_bytes: 256
use std::collections::HashMap;

macro_rules! get_one {
    ($t:ty) => {{
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse::<$t>().unwrap()
    }};

    ($t:ty; $n:expr) => {
        (0..$n).map(|_| get_one!($t)).collect::<Vec<_>>()
    };
}
macro_rules! get_tuple {
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };

    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get_tuple!($($t),*)
        ).collect::<Vec<_>>()
    };
}
macro_rules! get_vec {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_| get_vec!($t)).collect::<Vec<_>>()
    };
}
fn main() {
    let _ = get_one!(usize);
    let v_a = get_vec!(isize);
    let q = get_one!(usize);
    let v_bc = get_tuple!(isize, isize; q);

    let mut hm_a = HashMap::new();

    for a in v_a {
        *hm_a.entry(a).or_insert(0) += 1;
    }
    let mut ans: i64 = hm_a.iter().map(|(&k, &v)| (k as i64) * (v as i64)).sum();

    for (b, c) in v_bc {

        let k = hm_a.entry(b).or_insert(0);
        let kk = k.clone();
        *k = 0;
        *hm_a.entry(c).or_insert(0) += kk;

        ans += ((c - b) as i64) * kk;

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

}


Measured memory_bytes: 8644
/* ~ Programmer >> Tushar Mahajan */
#include <iostream>
#include <bits/stdc++.h> 
using namespace std;
#define ll unsigned long long
#define MOD 1000000007
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL); 

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

int main() {
	ios;
	int n,ab;
	cin>>n;
	ll sum=0;
    for(int i=1;i<=n;i++)
    {
        for(int j = 1;j<=n;j++)
        {
            ab = gcd(i,j);
            for(int k=1;k<=n;k++)
            {
                sum = sum + gcd(ab,k);
            }
        }
    }
   cout<<sum;
	return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <math.h>
int minimum(int a, int b) { return a < b ? a : b; }
int maximum(int a, int b) { return a > b ? a : b; }
const long long mod = 1000000007;
//const long long mod = 998244353;
int main() {
	int H, N;
	scanf("%d %d", &H, &N);
	printf("%d", (H - 1) / N + 1);
	return 0;
}

Measured memory_bytes: 128
n = int(input())
#A = [input() for i in range(n)]
C = [0,0,0,0]

for i in range(n):
    s = input()
    if s == "AC":
        C[0] +=1
    elif s == "WA":
        C[1] += 1
    elif s == "TLE":
        C[2] += 1
    else:
        C[3] += 1 
print('AC x '+str(C[0]))
print('WA x '+str(C[1]))
print('TLE x '+str(C[2]))
print('RE x '+str(C[3]))

Measured memory_bytes: 9032
num = STDIN.gets.chomp().split(" ")
p1 = [num[0].to_f, num[1].to_f]
p2 = [num[2].to_f, num[3].to_f]

distance = Math.sqrt((p2[0] - p1[0]) * (p2[0] - p1[0]) + (p2[1] - p1[1]) * (p2[1] - p1[1]))

puts sprintf("%.6f", distance)

Measured memory_bytes: 6132
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD = 1000000007
INF = float("inf")

sys.setrecursionlimit(1000000)

def main():
    N = SL()[::-1]
    dp = [0] * (len(N) + 1)

    for i, e in enumerate(N):
        if int(e) + dp[i] >= 6:
            dp[i] = 10 - (int(e) + dp[i])
            dp[i+1] += 1
        elif int(e) + dp[i] == 5 and i < len(N)-1 and int(N[i+1]) >= 5:
            dp[i] = 5
            dp[i+1] += 1
        else:
            dp[i] += int(e)
    print(sum(dp))

if __name__ == '__main__':
    main()

Measured memory_bytes: 137156
#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::input;
use std::cmp::max;
use std::cmp::min;
use std::collections::HashMap;
use std::collections::VecDeque;

fn main() {
    input! {
        N: usize,
        tmpLs: [i64; N],
    }

    let mut Ls: Vec<i64> = tmpLs.into_iter().collect();

    // ソートはタダ。
    Ls.sort();

    let mut ans = 0i64;

    for i in 0..N {
        let A = Ls[i];

        for j in i + 1..N {
            let B = Ls[j];

            // 3本目は、 j < k < N であるkで、
            // L[k] < A + Bを満たすものの中から選ぶ

            // L[k] < A + Bを満たすkは二分探索で求まりそう

            let sum_l = A + B;

            let mut ok = j + 1;
            if ok == N - 1 && Ls[ok] < A + B {
                ans += 1;
                continue;
            }

            if ok > N - 1 || Ls[ok] >= A + B {
                continue;
            }

            let mut ng = N;

            while ng - ok > 1 {
                let mid = (ok + ng) / 2;
                if Ls[mid] < sum_l {
                    ok = mid;
                } else {
                    ng = mid;
                }
            }

            ans += (ok - j) as i64;
        }
    }

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


Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, l, q, a[100005] = {}, h[18][100005] = {}, x, y;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    cin >> l >> q;
    for (int i = 1; i <= n; i++) h[0][i] = (int)(upper_bound(a, a + n + 1, a[i] + l) - a) - 1;
    for (int i = 1; i <= 17; i++) for (int j = 1; j <= n; j++) h[i][j] = h[i - 1][h[i - 1][j]];
    while (q--) {
        cin >> x >> y;
        if (x > y) swap(x, y);
        int z = 0;
        while (h[0][x] < y) {
            for (int i = 1; i <= 17; i++) if (h[i][x] >= y) {z += (1 << (i - 1)); x = h[i - 1][x]; break;}
        }
        cout << z + 1 << '\n';
    }
}


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

lint gcd(lint x, lint y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

lint lcm(lint x, lint y) { return abs(x*y)/gcd(x,y); }


int main() {
  lint a,b,c,d,ans; cin >> a >> b >> c >> d;
  lint c_num = b/c-(a-1)/c, d_num = b/d-(a-1)/d, cd_num = (b/lcm(c,d))-(a-1)/lcm(c,d);
  /*
  cout << c_num << endl;
  cout << d_num << endl;
  cout << cd_num << endl;
  */
  ans = (b-a+1) - (c_num + d_num - cd_num);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
/**
 *    author:  FromDihPout
 *    created: 2020-06-24
**/

#include <bits/stdc++.h>
using namespace std;

const int MOD = 1e9 + 7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    
    vector<bool> composite(n + 1);
    vector<int> primes;
    for (int i = 2; i <= n; i++) {
        if (composite[i]) continue;
        primes.push_back(i);
        for (int j = i + i; j <= n; j += i) {
            composite[j] = true;
        }
    }
    
    int prime_cnt = (int) primes.size();
    vector<int> factors(prime_cnt);
    for (int i = 2; i <= n; i++) {
        int num = i;
        for (int j = 0; j < prime_cnt; j++) {
            while (num % primes[j] == 0) {
                factors[j]++;
                num /= primes[j];
            }
        }
    }
    
    int ans = 1;
    for (auto i : factors) {
        ans = (long long) ans * (i + 1) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define all(x) (x).begin,(x).end()

using namespace std;
using LL = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;

void read_vi(vi & vec){for (auto & v : vec) cin >> v;}
void read_vpii(vpii & vec){for (auto & v : vec) cin >> v.fi >> v.se;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X, K;
    cin >> X >> K;
    vi rs(K);
    read_vi(rs);
    rs.pb(1e9 + 1);
    int Q;
    cin >> Q;
    vpii qs(Q);
    read_vpii(qs);

    vi min_a = {0};
    vi max_a = {X};
    vi min_v = {0};
    vi max_v = {X};
    int prev_t = 0;
    for (int i = 0; i != sz(rs); ++i){
        int delta_t = rs[i] - prev_t;
        prev_t = rs[i];
        if (i & 1){
            // A was bottom. A was increasing.
            if (max_v[i] + delta_t < X){
                max_v.pb(max_v[i] + delta_t);
                max_a.pb(max_a[i]);
            }else{
                max_v.pb(X);
                max_a.pb(max(max_a[i] - (max_v[i] + delta_t - X), 0));
            }
            if (min_v[i] + delta_t < X){
                min_v.pb(min_v[i] + delta_t);
                min_a.pb(min_a[i]);
            }else{
                min_v.pb(X);
                min_a.pb(X);
            }
        }else{
            // A was top. A was decreasing.
            if (min_v[i] - delta_t > 0){
                min_v.pb(min_v[i] - delta_t);
                min_a.pb(min_a[i]);
            }else{
                min_v.pb(0);
                min_a.pb(min(min_a[i] + (delta_t - min_v[i]), X));
            }
            if (max_v[i] - delta_t > 0){
                max_v.pb(max_v[i] - delta_t);
                max_a.pb(max_a[i]);
            }else{
                max_v.pb(0);
                max_a.pb(0);
            }
        }
    }

    int idx = 0;
    int rt = 0;
    for (auto & q : qs){
        auto t = q.fi;
        auto a = q.se;
        while (rs[idx] <= t) ++idx;
        if (idx >= 1) rt = rs[idx - 1];
        int delta_t = t - rt;
        int v;
        if (a >= max_a[idx]){
            v = max_v[idx];
        }else if (a <= min_a[idx]){
            v = min_v[idx];
        }else{
            v = min_v[idx] + (a - min_a[idx]);
        }
        if (idx & 1){
            v = min(v + delta_t, X);
        }else{
            v = max(v - delta_t, 0);
        }
        cout << v << '\n';
    }
    return 0;
}

Measured memory_bytes: 5112
n=int(input())
A=list(map(int,input().split()))
for i in range(n):
    v=A[i]
    j=i-1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j-=1
    A[j+1] = v
    for k in range(len(A)):
        if k != len(A)-1:
            print(A[k],end=' ')
        else:
            print(A[k])


Measured memory_bytes: 5980
import sys
#import string
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def solve():
    n = str(stdin.readline().rstrip())
    #A, B, C = map(int, stdin.readline().rstrip().split())
    #l = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    ans = 0
    for i in range(3):
        if n[i] == "R":
            if i != 2 and n[i+1] == "R":
                if i == 0 and n[i+2] == "R":
                    ans = 3
                    break
                else:
                    ans = 2
                    break
            else:
                ans = 1
        else:
            pass
    print(ans)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 9120
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
#define double long double
int S(ll n){
	int res=0;
	while(n){
		res+=n%10;
		n/=10;
	}
	return res;
}
double Calc(ll n,int k){
	REP(i,1,k) n/=10;
	REP(i,1,k) n=n*10+9;
	return (double)n/S(n);
}
ll f(ll x){
	int k=0,res=0;
	ll n=x;
	while(n) res++,n/=10;
	n=res;
	double Max=Calc(x,0);
	res=0;
	REP(i,0,n) if(chkmin(Max,Calc(x,i))) res=i;
	k=res;
	REP(i,1,k) x/=10;
	REP(i,1,k) x=x*10+9;
	return x;
}
int main(){
	int k=read();
	ll lst=0;
	while(k--){
		lst++;
		printf("%lld\n",lst=f(lst));
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

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

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 500;
const int C = 30;

int d[C][C],cv[N][N],cc[3][C];

int main() {
	int n,c;cin>>n>>c;
	rep(i,c) rep(j,c) cin>>d[i][j];
	rep(i,n) rep(j,n) {cin>>cv[i][j];cv[i][j]--;}
	rep(i,3) rep(j,c) cc[i][j]=0;
	rep(i,n) rep(j,n) cc[(i+j)%3][cv[i][j]]++;
	int ans=INF,sum[3];
	rep(i0,c){
		sum[0]=0;
		rep(j,c) sum[0]+=cc[0][j]*d[j][i0];
		rep(i1,c){
			if(i1==i0) continue;
			sum[1]=0;
			rep(j,c) sum[1]+=cc[1][j]*d[j][i1];
			rep(i2,c) {
				if(i2==i0||i2==i1) continue;
				sum[2]=0;
				rep(j,c) sum[2]+=cc[2][j]*d[j][i2];
				ans=min(ans,sum[0]+sum[1]+sum[2]);
			}
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1280
#pragma comment(linker,"/STACK:1024000000,1024000000")
//std::ios::sync_with_stdio(false)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#define INF 0X3F3F3F3F
#define MOD 2147493647
#define egs 1e-30
#define LL long long
#define SC(x) scanf("%d",&x)
#define SCC(x,y) scanf("%d%d",&x,&y)
#define SCCC(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define FF(i,a,b) for(int i=a; i<=b; i++)
#define RR(i,a,b) for(int i=a; i>=b; i--)
#define FC(i,a,b) for(int i=a; i<b; i++)
#define SS(x) scanf("%s",x)
#define PR(x) printf("%d\n",x)
#define PRR(x,y) printf("%d %d\n",x,y)
#define CL(a,x) memset(a,x,sizeof(a))
#define MID int mid=((l+r)>>1)
#define lson x<<1,l,mid
#define rson x<<1|1,mid+1,r
#define root int x,int l,int r
#define F(x) ((x)/3+((x)%3==1?0:tb))
#define G(x) ((x)<tb?(x)*3+1:((x)-tb)*3+2)
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define all(x) x.begin(),x.end()
#define IN freopen("in.txt","r",stdin)
#define OUT freopen("out.txt","w",stdout)
#define MAIN 1000010
#define MAXN 1010
using namespace std;
int main()
{
    int a,b;
    while(cin>>a>>b)
    {
        int ans=a-1;
        if(b>=a) ans++;
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		 Dice di = new Dice();
		 
		int[] dice = new int[6];
		 
		for(int i=0; i<6; i++) {
		 dice[i] = scan.nextInt();
		}
		
        char[] c = scan.next().toCharArray();	//stringをcharで入力
        int answer = 0;

        for(int i=0; i<c.length; i++) {
			answer = di.command(dice, c[i]);
        }
        
       	System.out.println(answer);
	}

}

class Dice{

	int command(int[] dice, char com) {
	    	int top = dice[0];	//dice[0]を覚えておく

	    	switch (com) {

	    	case 'N':
	    		dice[0] = dice[1];
	    		dice[1] = dice[5];
	    		dice[5] = dice[4];
	    		dice[4] = top;
	    		break;

	    	case 'E':
	    		dice[0] = dice[3];
	    		dice[3] = dice[5];
	    		dice[5] = dice[2];
	    		dice[2] = top;
	    		break;

	    	case 'W':
	    		dice[0] = dice[2];
	    		dice[2] = dice[5];
	    		dice[5] = dice[3];
	    		dice[3] = top;
	    		break;

	    	case 'S':
	    		dice[0] = dice[4];
	    		dice[4] = dice[5];
	    		dice[5] = dice[1];
	    		dice[1] = top;
	    		break;
	    	}
		return dice[0];
	 }
}


Measured memory_bytes: 26376
#include <stdio.h>

int main(void)
{
	int n,k;
	
	scanf("%d%d",&n,&k);
	
	if(k == 1 || n == k){
		printf("0\n");
	}else{
		int remain = n - k;
	
		printf("%d\n",remain);
	}
	
	return 0;
	
}

Measured memory_bytes: 128
#include<stdio.h>

int main() {

    int left, right, mid;
    int n, q;
    int S[100000], T[50000];
    int i;
    int count = 0;
    int key;

    scanf("%d", &n);
    for (i = 0; i < n; ++i) {
        scanf("%d", &S[i]);
    }
    scanf("%d", &q);
    for (i = 0; i < q; ++i) {
        scanf("%d", &T[i]);
    }

    left = 0;
    right = n;

    for (i = 0; i < q; ++i) {
        left = 0;
        right = n;
        key = T[i];
        while (left < right) {
            mid = (left + right) / 2;
            if (S[mid] == key) {
                count++;
                break;
            } else if (key < S[mid]) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
    }
    printf("%d\n",count);

}


Measured memory_bytes: 2392
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO ツ篠ゥツ督ョツ青カツ青ャツつウツづェツつスツδソツッツドツ・ツスツタツブ

		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			StringBuilder in = new StringBuilder(sc.nextLine());
			for(; ; ){
				if(in.indexOf("the") >= 0 || in.indexOf("this") >= 0 || in.indexOf("that") >= 0){
					System.out.println(in);
					break;
				}
				for(int i = 0; i < in.length(); i++){
					char c = in.charAt(i);
					if(Character.isLetter(c))
						in.setCharAt(i, c == 'z' ? 'a' : (char)(c+1));
				}
			}
		}
	}
}

Measured memory_bytes: 12000
o = input()
e = input()
l = []
while True:
    if len(o) > len(e):
        e = e + ' '
    elif len(o) < len(e):
        o = o + ' '
    else:
        break
for i, j in zip(o, e):
    l.append(i+j)
print(''.join(l).replace(' ', ''))

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

int main(){
	int a, b;
  	cin >> a >> b;
  	int x, y, z;
  	x = a + b;
  	y = a - b;
  	z = a * b;
  	cout << max(max(x, y), z) << endl;
  
}

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
typedef vector<int>vint;
typedef pair<int,int>pint;

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

int H,W;
int a[1000][1000];

int memo[1000][1000][1<<4];

int dfs(int y,int x,int s){
    if(~memo[y][x][s])return memo[y][x][s];
    if(y+1==H&&x+1==W)return 0;



    int ret=1145141919;

    int lis[4]={0},sum=0;
    rep(i,4){
        int ny=y+dy[i],nx=x+dx[i];
        if(ny<0||ny>=H||nx<0||nx>=W||!a[ny][nx])continue;
        if(i==0&&(s>>1&1))continue;
        if(i==1&&(s>>2&1))continue;
        lis[i]=a[ny][nx];
        sum+=lis[i];
    }

    if(y+1!=H){
        if(sum==0){
            ret=min(ret,dfs(y+1,x,(s&1)*2+4));
        }
        else if(sum==lis[3]){
            ret=min(ret,dfs(y+1,x,(s&1)*2+4)+sum);
        }
        else{
            if(lis[0]){
                ret=min(ret,dfs(y+1,x,(s&1)*2+12)+sum-lis[0]);
            }
            if(lis[1]){
                ret=min(ret,dfs(y+1,x,(s&1)*2+12)+sum-lis[1]);
            }
            if(lis[2]){
                ret=min(ret,dfs(y+1,x,(s&1)*2+4)+sum-lis[2]);
            }
        }
    }
    if(x+1!=W){
        if(sum==0){
            ret=min(ret,dfs(y,x+1,(s>>3&1)*4+2));
        }
        else if(sum==lis[2]){
            ret=min(ret,dfs(y,x+1,(s>>3&1)*4+2)+sum);
        }
        else{
            if(lis[0]){
                ret=min(ret,dfs(y,x+1,(s>>3&1)*4+3)+sum-lis[0]);
            }
            if(lis[1]){
                ret=min(ret,dfs(y,x+1,(s>>3&1)*4+3)+sum-lis[1]);
            }
            if(lis[3]){
                ret=min(ret,dfs(y,x+1,(s>>3&1)*4+2)+sum-lis[3]);
            }
        }
    }
    return memo[y][x][s]=ret;
}

signed main(){

    scanf("%d%d",&H,&W);
    rep(i,H)rep(j,W){
        char c;scanf(" %c",&c);
        if(isdigit(c))a[i][j]=c-'0';
    }

    memset(memo,-1,sizeof(memo));
    printf("%d\n",dfs(0,0,0));

    return 0;
}

Measured memory_bytes: 69816