akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n;i>=0;i--)
#define MAX 100001
#define ll long long
#define dmp make_pair
#define dpb push_back
#define P pair<int,int>
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);
const int inf = 1e9;
const ll INF = 1e18;
#define B 100

char a[MAX], c[4] = "JOI";
ll b[MAX][2], dp[MAX][5];
int main(){
	ll n, ans = 0, res = 0;
	scanf("%lld%s", &n, a);
	
	for(int i = 1;i <= n;i++){
		rep(j,5)dp[i][j] += dp[i-1][j];
		if(a[i-1] == 'J')b[i][0]++;b[i][0] += b[i-1][0];
		
		if(a[i-1] == 'J')dp[i][0] += 1;
		if(a[i-1] == 'O'){
			dp[i][1] += dp[i-1][0];
			dp[i][3] += 1;
		}
		if(a[i-1] == 'I'){
			dp[i][2] += dp[i-1][1];
			dp[i][4] += dp[i-1][3];
		}
	}
	
	for(int i = n;i >= 1;i--){
		if(a[i-1] == 'I')b[i][1]++;
		b[i-1][1] += b[i][1];
	}
	for(int i = 1;i <= n;i++){
		res = max(res, b[i][0]*b[i][1]);
	}
	
	ans = max(dp[n][2]+dp[n][4], dp[n][2]+dp[n][1]);
	ans = max(ans, dp[n][2]+res);
	printf("%lld\n", ans);
	return 0;
}

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

#define scan(x) scanf("%d",&x)
#define scan2(x,y) scanf("%d%d",&x,&y)
#define scan3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define FASTER std::ios::sync_with_stdio(false)
#define DEBUG(x) cout<<#x<<" = "<<x<<endl

#define pb push_back
#define mk make_pair
#define vp vector<pair<ll,ll> >
#define se second
#define fi first
#define vi vector<ll>
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define fab(i,a,b) for(ll i=a;i<=b;i++)
#define inp(n,a) for(ll i=0;i<n;i++){cin>>a[i];}
#define strToInt(x,z) istringstream y(x);y>>z  //(string,integer)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b / __gcd(a,b);
#define MOD 1000000007
#define pi 3.14159265

using namespace std;

int a[1000010],n;
int inc(int pos)
{
    for(int i = pos+1; i <= n ; i ++)
    {
        if(a[i] < a[i-1])
        {
            return i-1;
        }
    }

    return n;
}

int dec(int pos)
{
    for(int i = pos+1; i <= n ; i ++)
        {
            if(a[i] > a[i-1])
            {
                return i-1;
            }
        }

    return n;
}

int main()
{
    //FASTER;
	long j=0;
    scan(n);

    fab(i,1,n)scan(a[i]);
    int cnt = 0;
    while(j<n)
    {           
        j = max(inc(j+1),dec(j+1));
        //DEBUG(j);
        cnt++;
    }   

    /*int flag = a[2] > a[1] ? 1: 2; //1- inc , 2-dec

    for(int i = 2; i <= n ; i ++)
        {
            DEBUG(flag);
            if(a[i] > a[i-1] and flag == 1)
            {
                flag = 1;
            }else if(flag ==1)
            {
                cnt++;
                flag = a[i+1] > a[i] ? 1: 2;
                DEBUG(i);
            }

            if(a[i] < a[i-1] and flag == 2)
            {
                //cnt++;
                flag = 2;
            }else if(flag ==2)
            {
                cnt++;
                flag = a[i+1] > a[i] ? 1: 2;
                DEBUG(i);
            }
            

        }
        DEBUG(cnt);DEBUG(flag);
        if((flag == 1) and a[n] < a[n-1])cnt++;

        if((flag == 2) and a[n] > a[n-1])cnt++;
        DEBUG(cnt);*/
    printf("%d\n", cnt);


    return 0;
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline
N,K = [int(i) for i in input().split()]
ab = [0] * N
for i in range(N) :
    ab[i] = [int(i) for i in input().split()]
ab.sort()
sum = 0
for i in range(N) :
    sum += ab[i][1]
    if sum >= K:
        print(ab[i][0])
        break

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

using namespace std;

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

  string a, b;
  cin >> a >> b;

  if (a.size() > b.size()) {
    cout << "GREATER" << endl;
  } else if (a.size() < b.size()) {
    cout << "LESS" << endl;
  } else {  // a.size() == b.size()
    for (size_t i = 0; i < a.size(); ++i) {
      if (a[i] > b[i]) {
        cout << "GREATER" << endl;
        return 0;
      } else if (a[i] < b[i]) {
        cout << "LESS" << endl;
        return 0;
      }
    }
    cout << "EQUAL" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int main(){
    int a, b, count = 0;
    int num = 1;
    cin >> a >> b;
    
    rep(i, 0, 10000){
        if(num>=b){
            cout << i << endl;
            break;
        }
        num += a - 1;
    }
    return 0;
}

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

using namespace std;
const int MOD = 1000000007;
int main(){
    int N, R;
    while(cin >> N >> R && N){
        vector<int> a(N);
        REP(i, N) a[i] = i;
        REP(i, R){
            int s, t;
            cin >> s >> t;
            swap(a[s - 1], a[t - 1]);
        }
        vector<int> used;
        vector<long long> fact(N + 1, 1);
        REP(i, N) fact[i + 1] = fact[i] * (i + 1) % MOD;
        long long ans = 0;
        REP(i, N){
            int k = lower_bound(used.begin(), used.end(), a[i]) - used.begin();
            int b = a[i] - k;
            used.insert(used.begin() + k, a[i]);
            ans += fact[N - 1 - i] * b;
            ans %= MOD;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define D()
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 10000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(){
	ll N,ans=0;
	std::cin >> N;
	ll a[3*N];
	REP(i, 3*N) std::cin >> a[i];
	std::sort(a,a+3*N);
	for ( int i = 0 ; i < N ; i++ ) {
		ans += a[N+i*2];
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{  int n;
   cin>>n;
 int arr[n];
 for(int i=0;i<n;i++)
    cin>>arr[i];
 int dp[n];
 dp[0]=0;
 dp[1]=abs(arr[1]-arr[0]);
  for(int i=2;i<n;i++)
   dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
  cout<<dp[n-1];

}


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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(a * b, c * d) << endl;
}


Measured memory_bytes: 256
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

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

int equal_oprt(int M, int K) {
	if (M <= 0) {
		return 0;
	}
	else {
		return (M + K - 2) / (K - 1);
	}
}

int main() {
	int N, K;
	int min_oprt = 0;
	int idx_one = 0;
	cin >> N >> K;
	vector<int> A(N);

	REP(i, N) {
		cin >> A[i];
		if (A[i] == 1) {
			idx_one = i;
		}
	}

	min_oprt += equal_oprt(idx_one, K);

	int M_after = N - 1 - min_oprt * (K - 1);

	min_oprt += equal_oprt(M_after, K);

	cout << min_oprt << endl;

	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#define N 25
typedef struct{
  int right;
  int left;
  int parent;
}Node;

Node T[N];

void preorder(int id){
  printf(" %d",id);
  if(T[id].left!=-1) preorder(T[id].left);
  if(T[id].right!=-1) preorder(T[id].right);
}

void inorder(int id){
  if(T[id].left!=-1) inorder(T[id].left);
  printf(" %d",id);
  if(T[id].right!=-1) inorder(T[id].right);
}

void postorder(int id){
  if(T[id].left!=-1) postorder(T[id].left);
  if(T[id].right!=-1) postorder(T[id].right);
  printf(" %d",id);
}

int main(){
  int n,i;
  int id;
  scanf("%d",&n);
  for(i=0;i<n;i++) T[i].parent = T[i].left = T[i].right = -1;
  for(i=0;i<n;i++){
    scanf("%d",&id);
    scanf("%d%d",&T[id].left,&T[id].right);
    T[T[id].left].parent = id;
    T[T[id].right].parent = id;
  }
  printf("Preorder\n");
  for(i=0;i<n;i++){
    if(T[i].parent == -1) preorder(i);
  }
  printf("\n");
  printf("Inorder\n");
  for(i=0;i<n;i++){
    if(T[i].parent == -1) inorder(i);
  }
  printf("\n");
  printf("Postorder\n");
  for(i=0;i<n;i++){
    if(T[i].parent == -1) postorder(i);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 616
#include<cstdio>
#include<vector>
#include<algorithm>
#include<set>
#define men(d) (((d.vx*d.vx)+(d.vy*d.vy))/2)
using namespace std;
struct Data{
    short vx,vy,cx,cy;
    Data(short a,short b,short c,short d){
        vx=a;
        vy=b;
        cx=c;
        cy=d;
    }
    Data(){}
};
inline bool operator<(const Data &a,const Data &b){
    if(a.vx<b.vx)return true;
    if(a.vx==b.vx&&a.vy<b.vy)return true;
    if(a.vx==b.vx&a.vy==b.vy&&a.cx<b.cx)return true;
    if(a.vx==b.vx&&a.vy==b.vy&&a.cx==b.cx&&a.cy<b.cy)return true;
    return false;
}
inline bool operator==(const Data &a,const Data &b){
    return a.vx==b.vx&&a.vy==b.vy&&a.cx==b.cx&&a.cy==b.cy;
}
int main(){
    int n;
    for(;;){
        scanf("%d",&n);
        if(n==0)break;
        vector<pair<int,int> > ins(n);
        for(int i=0;i<n;i++){
            int x,y;
            scanf("%d%d",&x,&y);
            ins[i]=make_pair(x,y);
        }
        vector<Data> high,mid,low;
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                int tx=ins[i].first-ins[j].first,ty=ins[i].second-ins[j].second;
                Data d;
                if(tx>=0){
                    d.vx=tx;
                    d.vy=ty;
                }else{
                    d.vx=-tx;
                    d.vy=-ty;
                }
                d.cx=(ins[i].first+ins[j].first)/2;
                d.cy=(ins[i].second+ins[j].second)/2;
                if(d.vy==0)mid.push_back(d);
                else if(d.vy>0)high.push_back(d);
                else low.push_back(d);
            }
        }
        sort(&high[0],&high[0]+high.size());
        sort(&mid[0],&mid[0]+mid.size());
        sort(&low[0],&low[0]+low.size());
        int ma=0;
        for(int i=0;i<mid.size();i++){
            if(binary_search(high.begin(),high.end(),Data(0,mid[i].vx,mid[i].cx,mid[i].cy))||binary_search(low.begin(),low.end(),Data(0,-mid[i].vx,mid[i].cx,mid[i].cy)))ma=max(ma,men(mid[i]));
        }
        for(int i=0;i<high.size();i++){
            if(binary_search(low.begin(),low.end(),Data(high[i].vy,-high[i].vx,high[i].cx,high[i].cy)))ma=max(ma,men(high[i]));
        }
        printf("%d\n",ma);
    }
}

Measured memory_bytes: 0
n=int(input())
dic=dict()
for _ in range(n):
    s=input()
    if s in dic:
        dic[s] +=1
    else:
        dic[s]=1
m=max(dic.values())
dic=sorted(dic.items(),key=lambda x: x[0])
for i in range(len(dic)):
    if dic[i][1]==m:
        print(dic[i][0])

Measured memory_bytes: 46232
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>

using namespace std;


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

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

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n,a,b;
  cin>>n>>a>>b;
  if(abs(a-b)%2==0) cout<<abs(a-b)/2<<endl;
  else{
    int num=min(min(a,b),n+1-max(a,b));
    int x=abs(a-b);
    x--;
    cout<<num+(x/2)<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int static dp[100001];
int frog(vector<int>&a,int n,int current)
{
    if(current+1==n)
        return 0;
    if(dp[current]!=-1)
        return dp[current];
    int A=INT_MAX,B=INT_MAX;
    if(current+1<n)
        A=abs(a[current]-a[current+1])+frog(a,n,current+1);
    if(current+2<n)
        B=abs(a[current]-a[current+2])+frog(a,n,current+2);
    dp[current]=min(A,B);
    return dp[current];
}

int main() {
    memset(dp,-1,sizeof(dp));
	int n;
	cin>>n;
	vector<int>height;
	for(int i=0;i<n;i++)
	{
	    int x;
	    cin>>x;
	    height.push_back(x);
	}
	cout<<frog(height,n,0);
	return 0;
}

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

char s[2][2001];
int dp[2002][2002][2], n[2];
int main() {
	scanf("%d%d%s%s", &n[0], &n[1], s[0], s[1]);
	int Max = 0;
	for (int i = n[0]; i >= 0; i--)for (int j = n[1]; j >= 0; j--)rep(t, 2)rep(k, 2) {
		int a = (k ? dp[i][j + 1][!t] : dp[i + 1][j][!t]), b = (k ? j : i);
		if (b == n[k] || a%2 == t)continue;
		if (t != (s[k][b] != 'I'))dp[i][j][t] = max(dp[i][j][t], a + 1);
		if (dp[i][j][t]%2)Max = max(Max, dp[i][j][t]);
	}
	printf("%d\n", Max);
}

Measured memory_bytes: 34524
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

#define DIV 1000000007
using namespace std;

string S;
int main(){
	cin >> S;
	int ans = 0;
	int now = 0;
	for(int i = 0; i < S.size(); i++){
		if(S[i] == 'S'){
			now++;
		}else{
			if(now>0){
				ans++;
				now--;
			}
		}
	}
	cout << S.size() - 2 * ans << endl;

}


Measured memory_bytes: 1152
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

int main(){
  ll n,m; cin >> n >> m;
  map<ll,ll,greater<ll>> mp;
  rep(i,n){
    ll a; cin >> a;
    mp[a]++;
  }
  rep(i,m){
    ll b,c; cin >> b >> c;
    mp[c] += b;
  }
  
  ll ans = 0;
  ll cnt = 0;
  for(auto m:mp){
    //printf("%d -> %d\n",m.first, m.second);
    if(cnt+m.second > n){
      ans += m.first*(n-cnt);
      break;
    }else{
      ans += m.first*m.second;
      cnt += m.second;
    }
  }
  
  cout << ans << endl;

  
  return 0;
}


Measured memory_bytes: 12800
import sys, bisect, math, itertools, string, queue, copy
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

l = []
n = inp()
for i in range(1, n+1):
    r = input().split()
    s = r[0]
    p = int(r[1])
    l.append([i, s, p])
ans = sorted(l, key=lambda x:(x[1], -x[2]))
for t in ans:
    print(t[0])


Measured memory_bytes: 74828
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;
//debug 
#ifdef _DEBUG
#define debug(var)  do{cout << #var << " :";view(var);}while(0)
#else
#define debug(...)
#endif
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vector<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vector<vector<T> >& vv){ for(const auto& v : vv){ view(v); } }


int main(){
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  //累積和
  vector<int> sum(n);
  sum[0] = 0;
  int tmpsum = 0;
  REP(i,n-1){
    if(s[i] == 'A' && s[i+1] == 'C') tmpsum++;
    sum[i+1] = tmpsum; 
  }
  debug(sum);

  REP(i,q){
    int l, r;
    cin >> l >> r;
    --l, --r;
    int ans = sum[r] - sum[l];
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3788
#include<cstdio>
#include<algorithm>
using namespace std;
int f(int a,int b,int c)
{
	if(a==b&&b==c&&a-'+')return a;
	return 0;
}
int main()
{
	char s[10];
	int i,c;
	while(c=0,scanf("%s",s),s[0]-'0')
	{
		scanf("%s%s",&s[3],&s[6]);
		for(i=0;i<3;++i)c=max(max(c,f(s[i*3],s[i*3+1],s[i*3+2])),f(s[i],s[i+3],s[i+6]));
		c=max(c,max(f(s[0],s[4],s[8]),f(s[2],s[4],s[6])));
		if(c)printf("%c\n",c);
		else puts("NA");
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N, K; 
  cin >> N >> K;

  vector<int> A(N+1);
  FOR(i, 1, N+1){
    cin >> A[i];
    A[i]--;
    (A[i] += A[i-1]) %= K;
  }

  map<int, int> m;

  int ans = 0;
  REP(i, N+1){
    if(i-K >= 0) m[A[i-K]]--;
    ans += m[A[i]];
    m[A[i]]++;
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 14336
#include <iostream>
#include <string>
#include <set>
using namespace std;
int main() {
    string s;
    int K;
    cin >> s >> K;
    set<string> t;
    for (int i = 0; i < s.size(); i++) for (int j = 1; j <= K; j++) t.insert(s.substr(i, j));
    auto itr = t.begin();
    for (int i = 0; i < K - 1; i++) itr++;
    cout << *itr << endl;
}


Measured memory_bytes: 1664
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
using namespace std;
const int INF=0x3f3f3f3f;
int n,m,head[1001],cur[1001],dis[1001],s,t,tot;
char d[205][205];
queue <int> q;
struct data {
    int next,num,w;
}edge[100001];
void add(int u,int v,int w) {
    edge[++tot].next=head[u];
    edge[tot].num=v;
    edge[tot].w=w;
    head[u]=tot;
}
bool BFS() {
    q.push(s);
    memset(dis,0x3f,sizeof(dis));
    dis[s]=0;
    while (!q.empty()) {
        int k=q.front();
        q.pop();
        for (int i=head[k];i!=-1;i=edge[i].next) {
            if (edge[i].w==0) continue;
            int kx=edge[i].num;
            if (dis[k]+1<dis[kx]) {
                dis[kx]=dis[k]+1;
                q.push(kx);
            }
        }
    }
    if (dis[t]==INF) return 0;
    return 1;
}
int DFS(int x,int a) {
    if (x==t) return a;
    if (a==0) return 0;
    int flow=0;
    for (int &i=cur[x];i!=-1;i=edge[i].next) {
        int kx=edge[i].num;
        if (dis[kx]!=dis[x]+1) continue;
        int now=DFS(kx,min(a,edge[i].w));
        flow+=now;
        edge[i].w-=now;
        edge[i^1].w+=now;
        a-=now;
        if (a==0) return flow;
    }
    return flow;
}
int dinic() {
    int flow=0;
    while (BFS()) {
        for (int i=1;i<=n+m+2;i++) cur[i]=head[i];
        flow+=DFS(s,INF);
    }
    return flow;
}
int main() {
    memset(head,-1,sizeof(head));
    tot=-1;
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++) scanf("%s",d[i]+1);
    s=n+m+1;
    t=n+m+2;
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++) {
            if (d[i][j]=='S') {
                add(s,i,INF);
                add(i,s,0);
                add(s,n+j,INF);
                add(n+j,s,0);
            }
            if (d[i][j]=='T') {
                add(i,t,INF);
                add(t,i,0);
                add(n+j,t,INF);
                add(t,n+j,0);
            }
            if (d[i][j]=='o') {
                add(i,n+j,1);
                add(n+j,i,0);
                add(n+j,i,1);
                add(i,n+j,0);
            }
        }
    int ans=dinic();
    if (ans>1e9) printf("-1\n");
    else printf("%d\n",ans);
    return 0;
}


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

using namespace std;

/*  テンプレここから */
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define out(x) cout << (x) << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

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

    int n;
    cin >> n;

    double sum = 0;
    rep(i, n){
        double money;
        string type;
        cin >> money >> type;

        if(type == "JPY") sum += money;
        else sum += money * 380000;
    }

    cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <stack>
#include <utility>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>
using namespace std;
typedef long long int lld;
typedef pair<int, int> pii;

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  int BCs = 0;
  lld ans = 0;
  string cad = "";
  for (int i = s.size()-1; i >= 0; --i) {
    if (s[i] == 'A') {
      if (cad != "") {
        BCs = 0;
        cad = "";
      } 
      ans += BCs;
    } else cad += s[i];
    if (cad == "B") {
      BCs = 0;
      cad = "";
    }
    if (cad == "CB") {
      BCs++;
      cad = "";
    } else if (cad.size() == 2) {
      BCs = 0;
      cad.pop_back();
    }
  }
  cout << ans << "\n";
  return 0;
}

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

int main(){
    int N;

    scanf("%d", &N);

    int *A = (int *) malloc(sizeof(int) * N);
    int **x = (int **) malloc(sizeof(int * ) * N);
    int **y = (int **) malloc(sizeof(int *) * N);
    int *bits = (int *) malloc(sizeof(int *) * N);

    for(int i = 0; i < N; i ++){
        scanf("%d", A + i);

        x[i] = (int *) malloc(sizeof(int) * A[i]);
        y[i] = (int *) malloc(sizeof(int) * A[i]);

        for(int j = 0; j < A[i]; j ++){
            scanf("%d%d", x[i] + j, y[i] + j);
        }
    }
    int max_num = 0;
    int flag;

    for(int b = 0; b < (1 << 15); b ++){
        for(int i = 0; i < N; i ++){
            bits[i] = (b >> i) & 1;
        }
        flag = 0;

        for(int i = 0; i < N; i ++){
            if(bits[i] == 1){
                for(int j = 0; j < A[i]; j ++){
                    if(bits[x[i][j] - 1] != y[i][j]){
                        flag = 1;

                        break;
                    }
                }
            }
            if(flag == 1){
                break;
            }
        }
        if(flag == 1){
            continue;
        }
        int num = 0;

        for(int i = 0; i < N; i ++){
            num += bits[i];
        }
        if(num > max_num){
            max_num = num;
        }
    }
    printf("%d\n", max_num);
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String a = br.readLine();

        if(a.contains("7")){
            System.out.println("Yes");
        }
        else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 32680
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=1e5+9;
int main()
{
    FASTINOUT;
    string s;
    cin>>s;
    int c=0;
    for (int i=0;i<s.length();i++){
        if (s[i]=='+')
            c++;
        else
            c--;
    }
    cout<<c;
    return 0;
}


Measured memory_bytes: 256
N, Y = map(int, input().split())

for a in range(N + 1):
    for b in range(N + 1 - a):
        if 10000 * a + 5000 * b + 1000 * (N - a - b) == Y:
            print(a, b, N - a - b)
            break
    else:
        continue
    break
else:
    print(-1, -1, -1)


Measured memory_bytes: 9160
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

if V <= W:
  f = False
else:
  t = abs(B - A) / (V - W)
  if t <= T:
    f = True
  else:
    f = False

print("YES" if f else "NO")

Measured memory_bytes: 9184
#include<iostream>
using namespace std;
int main(){
    int a[5];
    for(int i=0;i<5;i++){
        cin >> a[i];
    }
    if(a[2]-a[4] >= 0 && a[2] + a[4] <= a[0]){
        if(a[3] - a[4] >= 0 && a[3]+a[4] <= a[1]){
            cout << "Yes" << endl;
        }else {
            cout << "No" << endl;
        }
    }else {
        cout << "No" << endl;
    }
    return 0;
    
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define int long long
#define INF 1000000007
#define SMO -1000000007
using namespace std;
bool prime(int n){
	for(int i=2;i<=sqrt(n);i++){
		if(n%i==0)return false;
	}
	return n!=1;
}
int kaicnt;
int kai(int n,int x){
	kaicnt++;
	if(kaicnt==x){
		kaicnt=0;
		return n%INF;
	}
	return (kai(n-1,x)%INF*n)%INF;
}
int conbi(int n,int x){
	x=min(x,n-x+1);
	return kai(n,x)/kai(x,x);
}
int n,m,x,y;
pair<bool,int>p[100005];
signed main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		if(i>1)p[i].first=false,p[i].second=1;
		else p[i].first=true,p[i].second=1;
	}
	for(int i=0;i<m;i++){
		cin>>x>>y;
		if(p[x].first&&p[x].second==1){
			p[x].first=false;
			p[x].second--;
			p[y].first=true;
			p[y].second++;
		}else if(p[x].first){
			p[x].second--;
			p[y].first=true;
			p[y].second++;
		}else {
			p[x].second--;
			p[y].second++;
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(p[i].first)ans++;
	}
	cout<<ans<<endl;
}

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

int main (){
    ll a, b;
    while (~scanf("%lld%lld", &a, &b)){
        ll ans = 1;
        while (a*2 <= b){
            ans += 1;
            a *= 2;
        }
        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 256
n = gets.to_i
s = Array.new(n) {gets.chomp}
ac_cnt = s.count("AC")
wa_cnt = s.count("WA")
tle_cnt = s.count("TLE")
re_cnt = s.count("RE")

puts "AC x #{ac_cnt}"
puts "WA x #{wa_cnt}"
puts "TLE x #{tle_cnt}"
puts "RE x #{re_cnt}"

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

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      long h = sc.nextLong();
      long w = sc.nextLong();
      if(h == 1 || w == 1) {
          System.out.println(1);
          return;
      }
      long cnt = h / 2 * w;
      if(h % 2 != 0) {
        cnt += (w + 2 - 1) / 2;
      }
      System.out.println(cnt);
  }
}


Measured memory_bytes: 23252
#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<algorithm>
using namespace std;
int solve(){
    int m,n;
    cin>>m>>n;
    vector<vector<int>> mat(m,vector<int>(n,0));
    for(int i=0;i<m;i++){
        for(int j=0; j<n;j++){
            cin>>mat[i][j];
        }
    }
    for(int i =0;i<m;i++){
        for(int j = 0;j<n;j++){
            int x;
            cin>>x;
            if(mat[i][j]>=x){
                mat[i][j]-=x;
            }
            else mat[i][j] = x-mat[i][j];
        }
    }

    vector<vector<bool>> dp(n,vector<bool>(25602,false));
    dp[0][12800] = true;
    // cout<<dp[0][6400]<<endl;
    for(int i = 0;i<m;i++){
        vector<vector<bool>> tdp(n,vector<bool>(25602,false));
        vector<bool> pre(25602,false);
        for(int j = 0;j<n;j++){
            for(int k = -12800;k<=12800;k++){
                if(dp[j][k+12800] == false && pre[k+12800]==false) continue;
                tdp[j][k+12800-mat[i][j]] = true;
                tdp[j][k+12800+mat[i][j]] = true;
            }
            pre = tdp[j];
        }
        dp = tdp;
    }
    int res = 25602;
    // cout<<res<<endl;
    for(int i = 0;i<25602;i++){
        if(dp[n-1][i]== false) continue;
        res = min(res,abs(i-12800));
    }
    // cout<<res<<endl;
    return res;
}

int main(){
    int T = 1;
    while(T--){
        int res = solve();
        cout<<res<<endl;
    }
    return 0;
}

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

int main(){
    long long x,k,d;
    cin >> x >> k >> d;

    long long ans;
    if (x > 0){
        if (k <= x/d) ans = x - d*k;
        else {
            if ((x/d)%2 == k%2) ans = x%d;
            else ans = -(x%d-d);
        }
    }
    else if (x < 0){
        if (k <= -x/d) ans = -(x + d*k);
        else {
            if ((-x/d)%2 == k%2) ans = -x%d;
            else ans = x%d+d;
        }
    }
    else{
        if (k%2 == 0) ans = 0;
        else ans = d;
    }

    cout << ans << "\n";
}


Measured memory_bytes: 3632
#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>

using namespace std;

long long N,D;
long long A;
long long B;
long long C[200000] = {};
long long result=0;

typedef pair<long long, long long> pl;
vector<pl> re;
vector<pl> bl;
pl buf;

long long an=0;
long long ma =5000000000;
long long E,yobun;

int main() {

	cin >>N;
	E = 0;
	yobun = 0;
	
	for (int i = 0; i < N; i++) {
		cin >> A;
		cin >> B;
		
		if (A < B) {
			D =1;
			result += B;
			yobun += B - A;
		}
		else if(A > B){
			if (ma > B) {
				ma = B;
			}
		}
		E += A;

		C[i] = A-B;
	}
	if (D > 0) {
		result = E-ma;
	}
	else {
		result = 0;
	}






	cout << result << endl;

return 0;
}

Measured memory_bytes: 512
#include <cstdio>
int main()
{
    int D;
    scanf("%d", &D);
    if (D == 25)
    {
        printf("Christmas");
    }
    else if (D == 24)
    {
        printf("Christmas Eve");
    }
    else if (D == 23)
    {
        printf("Christmas Eve Eve");
    }
    else if (D == 22)
    {
        printf("Christmas Eve Eve Eve");
    }
    
        
    return 0;
}



Measured memory_bytes: 128
#include <stdio.h>          // printf(), fgets()
#include <ctype.h>          // toupper()

#define N 200
static const int NUL = '\0';

int
main(int argc, char** argv)
{
	char line[N + 1];
	char* p;

	fgets(line, sizeof(line), stdin);
	for (p = line; *p != NUL; ++p)
		*p = toupper(*p);

	printf("%s", line);
	return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;
ll check(ll a,ll b){
	if((a<=0&&b<=0)||(a>=0&&b>=0)){
		return max(abs(a),abs(b));
	}else{
		return abs(a-b)+min(abs(a),abs(b));
	}
}

int main(){
	int N,K;
	ll x[100005];
	cin>>N>>K;
	ll ans = 1e9;
	for(int i = 0;i < N;i++){
		cin>>x[i];
	}
	for(int i = 0;i <= N-K;i++){
		int j = i+K-1;
		ans = min(ans,check(x[i],x[j]));
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1024
x,y=map(int,input().split())

ans=0
if x == 3:
  ans += 100000
if x == 2:
  ans += 200000
if x == 1:
  ans += 300000
  
if y == 3:
  ans += 100000
if y == 2:
  ans += 200000
if y == 1:
  ans += 300000
  
if x == y == 1:
  ans += 400000
  
print(ans)

Measured memory_bytes: 9192
def main():
	n,k = map(int,input().split())
	da = []
	for i in range(k*2):
		da.append(list(map(int,input().split())))
	okashi = []
	for i in range(1,k*2,2):
		if len(da[i]) > 1:
			for s in range(len(da[i])):
				okashi.append(da[i][s])
		else:
			okashi.append(da[i][0])
	print(n - len(set(okashi)))




if __name__ == '__main__':
	main()

Measured memory_bytes: 67932
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int N, K;
int A[200010];
int cnt[200010];

int main () {
  cin >> N >> K;
  fill(cnt, cnt+200010, 0);
  for (auto i = 0; i < N; ++i) {
    cin >> A[i];
    cnt[A[i]]++;
  }
  vector<int> V;
  for (auto i = 1; i <= N; ++i) {
    if (cnt[i] > 0) {
      V.push_back(cnt[i]);
    }
  }
  int ans = 0;
  sort(V.begin(), V.end());
  int s = V.size();
  for (auto x : V) {
    if (s <= K) break;
    ans += x;
    s--;
  }
  cout << ans << endl;
}


Measured memory_bytes: 2936
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <map>
#include <set>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define sz(x) int(x.size())

typedef long long ll;

using namespace std;

static const int MAX = 2001;

/******* c++14 don't include *******/

template<typename T>
T gcd(T a, T b){if( b == 0)return a; return gcd(b, a%b); }
template<typename T>
T lcm(T a, T b){return a*b/gcd(a,b); }

/*******                      *******/

int main(int argc, const char * argv[]) {
    // input from txt
    
    /////////
    //write//
    /////////
    
    int n, m;
    string a[MAX];
    string b[MAX];
    
    cin >> n >> m;
    rep(i, n){
        cin >> a[i];
    }
    rep(i, n){
        cin >> b[i];
    }
    ll res = 0;
    rep(i, n){
        rep(j, m){
            if(a[i][j] != b[i][j])res++;
        }
    }
    
    cout << res << endl;
    return 0;
}



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

namespace agc030_a
{
    class Program
    {
        static void Main(string[] args)
        {
            var text = Console.ReadLine();
            var list = text.Split(' ').ToList().Select(x => int.Parse(x)).ToList();

            var a = list[0];

            var items = new List<hoge>();
            for(int i = 0; i < a; i++)
            {
                text = Console.ReadLine();
                var lista = text.Split(' ').ToList();

                var item = new hoge();

                item.a = lista[0];
                item.b = int.Parse(lista[1]);
                item.c = i + 1;

                items.Add(item);
            }

            var restrants = items.OrderBy(x => x.a).ThenByDescending(x => x.b).ToList();
            foreach(var r in restrants){
                Console.WriteLine(r.c);

            }


        }
    }

    class hoge{
        public string a;
        public int b;

        public int c;
    }
}


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

int main() {
    ll n;
    cin >> n;
    ll ans = 1e18;
    for (ll i = 1; i * i <= n; ++i)
    {
        if (n%i != 0)
            continue;
        ll j = n / i;
        ans = min(ans, i + j - 2);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string outputYesNo(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int n,m;cin>>n>>m;
  cout<<outputYesNo(n==m)<<endl;
  return 0;
}


Measured memory_bytes: 256
import bisect

N = int(input())
L = list(map(int,input().split()))
L.sort()
ans = 0

for i in range (0,N-2): #最小辺
  for j in range (i+1,N-1): #2番目の辺
    ij = L[i] + L[j]
    k = bisect.bisect_left(L,ij)
    ans = ans + k - j - 1
print(ans)

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

import math
import sys
import heapq
from operator import itemgetter
import itertools
input = sys.stdin.readline

# a = int(input().rstrip())
# a, b = map(int, input().rstrip().split())
# D = list(map(int, input().rstrip().split()))
# H = [int(input().rstrip()) for _ in range(L)]
# DD = [[0 for j in range(100)] for i in range(200)]
# dict = {} ## dictionary

# a = sorted(a, key=lambda x: x[1]))
# if __name__ == '__main__':

n = str(input().rstrip())

for i in n:
	if i == '1':
		print(9, end="")
	elif i == '9':
		print(1, end="")
print()

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[110000];
ll ww[110],v[110];
int main()
{
    int n,w;cin>>n>>w;
    for(int i=1;i<=n;i++)cin>>ww[i]>>v[i];
    memset(dp,0x3f, sizeof(dp));
    dp[0]=0;
    for(int i=1;i<=n;i++)
        for(int j=100000;j>=v[i];j--)
            if(dp[j-v[i]]+ww[i]<=w)
            dp[j]=min(dp[j],dp[j-v[i]]+ww[i]);
    int maxx=0;
    for(int i=1;i<=100000;i++)
        if(dp[i]<=w)maxx=i;
    cout<<maxx<<endl;
    return 0;
}

Measured memory_bytes: 1152
<?php
// Your code here!
$n = (int)trim(fgets(STDIN));
// var_dump($n);
$left = 0;
$right = 0;
for($i=0; $i<$n; $i++){
    $cards = explode(" ", trim(fgets(STDIN)));
    // var_dump($cards[0]);
    if(strcmp($cards[0], $cards[1]) == 0){
        $left += 1;
        $right += 1;
    }elseif(strcmp($cards[0], $cards[1]) < 0){
        $right += 3;
    }else{
        $left += 3;
    }
}
echo $left,' ', $right, PHP_EOL;


Measured memory_bytes: 9224
from math import sqrt,ceil
N=int(input())
if N<105:
    print("0")
    exit()
ans=0
for n in range(105,N+1):
    cnt=0
    if n%2==0:
        continue
    for i in range(1,ceil(sqrt(n))):
        if n%i==0:
            cnt+=1
    if cnt==4:
        ans+=1
print(ans)

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

const int N=1000010,mod=998244353;
int tag[N<<2],n,a[N],k,ci[N],num[N],ans[N];

#define ls now<<1
#define rs now<<1|1
void psd(int now){
	if(tag[now]){
		ans[ls]=1ll*tag[now]*num[ls]%mod;
		ans[rs]=1ll*tag[now]*num[rs]%mod;
		tag[ls]=tag[now];
		tag[rs]=tag[now];
		tag[now]=0;
	}
}

void pre(int now,int l,int r){
	if(l==r) {ans[now]=num[now]=ci[n-r];return ;}
	int mid=(l+r)/2;
	pre(ls,l,mid);pre(rs,mid+1,r);
	ans[now]=num[now]=(num[ls]+num[rs])%mod;
}

void add(int now,int x,int y,int t,int l=1,int r=n){
	if(l==x && r==y) {
		ans[now]=1ll*t*num[now]%mod;
		tag[now]=t;
		return ;
	}
	psd(now);
	int mid=(l+r)/2;
	if(y<=mid) add(ls,x,y,t,l,mid);
	else if(mid<x) add(rs,x,y,t,mid+1,r);
	else add(ls,x,mid,t,l,mid),add(rs,mid+1,y,t,mid+1,r);
	ans[now]=(ans[ls]+ans[rs])%mod;
}

int main(){
	scanf("%d %d",&n,&k);tag[1]=1;
	int x,y,l,r;
	ci[0]=1;for(int i=1;i<=n;i++) ci[i]=1ll*ci[i-1]*10%mod;
	pre(1,1,n);
	for(int i=1;i<=k;i++)
		scanf("%d %d %d",&x,&y,&l),add(1,x,y,l),printf("%d\n",ans[1]);
}

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

//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4"

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define ll long long
#define int ll
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define VAR(v, i) __typeof( i) v=(i)
#define forit(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
 
using namespace std;
 
const int maxn = (int)2e5+100;
const int mod = (int)1e9 + 7;
 
#define inf mod
 
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;   
typedef vector<ll> Vll;               
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;

int n;
struct matrix{
  int a[70][70];
  matrix(){
    forn(i,0,n-1)
      forn(j,0,n-1)
        a[i][j]=0;
  }
};
matrix mult(matrix a, matrix b){
  matrix c;
  forn(i,0,n-1)
    forn(j,0,n-1)
      forn(k,0,n-1)
        c.a[i][j]=(c.a[i][j]+(a.a[i][k]*b.a[k][j])%mod)%mod;
  return c;
}
matrix binpow(matrix a, int b){
  matrix res;
  forn(i,0,n-1)res.a[i][i]=1;
  while(b){
    if(b&1)
      res=mult(res,a);
    b>>=1;
    a=mult(a,a);
  }
  return res;
}
matrix s;
int k,res;
main () {
  cin>>n>>k;
  forn(i,0,n-1)
    forn(j,0,n-1)
      cin>>s.a[i][j];
  s=binpow(s,k);
  forn(i,0,n-1)
    forn(j,0,n-1)
      res=(res+s.a[i][j])%mod;
  cout<<res;
}

Measured memory_bytes: 512
/* ****revpro**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl       '\n'
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)    
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define mii        map<ll,ll>
using namespace std;

#define N  100005

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        ll n,m;
        cin>>n>>m;
        string c;
        ll g[n+1][m+1],dp[n+1][m+1];
        rep(i,0,n+1)
        rep(j,0,m+1)
        dp[i][j]=0;
        dp[0][1]=1;
        rep(i,1,n+1){cin>>c;
        rep(j,1,m+1)
        {
            if(c[j-1]=='.')
                g[i][j]=1;
            else g[i][j]=0;
        }}
        rep(i,1,n+1)
        {
            rep(j,1,m+1)
            {
                if(g[i][j]==1)
                    dp[i][j]=(dp[i-1][j]+dp[i][j-1])%hell;
                else dp[i][j]=0;
            }
        }
        cout<<dp[n][m];
    }
    return 0;
}

Measured memory_bytes: 15872
s = input()
s = s[::-1]
l = "dream dreamer erase eraser".split()
l = [i[::-1] for i in l]


while len(s) > 0:
    flag = False
    for i in l:
        n = len(i)
        if s[:min(n, len(s))] in i:
            s = s[min(n, len(s)):]
            flag = True
            break
    if not flag:
        print("NO")
        exit()
print("YES")

Measured memory_bytes: 3188
n = int(input())
s = input()
ss = [0] * n
rr = [0] * n
ans_i = 0
ans = 0
tmp = 0
max = -10**9
for i in range(n):
    if s[i] == 'E':
        tmp += 1
    else:
        tmp -= 1
    ss[i] = tmp

tmp = 0
for i in range(n)[::-1]:
    if s[i] == 'W':
        tmp += 1
    else :
        tmp -= 1
    rr[i] = tmp

for i in range(n):
    if ss[i] + rr[i] > max:
        max = ss[i] + rr[i]
        ans_i = i

for i in range(0,ans_i):
    if s[i] == 'W':
        ans += 1
for i in range(ans_i+1,n):
    if s[i] == 'E':
        ans += 1
print(ans)
        

Measured memory_bytes: 45924
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N;
	string S;
 
	cin >> N >> S;
 
	int cnt1 = 0;
	int cnt2 = 0;
	for( int i = 0; i < N; i++ ) {
		if( S[i] == '.' ) {
			cnt2++;
		}
	}
	int ans = N;
	ans = min( ans, cnt1 + cnt2 );
	for( int i = 0; i < N; i++ ) {
		if( S[i] == '#' ) {
			cnt1++;
		}
		else {
			cnt2--;
		}
		ans = min( ans, cnt1 + cnt2 );
	}
 
	cout << ans << endl;
 
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define N ((ll)330)
#define INF ((ll)1e18)
#define MOD ((ll)1e9+7)

ll n,m,num[N][N],dp[N][N],ans;
string s[N];

int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>s[i];
	
	for(int t=0;t<m-1;t++)
	{
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				num[i][j]=(s[i][t]==s[j][t+1])+num[i-1][j-1];
		for(int i=0;i<=n;i++)
			for(int j=0;j<=n;j++)
				if(i || j)
					dp[i][j]=min((i)?dp[i-1][j]+num[i][j]:INF,(j)?dp[i][j-1]+num[i][j]:INF);
		ans+=dp[n][n];
	}
	cout<<ans;
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int sum = 0;
  rep(i, n) sum ^= a[i];
  cout << (sum == 0 ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 3752