akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    string s; int k;
    cin>>s>>k;
    int n=s.size();
    rep(i,n){
        if(26-(s[i]-'a')<=k){if(s[i]!='a')k-=26-(s[i]-'a'); s[i]='a';}
    }
    if(k!=0&&k%26!=0)s[n-1]=(s[n-1]-'a'+k%26)%26+'a';
    cout<<s<<endl;
    return 0;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MAX_N 3
#define MAX_M 5
typedef pair<i64, i64> P;
i64 N, M;
P C[MAX_M];
i64 x[MAX_N];

void solve() {
    i64 minv, maxv;
    if (N == 1) {
        minv = 0;
        maxv = 99;
    } else if (N == 2) {
        minv = 10;
        maxv = 100;
    } else {
        minv = 100;
        maxv = 999;
    }

    string is;
    i64 min_n = 10000;
    for (i64 i = minv; i <= maxv; i++) {
        is = to_string(i);
        bool ok = true;
        REP(i, M) {
            P p = C[i];
            if (p.F >= N) {
                cout << -1 << endl;
                return;
            }
            ok = ok && ((is[p.F] - '0') == p.S);
        }
        if (ok) chmin(min_n, i);
    }

    if (min_n == 10000) {
        cout << -1 << endl;
        return;
    }

    cout << min_n << endl;
}

int main() {
    cin >> N >> M;
    i64 s, c;
    REP(i, M) {
        cin >> s >> c;
        s--;
        C[i] = mp(s, c);
    }
    solve();

    return 0;
}

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

#define ll long long int
#define f(i,x,n)  for(int i=x;i<n;i++)
#define FASTIO cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define sz(a) int((a).size())
#define mod 1000000007
#define inf LLONG_MAX
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
template <typename T>
inline T gcd(T a, T b)
{
    while (b != 0) swap(b, a %= b);
    return a;
}

template <typename T>
inline void seethis(vector<T>vect)
{
    for(T x : vect)
        cout << x << " ";
    cout << "\n";
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
//LCM
int lcm(int a, int b)
{
    return a * (b / gcd(a, b));
}

//For sort by second
bool cmp(const pair<int, int> &a)
{
    return a.first < a.second;
}

//Tree
/* const int MAXN = 1e5 + 5;
vector<ll> adj[MAXN];*/

//ModPower
ll modpower(ll a, ll b, ll c)
{
    ll res = 1;
    while(b)
    {
        if(b & 1LL)
            res = (res * a) % c;
        a = (a * a) % c;
        b >>= 1;
    }
    return res;
}

int main()
{
    FASTIO;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    string s, t;
    cin >> s >> t;

    
    int len = s.length();
    int len2=t.length();
    int ans=len2;

    for(int i = 0; i <=  len-len2; i++)
    {
        int index=i;
        int j=0;
        int temp=0;
        for(int j=0;j<len2 and index<len;j++)
        {
          if(s[index]==t[j])
          {
            temp++;
          }
          index++;
        }
        ans=min(ans,len2-temp);
    }

    cout<<ans<<"\n";

    return 0;
}

Measured memory_bytes: 3584
#include <iostream>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #define int long long int
    int n,k;
    cin>>n>>k;
    int s=n/k;
    n=n-(s*k);
    while(1)
    {
        if(n>abs(n-k))n=abs(n-k);
        else break;
    }
    cout<<n<<endl;
    return 0;
}


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

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;

namespace atcoder {
	void judge_outer(bool judge_exp, string ok = "Yes", string ng = "No")
	{
		if (judge_exp) {
			cout << ok << endl;
		}
		else {
			cout << ng << endl;
		}
	}

	int ncr(int left, int right)
	{
		right = min(left - right, right);
		int ans = 1;
		for (int i = 1; i <= right; i++) {
			ans = ans * (left - right + i) / i;
		}
		return ans;
	}

	const int LIMIT = 1000000256;
	const int tenfive = 100100;
}

using namespace atcoder;

int main()
{
	int a, b;
	cin >> a >> b;
	cout << a + b / 2 << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define fi first
#define se second
using namespace std;
typedef pair<int,int> ii;

const ll siz = 2e5 + 10;
const ll SIZ = 1e6 + 10;
const ll mod = 1e9 + 7;
const ll maxx = 2e9;
const ll MAXX = 1e18;
const ll base = 31;

string s;

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//    freopen ("IN_3.INP", "r", stdin);
//    freopen ("OUT_3.OUT", "w", stdout);
    cin >> s;
    for (int i = 0; i < s.size(); i++)
        if (s[i] == '7')
        {
            cout << "Yes";
            return 0;
        }
    cout << "No";
    return 0;
}

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

int main(){
    vector<int> a(5);
    cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
    vector<int> p={0,1,2,3,4};
    int ans2=inf;
    do{
        int ans = 0;
        for(int i=0;i<5;i++){
            while(ans%10!=0)ans++;
            ans += a[p[i]];
        }
        ans2 = min(ans2,ans);
    }while(next_permutation(p.begin(),p.end()));
    cout << ans2 << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <iostream>

using namespace std;
 
#define true 1;
#define false 0;
 
int main(){
    int n,cnt,N=123456;
    char is_prime[1000000];
   
    for( int i = 0 ; i <= 2*N ; i++ ) is_prime[i] = true;
   
    is_prime[0] = is_prime[1] = false; 
   
    for( int i = 2 ; i*i <= 2*N ; i++ ){
	if( is_prime[i] ){
	    for( int j = i*2 ; j <= 2*N ; j += i ){
		is_prime[j] = false;
	    }
	}
    }
   
    while(1){
	cnt = 0;
 
	cin >> n;
	if( n == 0 ) break;
 
	for( int i = n + 1 ; i <= 2*n ; i++ ){
	    if( is_prime[i] ) cnt++;
	}
	cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 3252
' Imports System.Collections.Generic
' Imports System.Text.RegularExpressions

Class Main
    Public Shared Sub Main()
        Dim K = Console.ReadLine()
        Dim A, B As Integer
        Dim arr() As String
        arr = Split(Console.ReadLine())
        A = arr(0) : B = arr(1)
        Console.WriteLine(If(A <= Math.Floor(CType(B, Decimal) / K) * K, "OK", "NG"))
        Return
    End Sub
End Class


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

N, M = map(int, input().split())
A = [list(input()) for i in range(N)]
B = [list(input()) for i in range(M)]

# AとBの大きさに応じたループ回数
for i in range(N - M + 1):
    for j in range(N - M + 1):
        # Mの行数で比較のループ
        for k in range(M):
            # 各行についてAとBの一致を確認
            if "".join(A[i+k])[j:j+M] != "".join(B[k]):
                break
            # 全ての行について一致したらYes
            if k == M - 1:
                print("Yes")
                exit()
# 条件に合った箇所がなければNo
print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

ll dp[606][606][6];

int main(){
  int N;
  ll Y;
  cin>>N>>Y;
  vector<ll> A(N);
  rep(i,N) cin>>A[i];
  ll S=0;
  rep(i,N) S+=A[i];
  vector<ll> sum(2*N+1,0);
  for(int i=1;i<=2*N;i++) sum[i]=sum[i-1]+A[(i-1)%N];

  for(int i=0;i<N;i++){
    for(int j=i;j<i+N;j++){
      ll res=sum[j+1]-sum[i];
      if(res+Y>=S/5) dp[i][j][1]=1;
    }
  }

  for(int k=2;k<=5;k++){
    for(int i=0;i<N;i++){
      for(int j=i;j<i+N;j++){
        for(int l=i;l<j;l++){
          dp[i][j][k]+=dp[i][l][1]*dp[l+1][j][k-1];
        }
      }
    }
  }

  //cout<<dp[0][N-1][5]<<endl;
  ll ans=0;
  for(int i=0;i<N;i++) ans+=dp[i][i+N-1][5];
  cout<<ans<<endl;
  

  return 0;
}



Measured memory_bytes: 8516
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#define MOD 1000000007
using namespace std;
int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	cout << c <<" "<< a <<" "<< b << endl;
	return 0;
}

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

void Main() {
    int n, k;
    cin >> n >> k;
    vector<int> H(n);
    for (auto &e : H) {
        cin >> e;
    }
    sort(H.begin(), H.end());
    int ans = 1e9 + 5;
    rep(i, n - k + 1) { ans = min(ans, H[i + k - 1] - H[i]); }
    cout << ans << "\n";
}
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>
#define ll long long
#define mod 100003
#define inf 0x3f3f3f3f
using namespace std;

const int N=105;

int a[N];

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

int main()
{
    int n;
    while(cin>>n)
    {
        for(int i=0;i<n;i++)
            cin>>a[i];
        sort(a,a+n);
        cout<<a[n-1]-a[0]<<endl;
    }
    return 0;
}


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

using namespace std;
int main(){
	int i,n;
	string s;
	cin >> s;
	n = s.size();
	if(s[0]=='0' || s[n-2]=='0' || s[n-1]=='1'){
		cout << -1 << endl;
		return 0;
	}
	for(i=0;i<n-1;i++){
		if(s[i]!=s[n-2-i]){
			cout << -1 << endl;
			return 0;
		}
	}
	int x = 1;
	for(i=0;i<n-1;i++){
		if(s[i]=='1'){
			cout << x << " " << i+2 << endl;
			x = i+2;
		}else{
			cout << x << " " << i+2 << endl;
		}
	}
}
	

Measured memory_bytes: 1664
#include <cstdio>
#include <cstdlib>
#include <cstring>

const int MOD=1e9+7;

void addmod(int& x,int y){x=(x+y)%MOD;}

int dp[100005][3][2][2];
//i, trail sum, cana, canb

int N;
char str[100005];

void zebra(){
  for(int i=1;i<N;i++){
    if(str[i]==str[i-1]) return;
  }
  printf("1\n");
  exit(0);
}

int main(){
  scanf("%s",str);
  N=strlen(str);
  zebra();
  dp[0][0][1][1]=1;
  for(int i=0;i<N;i++){
    str[i]=str[i]-'a'+1;
    for(int s=0;s<3;s++){
      for(int a=0;a<2;a++){
	for(int b=0;b<2;b++){
	  int v=dp[i][s][a][b];
	  int s2=(s+str[i])%3;
	  switch(s2){
	  case 1:
	    if(a) addmod(dp[i+1][0][1][1],v);
	    addmod(dp[i+1][s2][0][b],v);
	    break;
	  case 2:
	    if(b) addmod(dp[i+1][0][1][1],v);
	    addmod(dp[i+1][s2][a][0],v);
	    break;
	  case 0:
	    addmod(dp[i+1][s2][a][b],v);
	    break;
	  }
	}
      }
    }
  }
  int ans=0;
  for(int a=0;a<2;a++){
    for(int b=0;b<2;b++){
      addmod(ans,dp[N][0][a][b]);
    }
  }
  int sum=0;
  for(int i=0;i<N;i++){
    sum=(sum+str[i])%3;
  }
  if(sum==0) addmod(ans,MOD-1);
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 4992
import sys

ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: [int(x) for x in ns().split()]
nall = lambda: [int(x) for x in sys.stdin.readlines()]
sall = lambda: sys.stdin.readlines()

def main():
    n, k = na()

    '''
    for i in range(k, n+1, k):
        for j in range(k, n+1, k):
            if (i + j) % k == 0:
                for m in range(k, n+1, k):
                    if (i+m) % k == 0 and (j+m) % k == 0:
                        print(i, j, m)
    '''
    # kは奇数
    if k % 2 == 1:
        print((n // k) ** 3)
        return
    '''
    c = 0
    for i in range(1, n+1):
        for j in range(1, n+1):
            if (i + j) % k == 0:
                for m in range(1, n+1):
                    if (i+m) % k == 0 and (j+m) % k == 0:
                        print(i, j, m)
                        c += 1
    '''
    # kは偶数
    c = (n//k) ** 3 + (n//(k//2) - n//k)  ** 3
    print(c)

main()


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


struct Node {
    int id;
    int parentId;
    int leftId;
    int rightId;
};


class BinaryTree {

public:
    static const int NIL_ID = -1;
    Node *nodes;

    BinaryTree(int cnt) {
        nodes = (Node *)malloc(sizeof(Node) * cnt);
        for (int i = 0; i < cnt; i++)
        {
            nodes[i] = Node{i, NIL_ID, NIL_ID, NIL_ID};
        }
    }

    ~BinaryTree() {
        delete nodes;
    }

    void push_values(int id, int leftId, int rightId) {
        nodes[id].leftId = leftId;
        nodes[id].rightId = rightId;

        if (leftId != NIL_ID)
            nodes[leftId].parentId = id;
        if (rightId != NIL_ID)
            nodes[rightId].parentId = id;
    }

    void printPreorder(int id) {
        if (id == NIL_ID)
            return;
        cout << " " << id;
        printPreorder(nodes[id].leftId);
        printPreorder(nodes[id].rightId);
    }

    void printInorder(int id) {
        if (id == NIL_ID)
            return;
        printInorder(nodes[id].leftId);
        cout << " " << id;
        printInorder(nodes[id].rightId);
    }

    void printPostorder(int id) {
        if (id == NIL_ID)
            return;
        printPostorder(nodes[id].leftId);
        printPostorder(nodes[id].rightId);
        cout << " " << id;
    }

    int findRootId() {
        Node node = nodes[0];
        int parentId = node.parentId;
        while (parentId != NIL_ID) {
            node = nodes[parentId];
            parentId = node.parentId;
        }
        return node.id;
    }
};


int main() {
    int N;
    int i, id, leftId, rightId;

    cin >> N;

    BinaryTree tree = BinaryTree(N);

    for (i = 0; i < N; i++) {
        cin >> id >> leftId >> rightId;
        tree.push_values(id, leftId, rightId);
    }

    int rootId = tree.findRootId();

    cout << "Preorder" << endl;
    tree.printPreorder(rootId);
    cout << endl;
    cout << "Inorder" << endl;
    tree.printInorder(rootId);
    cout << endl;
    cout << "Postorder" << endl;
    tree.printPostorder(rootId);
    cout << endl;

    return 0;
}



Measured memory_bytes: 3104
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
S = [0] + [int(x) - ord('0') for x in readline().rstrip()]
P = [int(x) for x in read().split()]

P += P

dp = [P]

for i in range(N+1):
    P = dp[i]
    newP = []
    dx = 1<<i
    for a,b in zip(P, P[dx:]):
        if a > b:
            a,b = b,a
        if S[b-a]:
            newP.append(b)
        else:
            newP.append(a)
    dp.append(newP)

answers = (x for x in P[:-1])
print('\n'.join(map(str, answers)))


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

#define __STDC_FORMAT_MACROS
#define p64 PRId64

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(f, x, ...)                                                         \
    ([&] (decltype ((x)) ALL) {                                                \
        return (f) (begin (ALL), end (ALL), ##__VA_ARGS__);                    \
    }) (x)

using namespace std;
using ll = int64_t;

int main() {
    int r;
    cin >> r;
    cout << 3 * pow (r, 2) << endl;
    return 0;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long int 
#define pb push_back
#define vv vector<ll>
#define MAX 105000
#define fr(i,x) for(int i=0;i<x;i++)
int dx[4] = {-1,0,0,1};
int dy[4] = {0,-1,1,0};

bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    
    if(a.first == b.first) return a.second<b.second;
    return (a.first < b.first); 
}
ll ar[MAX];
void divisor(){
    for (int i = 1; i <= MAX; i++)
    {
        for (int j = i; j <= MAX;j+=i)
        {
            ar[j]++;
            
        }
        
        
    }
    
}
int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    
    ll h,n,k,x,c = 0;
    cin >>n;
    for (int i = 0; i < n; i++)
    {
        cin >> x;
        if(x%2==0){
            if(x%3!= 0 && x%5!=0) c = 1;
        }
    }
    
    if(c)cout << "DENIED" <<endl;
    else cout << "APPROVED" << endl;
    
    
        
}

Measured memory_bytes: 3624
// created by mtnshh
 
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
 
#define ll long long
#define ld long double
 
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl
 
#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>
 
#define endl "\n"
 
const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e12;
#define PI 3.14159265
 
const ll N = 100005;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll k,n;
	cin>>k>>n;
	ll A[n];
	rep(i,0,n)	cin>>A[i];
	ll ans=0;
	rep(i,0,n-1)	ans = max(ans, A[i+1]-A[i]);
	ans = max(ans, k-A[n-1]+A[0]);
	cout<<k-ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
A = [int(_) for _ in input().split()]
BC = [[int(_) for _ in input().split()] for _ in range(M)]
A = sorted(A)
BC = sorted(BC, key=lambda x: -x[1])

index = 0
for i in BC:
    changenum = 0
    while changenum < i[0] and index < N:
        if i[1] > A[index]:
            changenum += 1
            A[index] = i[1]
        index += 1
    
    if index == N:
        break

print(sum(A))

Measured memory_bytes: 30952
#include<stdio.h>

int A[1000000], n;

int binarySearch(int key) {
	int left = 0;
	int right = n;
	int mid;
	while (left < right) {
		mid = (left + right) / 2;
		if (key == A[mid])return 1;
		if (key > A[mid])left = mid + 1;
		else if (key < A[mid])right = mid;
	}
	return 0;
}

int main() {
	int i, q, k, sum = 0;

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

	scanf("%d", &q);
	for (i = 0; i < q; i++) {
		scanf("%d", &k);
		if (binarySearch(k))sum++;
	}
	printf("%d\n", sum);

	return 0;
}

Measured memory_bytes: 988
n,m = map(int,input().split())
p = [list(map(str,input().split())) for i in range(m)]
answa = [0] * (n+1)
ans = [False] * (n+1)

#print(p)
for i in range(m):
    #print(p[i][1])
    #print(ans[int(p[i][0])])
    #print(sum(ans),sum(answa))
    #print(ans)
    if p[i][1] == "WA" and ans[int(p[i][0])] == False:
        answa[int(p[i][0])] += 1
    elif p[i][1] == "AC":
        ans[int(p[i][0])] = True

tmp = 0
#print(ans)
for i in range(1,n+1):
    if ans[i]:
        tmp += answa[i]

print(sum(ans),tmp)

Measured memory_bytes: 33684
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

int main()
{
	string s1, s2;
	cin >> s1 >> s2;
	string s = s1 + s2;

	int len = (int)s.size();

	double num = 0;

	REP(i, len){
		num *= 10;
		num += s[i] - '0';
	}

	REP(i, 1000){
		if (i == sqrt(num)){
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;

}


Measured memory_bytes: 256
from collections import deque

N, q = map(int, input().split())
A = []
for i in range(N):
    s, a = input().split()
    A.append((s, int(a)))

queue = deque(A)
t = 0
while queue:
    s, a = queue.popleft()
    if a-q > 0:
        t += q
        queue.append((s, a-q))
    else:
        t += a
        print(s, t)



Measured memory_bytes: 13956
module.exports=function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(r,i,function(e){return t[e]}.bind(null,i));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";var r=n(1),i=new(n(2))(r.readFileSync("/dev/stdin","utf8").trim().split(/\s+/g));n(4)(i)},function(t,e){t.exports=require("fs")},function(t,e,n){"use strict";var r=n(3);t.exports=class{constructor(t){this.inp=new r(t)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}fin(){this.inp.clear()}}},function(t,e,n){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=t.length,this.items=t,this.ind=0}enq(t){this.size+=1,this.items.push(t)}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}clear(){this.items=[],this.size=0,this.ind=0}}},function(t,e,n){"use strict";t.exports=function(t){var e=t.in(),n=e-1,r=0;e%2==1&&n--;for(var i=[],o=new Array(e).fill(-1),s=0;s<e;s++)for(var u=s+1;u<e;u++)s==r&&u==n||o[s]==u?(n--,r++,o[u]=s):i.push(`${s+1} ${u+1}`);console.log(i.length.toString()),console.log(i.join("\n"))}}]);

Measured memory_bytes: 7756
#include<bits/stdc++.h>
#define endl "\n"

typedef long long ll;
using namespace std;

//ll const N = 32000;

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

    int N;
    cin >> N;

    int arr[N];
    ll sum = 0;

    for(int i = 0; i < N; i++)
    {
        cin >> arr[i];

        if(i != 0)
        {
            if(arr[i - 1] > arr[i])
            {
                sum += arr[i - 1] - arr[i];

                arr[i] += arr[i - 1] - arr[i];
            }
        }
    }

    cout << sum;

    return 0;
}


Measured memory_bytes: 4368
#include<bits/stdc++.h>
#define inc(x,y) x=(x+y>=mod?x+y-mod:x+y)
int n, m, mod, dp[305][305][305];
int main(){
    scanf("%d %d %d", &n, &m, &mod);
    dp[0][1][0]=1;
    for (int i=0;i<=n;i++)
        for (int j=1;j<=m;j++)
            for (int k=i;k>=0;k--){
                if (k) inc(dp[i][j][k-1],dp[i][j][k]);
                else inc(dp[i][j+1][i],dp[i][j][k]);
                inc(dp[i+1][j][k],1ll*dp[i][j][k]*(k+1)%mod);
            } 
    printf("%d",dp[n][m][0]);
}

Measured memory_bytes: 110848
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int R = sc.nextInt();
        int S = sc.nextInt();
        int P = sc.nextInt();
        String T = sc.next();
        int[] array = new int[N];
        long result = 0;
        for(int i = 0; i < N; i++){
            char c = T.charAt(i);
            if(c == 'r'){
                if(K <= i && array[i - K] == 'r'){
                    array[i] = '0';
                }else{
                    array[i] = 'r';
                    result += P;
                }
            }
            if(c == 's'){
                if(K <= i && array[i - K] == 's'){
                    array[i] = '0';
                }else{
                    array[i] = 's';
                    result += R;
                }
            }
            if(c == 'p'){
                if(K <= i && array[i - K] == 'p'){
                    array[i] = '0';
                }else{
                    array[i] = 'p';
                    result += S;
                }
            }
        }
        System.out.println(result);
    }
}



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

#define gc( ) std::getchar( )
#define pc( i ) std::putchar( i )
#define RE cout << "Passing [" << __FUNCTION__ << "] on " << __LINE__ << '\n'
#define DEBUG(...) for( auto &i: __VA_ARGS__ ) cout << i << " "; cout << '\n'
#define space ' '
#define enter '\n'
using std::make_pair;

template < typename T >
inline T read( )
{
 T x = 0;
 char ch = gc( );
 bool f = 0;
 while( !std::isdigit( ch ) )
 {
  f = ( ch == '-' );
  ch = gc( );
 }
 while( std::isdigit( ch ) )
 {
  x = x * 10 + ( ch - '0' );
  ch = gc( );
 }
 return f ? -x : x;
}

template < typename T >
void print( T x )
{
 if( x < 0 )
 {
  x = -x;
  pc( '-' );
 }
 if( x < 10 )
 {
  pc( x + 48 );
  return;
 }
 print < T > ( x / 10 );
 pc( x % 10 + 48 );
 return ;
}

namespace Solution
{
#define IOS std::ios::sync_with_stdio( false ), std::cin.tie( 0 ), std::cout.tie( 0 )
#define Rep( i, j, k ) for( int i = j; i >= k; --i )
#define rdi( ) read < int > ( )
#define rdl( ) read < long long > ( )
#define pti( i ) print < int > ( i ), putchar( space )
#define ptl( i ) print < long long > ( i ), putchar( space )
#define For( i, j, k ) for( int i = j; i <= k; ++i )
 using std::cin;
 using std::cout;
 using std::endl;
 using std::vector;
 using std::map;
 using std::queue;
 using std::deque;
 using std::set;
 using std::pair;
 const int N = 204001, mod = 1e9 + 7;
 int n, ans;
 double d, x, y;
 void Fakemain( )
 {
  IOS;
  cin >> n >> d;
  d = d * d;
  For( i, 1, n )
   cin >> x >> y,
   ans += ( x * x + y * y <= d );
  cout << ans;
  return;
 }

} // namespace Solution

int main( int argc, char* argv[] )
{
 Solution::Fakemain( );
 return 0;
}

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

class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        List<int> a = new List<int>();
        List<int> b = new List<int>();
        List<int> c = new List<int>();
        a = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
        b = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
        c = Console.ReadLine().Split(' ').Select(int.Parse).ToList();

        a.Sort();
        c.Sort();

        long ans = 0;
        for (int i = 0; i < a.Count; i++)
        {
            long s = LowerBound(a, b[i]);
            long t = UpperBound(c, b[i]);
            ans += s * (n - t);
        }

        Console.WriteLine(ans);
    }

    static long LowerBound(List<int> list, int item)
    {
        int min = 0;
        int max = list.Count - 1;
        while (min <= max)
        {
            int mid = (min + max) / 2;
            if (item > list[mid]) min = mid + 1;
            else max = mid - 1;
        }
        return min;
    }

    static long UpperBound(List<int> list, int item)
    {
        int min = 0;
        int max = list.Count - 1;
        while (min <= max)
        {
            int mid = (min + max) / 2;
            if (item >= list[mid]) min = mid + 1;
            else max = mid - 1;
        }
        return min;
    }
}


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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n;
int b[125];
int a[125];

int main(){
    scanf("%d",&n);
    REP(i,n-1)scanf("%d",b+i);
    REP(i,n)a[i] = 1e9;
    REP(i,n-1){
        CHMIN(a[i], b[i]);
        CHMIN(a[i+1], b[i]);
    }
    ll ans = accumulate(a,a+n,0ll);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
N=int(input())
W=list(map(int,input().split()))
total=0
for i in range(N):
    total+=W[i]
ans=total
l=0
r=total
for i in range(N-1):
    l+=W[i]
    r-=W[i]
    if abs(r-l)<ans:
        ans=abs(r-l)
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

#define N	2000
#define M	2000

int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }

int main() {
	static char cc[N][M + 1];
	static int ll[N][M], rr[N][M];
	int n, m, i, j, ans;

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++)
		scanf("%s", cc[i]);
	for (i = 0; i < n; i++)
		for (j = 0; j < m; j++)
			cc[i][j] = cc[i][j] == '#';
	for (i = n - 1; i > 0; i--)
		for (j = m - 1; j > 0; j--)
			cc[i][j] ^= cc[i - 1][j] ^ cc[i][j - 1] ^ cc[i - 1][j - 1];
	for (i = 1; i < n; i++) {
		int k;

		k = 0;
		for (j = 1; j < m; j++)
			ll[i][j] = k = cc[i][j] == 0 ? k + 1 : 0;
		k = 0;
		for (j = m - 1; j > 0; j--)
			rr[i][j] = k = cc[i][j] == 0 ? k + 1 : 0;
	}
	ans = max(n, m);
	for (j = 1; j < m; j++) {
		int u = 0, l = m, r = m;

		for (i = 1; i < n; i++)
			if (cc[i][j] == 1)
				u = i, l = m, r = m;
			else {
				l = min(l, ll[i][j]), r = min(r, rr[i][j]);
				ans = max(ans, (i - u + 1) * (l + r));
			}
	}
	printf("%d\n", ans);
	return 0;
}


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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
}

long long dp[100];

long long lucas(int n) {
	if (n == 1) return 1;
	if (n == 0) return 2;
	if (dp[n]) return dp[n];
	return dp[n] = lucas(n-1)+lucas(n-2);
}

void solve() {
	int n; scanf("%d", &n);
	printf("%lld", lucas(n));
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
s=list(str(input()))
for i in range(len(s)-4):
    if s[i]=='a' and s[i+1]=='p' and s[i+2]=='p' and s[i+3]=='l' and s[i+4]=='e':
        s[i]='p'
        s[i+1]='e'
        s[i+2]='a'
        s[i+3]='c'
        s[i+4]='h'
    elif s[i]=='p' and s[i+1]=='e' and s[i+2]=='a' and s[i+3]=='c' and s[i+4]=='h':
        s[i]='a'
        s[i+1]='p'
        s[i+2]='p'
        s[i+3]='l'
        s[i+4]='e'
print(''.join(s))


Measured memory_bytes: 5564
from collections import Counter
n,x,y = map(int, input().split())
x -= 1
y -= 1
ans = [0]*n
dp = [[0]*n for _ in range(n)]
for i in range(n):
    for j in range(i,n):
         ans[min(abs(i-j),(abs(i-x)+abs(j-y)+1),(abs(i-y)+abs(j-x)+1))]+=1
for k in range(1,n):
    print(ans[k])

Measured memory_bytes: 35316
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n)cin >> s.at(i);
    vector<pair<int, string>> ans;
    sort(all(s));
    int cnt = 1;
    REP(i, n-1){
        if(s[i-1] == s[i])cnt++;
        else{
            ans.push_back({cnt * -1, s[i-1]});
            cnt = 1;
        }
    }
    ans.push_back({cnt * -1, s[n-1]});
    sort(all(ans));
    rep(i, ans.size()){
        if(ans[i].first == ans[0].first){
            cout << ans[i].second << endl;
        }
        else break;
    }
}

Measured memory_bytes: 18548
#include<iostream>
#include<stdlib.h>
#include<stack>
using namespace std;

int main(){
  stack<int> S;
  int a,b,x;
  string s;
  while(cin>>s){
    if(s[0]=='+'){
      a=S.top();S.pop();
      b=S.top();S.pop();
      S.push(a+b);
    }else if(s[0]=='-'){
      b=S.top();S.pop();
      a=S.top();S.pop();
      S.push(a-b);
    }else if(s[0]=='*'){
      a=S.top();S.pop();
      b=S.top();S.pop();
      S.push(a*b);
    }else{
      S.push(atoi(s.c_str()));
    }
  }
  cout<<S.top()<<endl;
  return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <string>

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

using namespace std;

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

  set<string> list;
  int n = s.length();
  int i, j;

  for(i=1; i<K+1; i++) { //抜き取る文字の個数
    for(j=0; j<n; j++) { //位置
      if(i+j>n) break;
      list.insert(s.substr(j, i));
    }
  }

  i=1;
  for(auto x : list) {
    if(i==K) {
      cout << "\n" << x << endl;
      break;
    }
    i++;
  }

  return 0;
}

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

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=Integer.parseInt(in.next());
		List<Integer> A=new ArrayList<>();
		for(int i=0;i<n;i++)A.add(Integer.parseInt(in.next()));
		int q=Integer.parseInt(in.next());
		
		Comparator<Integer> lower = (x, y) -> x.compareTo(y) >= 0 ? 1 : -1;
		for(int i=0;i<q;i++) {
			int key=Integer.parseInt(in.next());
			int p=~Collections.binarySearch(A, key, lower);
			if(p>=0)System.out.println(p);
			else System.out.println(n);
		}
	}
}


Measured memory_bytes: 117652
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#define r(i,n) for(int i=0; i<n; i++)
typedef long long ll;
using namespace std;

int main(void){
  int n;
  int a;
  cin >> n >> a;
  n%=500;
  if(n<=a){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


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

int main() {
	string s,t,u;
	int a,b;
	cin>>s>>t>>a>>b>>u;
	if(s==u){
		a--;
	}else{
		b--;
	}
	cout<<a<<' '<<b<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int N,A[100],i,j,cg,flag = 1,k,count=0;

  scanf("%d",&N);

  for(i = 0 ; i<N ; i++){
    scanf("%d",&A[i]);
  }
  while(flag == 1){
    flag = 0;
    for(j = N-1 ; j>0 ; j--){
      if(A[j] < A[j-1]){
	cg = A[j];
	A[j] = A[j-1];
	A[j-1] = cg;
	flag = 1;
	count++;
      }
    }
  }
  
  for(k=0;k<N;k++){
    printf("%d",A[k]);
      if(k == N-1) break;
      printf(" ");
  }
  printf("\n");

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



Measured memory_bytes: 2100
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Akash
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BFrog2 solver = new BFrog2();
        solver.solve(1, in, out);
        out.close();
    }

    static class BFrog2 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            int a[] = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = in.nextInt();

            int dp[] = new int[n + 5];
            dp[0] = 0;
            dp[1] = Math.abs(a[0] - a[1]);
            if (n > 2) {
                for (int i = 2; i < n; i++) {
                    dp[i] = Integer.MAX_VALUE;
                    for (int j = 1; j <= k && j <= i; j++) {
                        dp[i] = Math.min(dp[i - j] + Math.abs(a[i - j] - a[i]), dp[i]);
                    }
                }
            }

            out.println(dp[n - 1]);
        }

    }
}



Measured memory_bytes: 52068
#include <stdio.h>
#include <math.h>

int main(void)
{
  int w, a;
  double x = 0.0, y = 0.0;
  double age = 90.0;
  double r;

  while(1){
    scanf("%d,%d", &w, &a);
    if(w == 0 && a == 0) break;
    r = (age/180.0 * M_PI);
    x += cos(r) * w;
    y += sin(r) * w;
    age -= a;
  }
  printf("%d\n%d\n", (int)x, (int)y);

  return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
typedef long double lb;
typedef long double ld;
typedef pair<int,int> P;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0L)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1e9+7;
#define INF 1e9;
#define EPS 1e-9;

//----***入出力***---
#define print(out) cout<< out  << "\n";
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}initial_;

signed main(){
  int N,T;cin>>N>>T;
  vector<int> t_l(N);
  REP(i,0,N){
    cin>>t_l[i];
  }
  int pre=t_l[0]+T;
  int now;
  int ans=T;
  REP(i,1,N){
    now=t_l[i];
    ans+=T-max(0LL,pre-now);
    //debug(pre-now)
    pre=now+T;
  }
  print(ans)

}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
using namespace std;
int main(){
    long long a,b;
    cin >> a >> b;
    long long ans;
    if(a == 0){
        if(b<0){
            ans = 1 -b;
        }
        else{
            ans = b;
        }
    }
    else if (b == 0){
        if(a <= 0){
            ans = abs(a);
        }
        else{
            ans = 1 +a;
        }
    }
    else{
    if(a>=0 && b>=0){
        if(b>=a){
            ans = b-a;
        }
        else{
            ans = 2+abs(a-b);
        }
    }
    else if(a*b<0){
        ans = 1 + abs(a+b);
    }
    else{
        if(a>b){
            ans = 2 + a - b;
        }
        else if(a == b){
            ans = 0;
        }
        else{
            ans = b - a;
        }
    }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
ll exp(ll taban, ll us) {
    ll carpan = taban % mod;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % mod;
        temp /= 2;
        carpan = (carpan*carpan) % mod;
    }
    return res;
}
ll ebob(ll a, ll b){
	if(!a)return b;
	return ebob(b%a, a);
}
ll ekok(ll a, ll b){
	return (a*b)/ebob(a, b);
}
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int ar[3][3];
	for(int i = 0; i < 3; i++){
		for(int j = 0; j < 3; j++){
			cin>>ar[i][j];
		}
	}
	bool c[3][3] = {};	
	int n; cin>>n;
	for(int i = 0; i < n; i++){
		int sayi; cin>>sayi;
		for(int j = 0; j < 3; j++){
			for(int k = 0; k < 3; k++){
				if(ar[j][k] == sayi) c[j][k] = true;
			}
		}
	}
	bool ch = false;
	if(c[0][0] && c[0][1] && c[0][2]) ch = true;
	if(c[1][0] && c[1][1] && c[1][2]) ch = true;
	if(c[2][0] && c[2][1] && c[2][2]) ch = true;
	if(c[0][0] && c[1][0] && c[2][0]) ch = true;
	if(c[0][1] && c[1][1] && c[2][1]) ch = true;
	if(c[0][2] && c[1][2] && c[2][2]) ch = true;
	if(c[0][0] && c[2][2] && c[1][1]) ch = true;
	if(c[2][0] && c[1][1] && c[0][2]) ch = true;
	if(ch) cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int i,j,k,n,m,l,x,y,build[1001][2],assign[1001],assign2[1001],prev[1001][1001];
double route[11][1001][1001];

void backtrack(int from,int to){
	int z=prev[from][to];

	if(from==to)return;
	if(z==from){
		printf("%d ",assign[from]);
		return;
	}
	backtrack(from,z);
	backtrack(z,to);
	
}

int main(){
	while(scanf("%d",&n)*n){
		for(i=0;i<n;i++){
			scanf("%d %d %d",&assign[i],&build[i][0],&build[i][1]);
			assign2[assign[i]]=i;
		}
		for(i=0;i<n;i++){
			for(j=i;j<n;j++){
				l=(build[i][0]-build[j][0])*(build[i][0]-build[j][0])+(build[i][1]-build[j][1])*(build[i][1]-build[j][1]);
				if(l<=2500){
					route[0][i][j]=sqrt((double)l);
					route[0][j][i]=sqrt((double)l);
					prev[i][j]=i;
					prev[j][i]=j;
				}
				else{
					route[0][i][j]=999999999;
					route[0][j][i]=999999999;
				}
			}
		}

		for(l=1;pow(2.0,l-1)<n-1;l++){
			for(i=0;i<n;i++){
				for(j=0;j<n;j++){
					route[l][i][j]=route[l-1][i][j];
					for(k=0;k<n;k++){
						if(route[l][i][j]>route[l-1][i][k]+route[l-1][k][j]){
							route[l][i][j]=route[l-1][i][k]+route[l-1][k][j];
							prev[i][j]=k;
						}
					}
				}
			}
		}

		l--;

		for(scanf("%d",&m);m>0;m--){
			scanf("%d %d",&x,&y);
			x=assign2[x];
			y=assign2[y];
			if(x==y){
				printf("%d\n",assign[y]);
			}
			else if(route[l][x][y]<999999999){
				backtrack(x,y);
				printf("%d\n",assign[y]);
			}
			else printf("NA\n");
		}

	}
	return 0;
}

Measured memory_bytes: 25620
n=gets.chomp.to_i
w=gets.chomp.split(" ").map{|s| s.to_i}
t=[]
for i in 0..n-2
  s1=w[0..i].inject(:+)
  s2=w[i+1..n-1].inject(:+)
  t[i]=(s1-s2).abs
end
puts t.min

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

typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

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

const ll INF = 1e18;
const ll MOD = 998244353;
const ll MX = 200005;

ll N, K, C;
char days[MX];
int pos[MX];

void solve() {
    cin >> N >> K >> C;
    for (int i = 0; i < N; i++) cin >> days[i];
    for (int i = 0; i < N; i++) {
        pos[i] = (days[i] == 'o');
        
        if (i > C) pos[i] += pos[i - C - 1];
        if (i) chmax(pos[i], pos[i - 1]);
    }
    
    if (pos[N - 1] > K) return;
    
    // Go backwards and find the first one you couldn't do without
    // If it's the last one and the one before != N
    // Store the number the thing enables, if no other o has that then it's needed
    // Set, if 
    
    // for (int i = 0; i < N; i++) cout << pos[i] << "\n";
    set<int> found;
    vector<int> ans;
    for (int i = N - 1; i >= 0; i--) {
        if (days[i] == 'o' && !found.count(pos[i])) {
            if (i == 0) {
                ans.push_back(i + 1);
            } else if (pos[i] > pos[i - 1]) {
                ans.push_back(i + 1);
            }
            found.insert(pos[i]);
            i -= C;
        }
    }
    
    reverse(ans.begin(), ans.end());
    for (auto& i : ans) cout << i << "\n";
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    ll T = 1; // cin >> T;
    while (T--) solve();
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


Measured memory_bytes: 12660
def call(n):
    s = ""
    for i in range(1,n+1):
        if i%3 == 0:
            s += " {0}".format(i)
        else:
            x = i
            while x > 0:
               if x%10 == 3:
                   s += " {0}".format(i)
                   break
               x = x // 10
    print(s)

m = int(input())
call(m)

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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int ret;
  ret = 0;
  for(int i = a; i <= b; i++){
    if(c % i == 0) 
    ret++;
  }
  cout << ret << endl;
}


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

using namespace std;

typedef long long ll;

int main() {
  int k, s;
  cin >> k >> s;
  int count =  0;
  for (int x = 0; x <= k; x++) {
    for (int y =  0; y <= k;  y++) {
      int z = s-x-y;
      if  (z >= 0 && k >= z) count++;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(){
  int W, H, x, y, r;
  std::cin >> W >> H >> x >> y >> r;

  if( (0<=(x-r) && (x+r)<=W) && (0<=(y-r) && (y+r)<=H) ){
      std::cout << "Yes" << std::endl;
  }else std::cout << "No" << std::endl;
  return 0;
}



Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll n,cnt=0;
  cin>>n;
  vector<ll> a(n);
  for(ll i=0;i<n;i++) {
    cin>>a[i];
    while(a[i]%2==0){
   	  cnt++;
      a[i]/=2;
    }
  }
  cout<<cnt;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int m,f,b;
  cin >> m >> f >> b;
  if(m<b&&b<=m+f)
    cout << b-m << endl;;
  if(m+f<b)
    cout << "NA" << endl;
  if(m>=b)
    cout << 0 << endl;
  return 0;
}

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

int selectionSort(int A[],int N){
    int minj,b;
    int c = 0;
    for(int i = 0 ; i < N-1 ; i++){
        minj = i;
        for(int j = i ; j < N ; j++){
            if(A[j] < A[minj]){
                minj = j;
            }
        }
        b = A[i];
        A[i] = A[minj];
        A[minj] = b;

        if(i != minj){
            c += 1;
        }       
    }
    return c;
}

int main(){
    int A[100];
    int N , c;

    cin >> N;
    for(int i = 0 ; i < N ; i++){
        cin >> A[i];
    }

    c = selectionSort(A , N);

    for(int i = 0 ; i < N ; i++){
        if(i > 0 ){
            cout << " ";
        }
        cout << A[i];
    }
    cout << endl;
    cout << c << endl;
    
    return 0;
}


Measured memory_bytes: 3112