akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
  
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int N = 1005;
char ans[N][N];

int n, m, a, b;

void tile_hor(int x, int y) {
    if (a == 0 || ans[x][y] != '.' || ans[x][y + 1] != '.')
        return;
    a--;
    ans[x][y] = '<';
    ans[x][y + 1] = '>';
}

void tile_ver(int x, int y) {
    if (b == 0 || ans[x + 1][y] != '.' || ans[x][y] != '.')
        return;
    b--;
    ans[x][y] = '^';
    ans[x + 1][y] = 'v';
}

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

    
    cin >> n >> m >> a >> b;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            ans[i][j] = '.';
        }
    }

    int sa = n * (m / 2),
        sb = m * (n / 2),
        s = (n * m) / 2;

    if (b > sb || a > sa || a + b > s) {
        cout << "NO\n";
        return 0;
    }

    if (n == 1 && m == 1) {
        if (a || b) {
            cout << "NO\n";
            return 0;
        }
    }
    else if (n * m % 2) {
        if (b <= sb && a <= sa && a + b <= s) {
            if ((sa - a) % 2) {
                tile_hor(n - 3, m - 3);
                tile_ver(n - 3, m - 1);
                tile_hor(n - 1, m - 2);
                tile_ver(n - 2, m - 3);
            }

            for (int i = 0; i < m; i += 2) {
                tile_hor(n - 1, i);
            }
            for (int i = 0; i < n; i += 2) {
                tile_ver(i, m - 1);
            }

            for (int i = 0; i + 1 < n; i += 2)  {
                for (int j = 0; j + 1 < m; j += 2) {
                    tile_hor(i, j);
                    tile_hor(i + 1, j);
                    tile_ver(i, j);
                    tile_ver(i, j + 1);
                }
            }
        }
    }
    else {
        if (s - sa + (sa - a) / 2 * 2 < b) {
            cout << "NO\n";
            return 0;
        }
        
        if (n % 2) {
            for (int i = 0; i < m; i += 2) {
                tile_hor(n - 1, i);
            }
        }
        if (m % 2) {
            for (int i = 0; i < n; i += 2) {
                tile_ver(i, m - 1);
            }
        }

        for (int i = 0; i + 1 < n; i += 2) {
            for (int j = 0; j + 1 < m; j += 2) {
                tile_hor(i, j);
                tile_hor(i + 1, j);
                tile_ver(i, j);
                tile_ver(i, j + 1);
            }
        }
    }

    cout << "YES\n";

    for (int i = 0; i < n; i++) {
        cout << ans[i] << "\n";
    }

    return 0;
}

Measured memory_bytes: 2176
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


import collections

N = int(input())
c = collections.Counter(prime_factorize(N))
ans = 0

for p, n in c.items():
    for i in range(1, 10000000):
        if n < i:
            break
        ans += 1
        n -= i

print(ans)

Measured memory_bytes: 9464
#include <bits/stdc++.h>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll =long long;
const ll INF =999999999;

//最大公約数
ll gcd(ll a, ll b){
   if (a%b==0){
       return(b);
   }else{
       return(gcd(b,a%b));
   }
}
//最小公倍数
ll lcm(ll a, ll b){
   return a*b/gcd(a,b);
}

//素数判定
ll isprime(ll n){
  bool prime=true;
  for(int i=2;i<n;i++){
    if(n%i==0){
      prime=false; break;
    }
  }
if(prime){cout<<n<<" is prime"<<endl;
         }else{cout<<n<<" is not prime"<<endl;}

}
//階乗　20くらいが限界
ll factorial(ll n){
  ll a=1;ll b=n;
  for(int i=0;i<n;i++){
    a*=b;
    b--;
  }
  return a;
}

//組み合わせ　nCr
ll comb(ll a,ll b){
  ll c;
  c=factorial(a)/(factorial(a-b)*factorial(b));
  return c; 
}




//10億7。　　　100000007
//2*2行列 H*W
//vector<vector<int>> vec(H,vector<int>(W));
//for(int i=0;i<H;i++){
//for(int j=0;j<W;j++){
//cin>>vec[i][j];
//  }
//}

//文字列→数列
//string S;int A=atoi(S.c_str());
//数列→文字列
//int A;string S=to_string(A);
//数字判定　isdigit(a)
//pair宣言　pair<int,int> p(5,7);
//ソート　sort(vec.begin(),vec.end());



int main(){
cout<<fixed<<setprecision(10);

  int A,B,C;cin>>A>>B>>C;
  if(A*B*C==5*7*5){
    cout<<"YES"<<endl;
  }else{cout<<"NO"<<endl;
       }
}


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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()


void solve(std::string C){
    cout << (char)((int)C[0] + 1) << endl;
}

int main(){
    std::string C;
    std::cin >> C;
    solve(C);
    return 0;
}


Measured memory_bytes: 256
# vim: fileencoding=utf-8


def main():
    red, green, blue = map(int, input().split())
    k = int(input())
    res = "No"
    for i in range(k):
        if blue <= green or blue <= red:
            blue *= 2
        elif green <= red:
            green *= 2
        if blue > green and green > red:
            res = "Yes"
            break
    print(res)


if __name__ == "__main__":
    main()


Measured memory_bytes: 61728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
/*--------------------------------------------*/

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

    string s;
    cin >> s;

    ll Q;
    cin >> Q;

    ll rev = 0;

    rep(_,Q){
        int a;
        cin >> a;

        if(a == 1){
            rev++;
        }else{
            int f;
            char c;
            cin >> f >> c;

            if((f == 1 && rev%2 == 0) || (f == 2 && rev%2 == 1)){
                s.insert(s.begin(), c);
            }else{
                s.PB(c);
            }
        }
    }

    if(!(rev%2)){
        cout << s << endl;
    }else{
        for(int i = sz(s)-1;i >= 0;i--){
            cout << s[i];
        }
        cout << endl;
    }
}

Measured memory_bytes: 912
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
void vdeb(std::vector<T> &da) {
    for (int i = 0;i < da.size();i++) {
        if (i == da.size() - 1) std::cout << da[i];
        else std::cout << da[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
    for (int i = 0;i < da.size();i++) {
        std::cout << i << ' ';
        vdeb(da[i]);
    }
    std::cout << '\n';
}

using namespace std;

int main() {
    int n; cin >> n;
    vector<int> da(n);
    rip(i,n,0) cin >> da[i];
    vector<int> ans(n);
    int now = n-2, id = n-1;
    while(now >= 0) {
        ans[id] = da[now];
        now -= 2;
        --id;
    }
    now = n-1, id = 0;
    while(now >= 0) {
        ans[id] = da[now];
        now-=2;
        ++id;
    }
    vdeb(ans);
}

Measured memory_bytes: 4836
N = int(input())
a = list(map(int,input().split()))
sum_a = sum(a)
sunuke = a[0]
mini = abs(sum_a - 2*sunuke)
for i in range(1,N-1):
    sunuke += a[i]
    mini = min(mini,abs(sum_a - 2*sunuke))

print(mini)



Measured memory_bytes: 24948
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int A = sc.nextInt();
		// スペース区切りの整数の入力
		int B = sc.nextInt();

		int C = sc.nextInt();

		int res = C - (A - B);
		if(res < 0){
			res = 0;
		}

		System.out.println(res);
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
long long n,d;
int main(){
	cin>>d>>n;
	if(n==100) n++;
	if(d==0){
		cout<<n;
	} 
	if(d==1){
		cout<<100*n;
	} 
	if(d==2){
		cout<<10000*n;	
	}
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(0); 
    cin.tie(0);   
	ll n,a[200009];
	string s;
	cin>>n;
	cout<<int(n+(n*n)+(n*n*n))<<endl;
	return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    char c;
    int plus=0,minus=0;
    while(cin>>c) (c=='+')?++plus:++minus;
   	cout<<plus-minus;
   return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w
using namespace std;

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

struct Trie {
	Trie *next[2];
	Trie() { fill(next, next + 2, (Trie*)0); }
};

void *add(const char *t, Trie *r) {
	for(int i = 0; t[i]; ++i) {
		char c = t[i] - '0';
		if (!r->next[c]) r->next[c] = new Trie;
		r = r->next[c];
	}
}

int l,g = 0;

int grundy(int x){
	if(!x) return 0;
	int tmp = 1;
	while(x % tmp == 0) tmp *= 2;
	return tmp / 2;
}

void dfs(int d,Trie *t){
	if((t->next[0] != 0) ^ (t->next[1] != 0)) g ^= grundy(l - d);
	if(t->next[0]) dfs(d + 1,t->next[0]);
	if(t->next[1]) dfs(d + 1,t->next[1]);
}

signed main(){
	int n;
	cin >> n >> l;
	Trie *trie = new Trie;
	for(int i = 0;i < n;i++){
		string s;
		cin >> s;
		add(s.c_str(),trie);
	}
	dfs(0,trie);
	if(g) cout << "Alice" << endl;
	else cout << "Bob" << endl;
	return 0;
}

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


/*
締め切りが近いものから順に貪欲で処理？
*/


void solve(){
    int n;
    cin >> n;
    vector<pair<int,int>> v;
    rep(i,n){
        int a,b;
        cin >> a >> b;
        v.emplace_back(make_pair(b,a));
    }

    sort(v.begin(), v.end());
    string s = "Yes";
    int time = 0;
    rep(i,n){
        time += v.at(i).second;
        if(time > v.at(i).first){
            s = "No";
            break;
        }
    }
    cout << s << endl;
}

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

Measured memory_bytes: 2420
#include<iostream>
using namespace std;
#include<vector>
#define mod 1000000007

int n;
vector<int> graph[100006];
long long dp[100006][2];

void solution(int sv , int parent){
    
    long long white = 1;
    long long black = 1;
    for(int i=0 ; i<graph[sv].size() ; i++){
        if(graph[sv][i]!=parent){
            solution(graph[sv][i] , sv);
            white = (white*((dp[graph[sv][i]][1] + dp[graph[sv][i]][0])%mod))%mod;
            black = (black*dp[graph[sv][i]][0])%mod;
        }
    }
    dp[sv][0] = white;
    dp[sv][1] = black; 


}


int main(){
     
    cin>>n;
    for(int i=0 ; i<n-1 ; i++){
        int s , d;
        cin>>s>>d;
        graph[s].push_back(d);
        graph[d].push_back(s);
    } 
    solution(1 , 0);
    cout<<(dp[1][0]+dp[1][1])%mod<<endl;

}

Measured memory_bytes: 15616
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {

	public static int calc(ArrayList<Integer> arr, int k, boolean head) {
		int temp = 0,max;
		for(int i = 0;i < k*2;++i) {
			temp += arr.get(i);
		}
		if(head) {
			temp += arr.get(k*2);
		}
		max = temp;
		for(int i = k*2;i < arr.size();i+=2) {
			temp -= arr.get(i - k*2);
			if(head) {
				temp -= arr.get(i+1 - k*2);
			} else {
				if(i != k*2) {
					temp -= arr.get(i-1 - k*2);
				}
			}
			if(head) {
				if(i+2 < arr.size()) {
					temp += arr.get(i+2);
				}
				if(i+1 < arr.size()) {
					temp += arr.get(i+1);
				}
			} else {
				temp += arr.get(i);
				if(i+1 < arr.size()) {
					temp += arr.get(i+1);
				}
			}
			if(max < temp) {
				max = temp;
			}
		}
		return max;
	}

	public static void main(String[] args) throws IOException {
		BufferedReader bf = null;
		bf = new BufferedReader(new InputStreamReader(System.in));
		int n,k,ans = 0,tempn;
		boolean head,tempb;
		ArrayList<Integer> arr = new ArrayList<Integer>();
		String str;
		String[] s;
		str = bf.readLine();
		s = str.split(" ");
		n = Integer.parseInt(s[0]);
		k = Integer.parseInt(s[1]);
		str = bf.readLine();
		s = str.split("");
		head = Integer.parseInt(s[0]) == 1;
		tempb = head;
		tempn = 1;
		for(int i = 1;i < n;++i) {
			if(tempb == (Integer.parseInt(s[i]) == 1)) {
				tempn++;
			} else {
				arr.add(tempn);
				tempn = 1;
				tempb = !tempb;
			}
		}
		arr.add(tempn);
		if(head) {
			if(k >= arr.size()/2) {
				ans = n;
			} else {
				ans = calc(arr,k,head);
			}
		} else {
			if(k >= (arr.size()+1)/2) {
				ans = n;
			} else {
				ans = calc(arr,k,head);
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 31304
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

int main() {
  int64 N;
  cin >> N;
  int64 ans = 0;
  int64 mx = sqrt(N);
  for (int i = 1; i <= mx; i++) {
    if ((N - i) % i != 0) continue;
    int64 shou = (N - i) / i;
    if (shou > i) ans += shou;
    debug(i, shou);
  }
  cout << ans << endl;
  return 0;
}
// 15 分くらい

Measured memory_bytes: 3616
// Problem: E - Coprime
// Contest: AtCoder - AtCoder Beginner Contest 177
// URL: https://atcoder.jp/contests/abc177/tasks/abc177_e
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define ll long long int
#define ii int
#define du double
#define jmp "\n"
#define vl vector<ll>
#define vvl vector<vl>
#define pb push_back
#define printv(v)     \
  for (auto x : v)    \
    cout << x << " "; \
  cout << jmp;
#define vi vector<int>
#define vb vector<bool>
#define SORT(v) sort(v.begin(), v.end())
#define REV(x) reverse(x.begin(), x.end())
#define all(x) x.begin(), x.end()
#define SET(x, a) memset(x, a, sizeof(x))
#define si(x) x.size()
#define ff first
#define ss second
#define iin insert
#define deb(x) cout << "test " << #x << "=" << x << jmp
#define deb2(x, y) cout << "test " << #x << "=" << x << "," << #y << "=" << y << jmp
using namespace std;
const ll nax = 1e6 + 5;
bool pr[nax];
bool ptest(ll n)
{

  for (ll i = 2; i * i < n; i++)
    if (n % i == 0)
    {
      //cout<<i<<jmp;
      if (pr[i] == 1 && i != 1)
        return 1;
      while (n % i == 0)
        n /= i;
    }
    //cout<<pr[n];
  if (n > 1)
    if (pr[n] == 1)
    return 1;
    else pr[n]=1;
  return 0;
}
void solve()
{
  ll n;
  cin >> n;
  vl a(n);
  for (auto &x : a)
    cin >> x;
  SET(pr, 0);
  ll res = a[0];
  for (ll i = 1; i < n; i++)
    res = __gcd(res, a[i]);
  if (res > 1)
    cout << "not coprime";
  else
  {
    bool f = 0;
    for (ll i = 0; i < n; i++)
      if (ptest(a[i]))
      {
        f = 1;
        break;
      }
    f ? cout << "setwise coprime" : cout << "pairwise coprime";
  }
}
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1;
  //cin >> t;
  while (t--)
    solve();
  return 0;
}

Measured memory_bytes: 11808
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

N = lines[0][0]
leaves = []
for i in 0..N do
  leaves.push(lines[1][i])
end

max_bi = -1  # max bification
for i in 0..N do
  max_bi += leaves[i]
end

def max_nodes(leaves, max_bi)
  remain_bi = max_bi
  nodes = [1]       #always one node with depth 0
  for i in 0..N-1 do
    if nodes[i] < leaves[i] then
      return [-1]
    end
    num_fin = leaves[i]
    if remain_bi >= nodes[i] - num_fin then
      num_bi = nodes[i] - num_fin
      remain_bi -= nodes[i] - num_fin
      num_sin = 0
    else
      num_bi = remain_bi
      remain_bi = 0
      num_sin = nodes[i] - num_fin - num_bi
    end
    next_nodes = num_bi * 2 + num_sin
    nodes.push(next_nodes)
  end
  if nodes[N] < leaves[N] then
    return [-1]
  else
    return nodes
  end
end
  
num_nodes = max_nodes(leaves, max_bi)
ans = 0
for i in 0..(num_nodes.length-1) do
  ans += num_nodes[i]
end
print ans

Measured memory_bytes: 23364
def main():
    t1, t2 = map(int, input().split())
    a1, a2 = map(int, input().split())
    b1, b2 = map(int, input().split())
    if a1 < b1:
        a1, b1 = b1, a1
        a2, b2 = b2, a2

    div = (a1 - b1) * t1 + (a2 - b2) * t2
    ans = (b1 - a1) * t1

    if div == 0:
        print('infinity')
        return
    elif div > 0:
        # includes a2 > b2
        print('0')
        return

    else:
        if ans % div == 0:
            print(2 * (ans // div))
            return
        else:
            print(2 * (ans // div) + 1)
            return


if __name__ == "__main__":
    main()


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

using namespace std;

const int N = 5050, mod = 1e9 + 7;

long long powmod(long long b, long long p) {
  long long r = 1;
  for (; p; p >>= 1, b = b * b % mod)
    if (p & 1)
      r = r * b % mod;
  return r;
}

int dp[N], dp2[N][2], cnt[N], ujung[N];

int a, b;

void upd(int & var, int val) {
  var += val;
  if (var >= mod)
    var -= mod;
}

int main() {
  memset(dp, 0, sizeof dp);
  int n;
  scanf("%d %d %d", &n, &a, &b);
  if (a > b)
    swap(a, b);
  dp[0] = 2;
  for (int i = 0; i < n; ++i) {
    for (int j = i+1; j <= n && j - i < b; ++j) {
      upd(dp[j], dp[i]);
    }
  }
  long long ans = (powmod(2, n) - dp[n]) % mod;
  // cerr << ans << endl;
  if (a < b) {
    for (int i = 1; i < b; ++i) {
      upd(cnt[i], 1);
    }
    for (int i = 1; i < b; ++i) {
      for (int j = i+a+1; j < b; ++j) {
        int add = j - i;
        upd(cnt[j], 1LL * (add - a) * cnt[i] % mod);
      }
      // cerr << i << " cnt " << cnt[i] << endl;
    }
    for (int i = a+1; i < b; ++i) {
      for (int j = a; j < i; ++j)
        upd(ujung[i], cnt[i-j]);
    }
    for (int i = 1; i < b; ++i) {
      upd(ujung[i], cnt[i]);
      // cerr << " ujung " << i << " " << ujung[i] << endl;
    }
    dp2[0][0] = dp2[0][1] = 1;
    for (int i = 0; i < n; ++i) {
      for (int j = i+1; j <= n && j - i < a; ++j) {
        upd(dp2[j][1], dp2[i][0]);
      }
      for (int j = i+1; j <= n && j - i < b; ++j) {
        int cost = (j == n || i == 0) ? ujung[j-i] : cnt[j-i];
        upd(dp2[j][0], 1LL * cost *  dp2[i][1] % mod);
      }
      // cerr << dp2[i][0] << " " << dp2[i][1] << endl;
    }
    // cerr << dp2[n][0] << " " << dp2[n][1] << endl;
    ans = (ans + dp[n] - dp2[n][1] - dp2[n][0]) % mod;
    // for (int i = a+1; i < b; ++i) {
    //   upd(ujung[n-i], mod - cnt[n-i]);
    //   ans = (ans - ujung[n-i]) % mod;
    // }
  }
  ans %= mod;
  if (ans < 0)
    ans += mod;
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 3924
def gets_i()
  return gets.chomp.to_i
end

def gets_list()
  return gets.chomp.split(" ")
end

def gets_list()
  return gets_list().map(&:to_i)
end

N = gets_i
S = gets.chomp

if N % 2 != 0 then
  puts "No"
  exit
end

d = (N / 2)

if S[0..d-1] == S[d..-1] then
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 3836
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){

    int n, m;
    cin >> n >> m;

    vector<pair<int, int>> students, checkpoints;


    for (int i = 0; i < n; i++){
        int t1, t2;
        cin >> t1 >> t2;
        students.push_back(make_pair(t1, t2));
    }

    for (int i = 0; i < m; i++){
        int t1, t2;
        cin >> t1 >> t2;
        checkpoints.push_back(make_pair(t1, t2));
    }

    for (int i = 0; i < n; i++){ 
        int t1 = students[i].first;
        int t2 = students[i].second;

        int mn = 2e9;
        int ind = -1;

        for (int j = 0; j < m; j++){
            int c1 = checkpoints[j].first;
            int c2 = checkpoints[j].second;

            if (mn != abs((t1 - c1)) + abs(t2 - c2)){ 
                int t = mn;
                // cout << " here " << j << endl;
                // cout << " mn : " << mn << " (t1 - c1) + (t2 - c2) : " << (t1 - c1) + (t2 - c2) << endl;
                mn = min(mn, abs((t1 - c1)) + abs(t2 - c2)); // this could undo with -1 values, we could want closest to zero
                if (mn != t) ind = j + 1;
            }

        }

        cout << ind << endl;
    }

    /**

    2 2
    2 0
    0 0
    -1 0
    1 0 


    3 4
    10 10
    -10 -10
    3 3
    1 2
    2 3
    3 5
    3 5


    5 5
    -100000000 -100000000
    -100000000 100000000
    100000000 -100000000
    100000000 100000000
    0 0
    0 0
    100000000 100000000
    100000000 -100000000
    -100000000 100000000
    -100000000 -100000000




     */
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>

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

using namespace std;
using ll = long long int;
const int inf = 1001001000;
const long long int Inf = 1001001001001001000;

void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}



int main()
{
	int n;
	cin >> n;
	string s, t, ans;
	cin >> s >> t;
	rep(i,n){
		ans = ans + s[i];
		ans = ans + t[i];
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
while line = gets
  a = line.chomp.split
  b = gets.chomp.split
  hit = 0
  blow = 0
  4.times{|i|
    4.times{|j|
      if a[i] == b[j]
        if i == j
          hit += 1
        else
          blow += 1
        end
      end
    }
  }
  puts "#{hit} #{blow}"
end

Measured memory_bytes: 8648
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static String in;
	public static void main(String[] args) {
		while(read()){
			solve();
		}
	}
	
	static boolean read(){
		if(!sc.hasNext())return false;
		in = sc.next();
		return true;
	}
	
	static void solve(){
		StringBuffer sb = new StringBuffer(in);
		System.out.println(sb.reverse());
	}
}

Measured memory_bytes: 11000
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
//KMP算法练习
long long ans=0;


int main(){
    int i;
    int  n;
    scanf("%d",&n);
    for(i=1;i<n;i++){
        if(n%i==0){
            ans=ans+(n/i)-1;
            
        }
        else{
            ans+=(n/i);
            
        }
    }
    
    
    printf("%d",ans);
}

Measured memory_bytes: 2152
import java.util.*;

class Main
{
    public static void main(String[] args)
    {
        Scanner cin = new Scanner(System.in);
        int n = cin.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = cin.nextInt();
        int[] b = new int[n];
        for (int i = 0; i < n; i++) b[i] = cin.nextInt();
        int[] c = new int[n];
        for (int i = 0; i < n; i++) c[i] = a[i] - b[i];

        Arrays.sort(c);

        int i = 0, mi = 0;
        int j = n - 1, mj = n - 1;

        while (c[i] < 0 && i < j) {
            int m = Math.min(-c[i], c[j]);
            c[i] += m;
            mi = i + 1;
            if (c[i] == 0) ++i;
            c[j] -= m;
            mj = j - 1;
            if (c[j] == 0) --j;
        }

        if (c[i] >= 0) {
            System.out.println(n - (mj - mi + 1));
        } else {
            System.out.println(-1);
        }
    }
}


Measured memory_bytes: 64992
import sys
 
n, m = list(map(int, input().split()))
if m > 0:
    aaa = set(map(int, sys.stdin))
else:
    aaa = set()
dp = [0] * (n + 1)
dp[0] = 1
dp[1] = 1 if 1 not in aaa else 0
MOD = 10 ** 9 + 7
 
for i in range(2, n + 1):
    if i in aaa:
        continue
    dp[i] = (dp[i - 2] + dp[i - 1]) % MOD
print(dp[n])

Measured memory_bytes: 11884
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n, a, b, val;
    cin >> n >> a >> b;
    vector<int> ans(3, 0);
    for(int i = 0; i < n; i++) {
        cin >> val;
        if (val <= a)
            ans[0] += 1;
        else if (val <= b)
            ans[1] += 1;
        else
            ans[2] += 1;
    }
    cout << *min_element(ans.begin(), ans.end()) << endl;
    return 0;
}


Measured memory_bytes: 3608
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
	"unsafe"
)

func main() {
	N := sc.nextInt()
	P := sc.nextInts()
	Q := sc.nextInts()

	pans := calc(N, P)
	qans := calc(N, Q)
	fmt.Println(abs(pans - qans))
}

func calc(N int, P []int) int {
	P2 := make([]int, len(P))
	copy(P2, P)
	sort.Ints(P2)

	var ans int
	for _, v := range P {
		index := 1
		if len(P2) == 2 {
			for i, v2 := range P2 {
				if v == v2 {
					ans += i + 1
					return ans
				}
			}
		} else {
			for i, v2 := range P2 {
				if v == v2 {
					index = i
					P2 = delete(P2, i)
					ans += pows(N-1) * (index)
					break
				}
			}
		}
		N--
	}
	return 0
}

func pows(num int) int {
	if num == 1 {
		return 1
	}
	ans := 1
	for {
		ans *= num
		num--
		if num <= 1 {
			break
		}
	}
	return ans
}

func delete(s []int, i int) []int {
	s = append(s[:i], s[i+1:]...)
	n := make([]int, len(s))
	copy(n, s)
	return n
}

/* template functions */
var (
	sc scanner
)

func init() {
	sc = scanner{
		buf: make([]string, 0, 0),
		cur: 0,
		r:   bufio.NewReader(os.Stdin),
	}
}

type scanner struct {
	buf []string
	cur int
	r   *bufio.Reader
}

func (s *scanner) readln() {
	rbuf := make([]byte, 0, 0)
	for {
		line, prefix, err := s.r.ReadLine()
		if err != nil {
			panic(err)
		}
		rbuf = append(rbuf, line...)
		if prefix == false {
			break
		}
	}
	s.cur = 0
	s.buf = strings.Split(*(*string)(unsafe.Pointer(&rbuf)), " ")
}
func (s *scanner) isFull() bool {
	if s.cur == len(s.buf) {
		return true
	}
	return false
}
func (s *scanner) resetCur() {
	s.cur = 0
}
func (s *scanner) next() string {
	if s.cur == 0 {
		s.readln()
	}
	res := s.buf[s.cur]
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nexts() []string {
	s.readln()
	s.resetCur()
	return s.buf
}
func (s *scanner) nextInt() int {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.Atoi(s.buf[s.cur])
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextInts() []int {
	s.readln()
	res := make([]int, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.Atoi(s.buf[i])
	}
	s.resetCur()
	return res
}
func (s *scanner) nextFloat() float64 {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.ParseFloat(s.buf[s.cur],
		64)
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextFloats() []float64 {
	s.readln()
	res := make([]float64, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.ParseFloat(s.buf[i],
			64)
	}
	s.resetCur()
	return res
}
func digits(x int) int {
	return len(strconv.Itoa(x))
}
func powInt(x, p int) (result int) {
	result = 1
	for i := 0; i < p; i++ {
		result *= x
	}
	return
}
func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}
func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}
func abs(x int) int {
	return int(math.Abs(float64(x)))
}
func varDump(value ...interface{}) {
	for _, v := range value {
		fmt.Fprintf(os.Stderr, "%#v\n", v)
	}
}
func yes() {
	fmt.Println("Yes")
}
func no() {
	fmt.Println("No")
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
long long int dp[100007][4];
long long int dizi[100007][4];
int main()
{
// 	freopen("a.gir","r",stdin);
// 	freopen("a.cik","w",stdout);
	int n,k;
	cin >> n;
	for(int i=0;i<n;i++)
	{
		cin >> dizi[i][0] >> dizi[i][1] >> dizi[i][2];
	}
	dp[0][0]=dizi[0][0],dp[0][1]=dizi[0][1],dp[0][2]=dizi[0][2];
	for(int i=1;i<=n;i++)
	{
		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+dizi[i][0];
		dp[i][1]=max(dp[i-1][0],dp[i-1][2])+dizi[i][1];
		dp[i][2]=max(dp[i-1][0],dp[i-1][1])+dizi[i][2];
	}
	cout << max(max(dp[n][0],dp[n][1]),dp[n][2]);

}

Measured memory_bytes: 6528
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = [0 for i in range(n+1)]
b = [0 for j in range(m+1)]
for i in range(n):
    a[i+1] = a[i]+A[i]
for j in range(m):
    b[j+1] = b[j]+B[j]

j = m
res = 0
for i in range(n+1):
    if a[i] > k:
        break
    while k - a[i] < b[j]:
        j -= 1
    res = max(res, i+j)

print(res)

Measured memory_bytes: 47544
/* 
 * File:   main.c
 * Author: s1252007
 *
 * Created on June 26, 2018, 11:17 AM
 */

#include <stdio.h>
#include <stdlib.h>

/*
 * 
 */

int linearSearch(int *S, int n, int *T, int q);

int main(int argc, char** argv) {
    int n, q;
    int *S, *T;
    scanf("%d", &n);
    S = (int *)malloc(sizeof(int) * n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &S[i]);
    }
    scanf("%d", &q);
    T = (int *)malloc(sizeof(int) * q);
    for (int j = 0; j < q; j++)
    {
        scanf("%d", &T[j]);
    }
    
    printf("%d\n", linearSearch(S, n, T, q));
    return (EXIT_SUCCESS);
}

int linearSearch(int *S, int n, int *T, int q)
{
    int counter = 0;
    for (int i = 0; i < q; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (S[j] == T[i]) 
            {
                counter++;
                break;
            }
        }
    }
    return counter;
}




Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
#define int long long
void Digvijay()
{
   int n,x;
   cin>>n>>x;
   vector<int> a(n);
   for(auto& it:a)cin>>it;
   int ans=0;
   for(int i=0;i<n-1;i++)
   {
       int val=a[i]+a[i+1];
       if(val>x)
       {
           val-=x;
           if(val<=a[i+1])
           {
               ans+=val;
               a[i+1]-=val;
           }
           else
           {
               ans+=val;
               val-=a[i+1];
               a[i+1]=0;
               a[i]-=val;
           }
       }
   }
   cout<<ans<<"\n";
   
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int _=1;
    //cin>>_;
    for(int __=0;__<_;__++)
    {
        Digvijay();
    }
}

Measured memory_bytes: 3956
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(BigInt,x)
pM(x::Array{SubString{String},1})=map(pI,x)
function main()
  n=pI(readline())
  a=sort(pM(split(readline())))
  println(sum(a[n+1:2:3n]))
end
main()
if isdefined(Base, :mystdin);close(mystdin);end

Measured memory_bytes: 186628
#include <iostream>
#include <cstdio>
using namespace std;
#define MAXN 10001

int n, A[MAXN];

void init()
{
	for (int i = 0; i < n; i++) {
		A[i] = i;
	}
}

int findFather(int x)
{
	int a = x;
	while (x != A[x]) {
		x = A[x];
	}
	while (a != A[a]) {
		//int z = a;
		A[a] = x;
		a = A[a];
	}
	return x;
}

void Union(int x, int y)
{
	int a = findFather(x);
	int b = findFather(y);
	if (a != b) {
		A[a] = b;
	}
}

bool same(int x, int y)
{
	return findFather(x) == findFather(y);
}


int main(int argc, char *argv[]) {
	int m;
	cin >> n >> m;
	init();
	for (int i = 0; i < m; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		if (a == 0) {
			Union(b, c);
		}else if (a == 1) {
			if (same(b, c)) {
				printf("1\n");
			}else {
				printf("0\n");
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3132
// tsukasa_diary's programing contest code template
#include <bits/stdc++.h>
using namespace std;
#define TSUKASA_DIARY_S_TEMPLATE
// define
#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) int((a).size())
#define cauto const auto
// typedef
typedef long long lint;
typedef double Double;
typedef pair< int, int > pii;
template< typename T > using Vec = vector< T >;
template< typename T > using Matrix = Vec< Vec< T > >;
template< typename T > using USet = unordered_set< T >;
template< typename T, class C > using MyUSet = unordered_set< T, C >;
template< typename T, typename F > using UMap = unordered_map< T, F >;
template< typename T, typename F, class C > using MyUMap = unordered_map< T, F, C >;
// hash
class PiiHash { public: size_t operator () (const pii& p) const { return (p.first << 16) | p.second; } };
// popcount
inline int POPCNT(int x) { return __builtin_popcount(x); }
inline int POPCNT(lint x) { return __builtin_popcount(x); }
// inf
const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
// eps
const Double EPS = 1e-9;
const Double PI = acos(-1);
// inrange
template< typename T >
inline bool in_range(T v, T mi, T mx) { return mi <= v && v < mx; }
template< typename T >
inline bool in_range(T x, T y, T W, T H) { return in_range(x,0,W) && in_range(y,0,H); }
// neighbor clockwise
const int DX[4] = {0,1,0,-1}, DY[4] = {-1,0,1,0};
const int DX_[8] = {0,1,1,1,0,-1,-1,-1}, DY_[8] = {-1,-1,0,1,1,1,0,-1};
// variable update
template< typename T > inline void modAdd(T& a, T b, T mod) { a = (a + b) % mod; }
template< typename T > inline void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > inline void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > inline void maxUpdate(T& a, T b) { a = max(a, b); }
// converter
template< typename F, typename T >
inline void convert(F& from, T& to) {
	stringstream ss;
	ss << from; ss >> to;
}



int main() {
	lint K;
	cin >> K;
	
	const int N = 50;
	vector< lint > a(N, N-1);
	
	lint x = K / N, y = (K % N);
	for_(i,0,N) a[i] += N * x - (N - 1) * x;
	for_(i,0,y) a[i] += N - (y - 1);
	for_(i,y,N) a[i] -= y;
	
	cout << N << endl;
	for_(i,0,N) cout << a[i] << (i < N - 1 ? " " : "\n");
}

Measured memory_bytes: 256
#include<stdio.h>

int main (){
  int a;
  int b;
  int c;
  int d;
  scanf("%d %d %d",&a,&b,&c);
  if(a > b){
    d = a;
    a = b;
    b = d;
  }     if (b > c){
    d = b;
    b = c;
    c = d;
  }     if (a > b){
    d = a;
    a = b;
    b = d;
}
  printf("%d %d %d\n", a,b,c);

  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printInt(a) printf("%d\n", a)
#define scanInt(a) scanf("%d", &a)
#define scan2Int(a, b) scanf("%d %d", &a, &b)
#define scan3Int(a, b, c) scanf("%d %d %d", &a, &b, &c)
using namespace std;

int main() {
    int x, y;
    scan2Int(x, y);
    if ((y-x*2)/2 <= x && (y-x*2) >= 0 && !(y % 2))
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;
const ll mod = 1e9 + 7;

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


Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
  int n, m, in, out, i, max;
  scanf("%d%d",&n,&m);
  max = m;
  for(i = 0; i < n; i++ ) {
    scanf("%d%d",&in,&out);
    m += (in - out);
    if(m < 0) {
      max = -1;
      break;
    }
    if(max < m) max = m;
  }
  if(max == -1) puts("0");
  else printf("%d\n",max);
  return(0);
}

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

int main()
{
    int n = 0;
    int sum = 0;

    cin >> n;
    vector<int> v(n);

    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
        sum += v[i];
    }
    if (sum % 10 != 0)
    {
        cout << sum << endl;
        return 0;
    }
    sort(v.begin(), v.end());

    for (int i = 0; i < n; i++)
    {
        if (v[i] % 10 != 0)
        {
            sum -= v[i];
        }
        if (sum % 10 != 0)
        {
            cout << sum << endl;
            return 0;
        }
    }
    cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
B - Echo
https://atcoder.jp/contests/abc145/tasks/abc145_b

"""
import sys


def solve(N, S):
    return 'Yes' if (N % 2 == 0) and (S[:N//2] == S[N//2:]) else 'No'


def main(args):
    N = int(input())
    S = input()
    ans = solve(N, S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 2940
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;
use std::f64::consts;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

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

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let R: f64 = sc.get();
    println!("{}", 2. * R * consts::PI);
}


Measured memory_bytes: 2224
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const int dy1[4] = {0, 1, 0, 1};
const int dx1[4] = {1, 0, 1, 0};
const int dy2[4] = {0, 0, -1, -1};
const int dx2[4] = {-1, -1, 0, 0};

map<char, vector<pair<int,int>>> hole;
char g[50][50];
int memo[50][50][51][51]; // init -2
int solve(int h1, int w1, int h2, int w2){
    if((h1==h2 and w2-w1<=1) or (w1==w2 and h2-h1<=1)){
        return 0;
    }
    if((h1==h2 and w2-w1>1) or (w1==w2 and h2-h1>1)){
        return -1;
    }
    if(h1>h2 or w1>w2){
        return -1;
    }

    int &curr = memo[h1][w1][h2][w2];
    if(curr != -2) return curr;
    if(g[h1][w1]=='#' or g[h2-1][w2-1]=='#'){
        curr = -1;
        return curr;
    }
    curr = -1;
    // pass
    for(int d=0; d<2; d++){
        curr = max(curr, solve(h1+dy1[d], w1+dx1[d], h2, w2));
    }
    // get
    if('a'<=g[h1][w1] and g[h1][w1]<='z'){
        for(auto p: hole[g[h1][w1]-'a'+'A']){
            int y = p.first;
            int x = p.second;
            if(!(h1<=y and y<h2 and w1<=x and x<w2)) continue;
            int ret1 = -1;
            for(int d=0; d<4; d++){
                ret1 = max(ret1, solve(h1+dy1[d], w1+dx1[d], y+1+dy2[d], x+1+dx2[d]));
            }
            int ret2 = -1;
            for(int d=0; d<4; d++){
                ret2 = max(ret2, solve(y+dy1[d], x+dx1[d], h2, w2));
            }
            if(ret1 != -1 and ret2 != -1){
                curr = max(curr, ret1+ret2+1);
            }
        }
    }
    return curr;
}

int main(){
    while(1){
        int h,w;
        cin >> h >> w;
        if(h == 0) break;

        hole.clear();
        rep(i,h) rep(j,w){
            cin >> g[i][j];
            if('A'<=g[i][j] and g[i][j]<='Z'){
                hole[g[i][j]].emplace_back(i, j);
            }
        }
        rep(i,h) rep(j,w) rep(k,h+1) rep(l,w+1){
            memo[i][j][k][l] = -2;
        }
        cout << solve(0, 0, h, w) << endl;
    }
    return 0;
}


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





int main(){
	int A,B,C;
	cin>>A>>B>>C;
	long long K;
	cin>>K;
	if(K%2==0){
		cout<<A-B<<endl;
	}
	else{
		cout<<B-A<<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++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using P = pair<int,int>;
using pq = priority_queue<int>;
typedef long long ll;

int  main()
{
	int n,m,x,y; cin >> n >> m >> x >> y;
	vector<int> xn(n);
	vector<int> ym(m);
	rep(i, n)
		cin >> xn[i];
	rep(i, m)
		cin >> ym[i];
	sort(xn.begin(), xn.end());
	sort(ym.begin(), ym.end());

	bool war = false;
	for (int i = 1; i <= y-x; i++)
	{
		if (xn.back() + i > x && xn.back() + i <= y)
		{
			if (xn.back() + i <= ym.front())
			{
				war = true;
			}
		}
	}
	if (war)
		cout << "No War\n";
	else
		cout << "War\n";
	return (0);
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
namespace fastio{
	template<typename tn> void read(tn &a){
	    tn x=0,f=1;char c=' ';
	    for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	    for(;isdigit(c);c=getchar() ) x=x*10+c-'0';
	    a=x*f;
	}
	template<typename tn> void print(tn a){
	    if(a<0) putchar('-'),a=-a;
	    if(a>9) print(a/10);
	    putchar(a%10+'0');
	}
};
using namespace fastio;
#define ll long long
ll x,ans;
int main(){
	read(x);
	for(int a=0;a<=1000;a++)
		for(int b=-1000;b<=a;b++)
			if(a*a*a*a*a-b*b*b*b*b==x) return printf("%d %d\n",a,b),0;
	return 0;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
#define endl '\n'
#define debug(X) cout << #X << " = " << X << endl

using namespace std;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	#ifdef UTP
	freopen("input.txt", "r", stdin);
	#endif
	int n, k; cin >> n >> k;
	string s; cin >> s; s += "1";
	int ans = 0;
	int l = 0, r = 0, cnt = (s[0] == '0');
	while (r < n) {
        while (r < n && cnt <= k) {
            cnt += (s[r] == '1' && s[r + 1] == '0');
            r++;
        }
        // cout << r << " " << l << endl;
        ans = max(ans, r - l);
        cnt -= (s[l] == '0' && s[l + 1] == '1');
        l++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  for_each(begin(A), end(A), [](auto& x) { cin >> x; });
  ll Q;
  cin >> Q;
  vector<ll> B(Q);
  vector<ll> C(Q);
  for (ll i = 0; i < Q; i++) {
    cin >> B[i] >> C[i];
  }
  map<ll, ll> m;
  for (ll i = 0; i < N; i++) {
    m[A[i]]++;
  }
  ll basesum = accumulate(cbegin(A), cend(A), 0LL);

  for (ll i = 0; i < Q; i++) {
    ll count = 0;
    try {
      count = m.at(B[i]);
    } catch (...) {
    }
    ll sum = basesum;
    if (count > 0) {
      m.at(B[i]) -= count;
      try {
        m.at(C[i]) += count;
      } catch (...) {
        m[C[i]] = count;
      }
      sum -= count * B[i];
      sum += count * C[i];
    }
    cout << sum << endl;
    basesum = sum;
  }

  return 0;
}


Measured memory_bytes: 10372
#include <stdio.h>
#include <string.h>

int main()
{
    int N;
    char buf[10];
    int count = 0;

    scanf( "%d", &N );

    for ( int i = 1; i <= N; i ++ ) {
        sprintf( buf, "%d", i );
        if ( strlen(buf) & 0x01 ) count ++;
    }

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

 
    return 0;
}

Measured memory_bytes: 128