akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;



int main(void) {
	
	while (1) {
		int n;
		int now;
		int pos = 1;
		string s;

		cin >> n;
		vector<int> k(n + 1);
		if (n == 0) {
			break;
		}
		FOR(i, 1, n) {
			cin >> k[i];
		}
		cin >> s;

		FOR(i, 0, s.size() - 1) {
			now = k[pos];
			if ('a' <= s[i] && s[i] <= 'z') {
				if (s[i] - now >= 'a') {
					s[i] -= now;
				}
				else {
					now = 'a' - (s[i] - now);
					if (now <= 26) {
						s[i] = 'Z' - now + 1;
					}
					else {
						now -= 26;
						s[i] = 'z' - now + 1;
					}
				}
			}
			else {
				if (s[i] - now >= 'A') {
					s[i] -= now;
				}
				else {
					now = 'A' - (s[i] - now);
					if (now <= 26) {
						s[i] = 'z' - now + 1;
					}
					else {
						now -= 26;
						s[i] = 'Z' - now + 1;
					}
				}
			}
			cout << s[i];
			pos++;
			if (pos == n + 1) {
				pos = 1;
			}
		}
		cout << endl;
	}
}


Measured memory_bytes: 3204
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
	int n,a,b,s1,s2;
	while(cin>>n>>a>>b){
	s1=n*a;s2=b;
	if(s1<s2)cout<<s1<<endl;
	else cout<<s2<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 0
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;

int n,k,ans;
int a[111111];
signed main(){
	
	cin>>n>>k;
	rep(i,k)cin>>a[i];
	int sum=0;
	rep(i,k){
		sum+=a[i];
	}
	if(sum<=n)cout<<n-sum<<endl;
	else cout<<-1<<endl;
	
}


Measured memory_bytes: 3664
import java.util.*;

public class Main{

    public static void main(String[] args){
	int Walk,x,y,w,h;
	Scanner in = new Scanner(System.in);
	final int[] dx = {0,1,0,-1}; 
	final int[] dy = {1,0,-1,0};
	int dir;
       
	while(true){
	    w = in.nextInt();
	    h = in.nextInt();	       

	    if(w+h == 0)break;
	    dir = 0;
	    x=y=1;
	    while(true){
		String op = in.next();
		if(op.equals("STOP"))break;

		if(op.equals("RIGHT")){
		    ++dir;
		    if(dir == 4)dir = 0;
		}
		else if(op.equals("LEFT")){
		    --dir;
		    if(dir == -1)dir = 3;
		}
		else if(op.equals("FORWARD")){
		    Walk = in.nextInt();
		    x = x + Walk*dx[dir];
		    if(x > w)x = w;
		    if(x <= 0)x=1;
		    y = y + Walk*dy[dir];
		    if(y > h)y = h;
		    if(y <= 0)y=1;
		}
		else if(op.equals("BACKWARD")){
		    Walk = in.nextInt();
		    x = x - Walk*dx[dir];
		    if(x > w)x = w;
		    else if(x < 0)x = 1;
		    y = y - Walk*dy[dir];
		    if(y > h)y = h;
		    else if(y <= 0)y = 1;
		}
	    }
	    System.out.println(x + " " + y);
	}

    }



}

Measured memory_bytes: 12000
#include <iostream>

using namespace std;

int main(void) {
    int A,B,C,X,Y;
    cin>>A>>B>>C>>X>>Y;
    int MIN = 1<<30;
    int min_xy = max(X, Y) * 2;
    for (int c=0; c<=min_xy; c+=2) {
        int a = max(X - c/2, 0);
        int b = max(Y - c/2, 0);
        int price = A*a + B*b + C*c;
        MIN = min(price, MIN);
    }
    cout<<MIN<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
  int s,a,b,c;
  cin >> s;
  a = s/100;
  b = s%100/10;
  c = s%100%10;
  if(a+b+c == 0){
    cout << 0 << endl;
  }else if(a+b+c == 1) {
    cout << 1 << endl;
  }else if(a+b+c == 2) {
    cout << 2 << endl;
  }else if(a+b+c == 3) {
    cout << 3 << endl;
  }else{
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <map>
#define int long long

using namespace std;

typedef long double ld;
typedef pair<int, int> pa;
typedef long long ll;

const int mod = 1e9 + 7, N = 1e5;
const ld pi = 3.1415926535;

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

    cout.precision(6);
    cout << fixed;

    int n;
    cin >> n;
    vector<pa> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a.rbegin(), a.rend());
    int ans = 0;
    vector<vector<int>> dp(n + 1, vector<int>(n + 1, 0));
    for (int i = 0; i < n; ++i) {
        int len = n - i - 1;
        for (int l = 0, r = len; r < n; ++l, ++r) {
            if (i < n - 1) {
                dp[l + 1][r] = max(dp[l + 1][r], dp[l][r] + a[i].first * abs(a[i].second - l));
                dp[l][r - 1] = max(dp[l][r - 1], dp[l][r] + a[i].first * abs(a[i].second - r));

            }if (i == n - 1) {
                ans = max(ans, dp[l][r] + a[i].first * abs(a[i].second - l));
                ans = max(ans, dp[l][r] + a[i].first * abs(a[i].second - r));
            }
        }
    }
    cout << ans;

}

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

int main(void)
{
	char s[7];

	scanf("%s", &s);
	
	if (s[2] == s[3] && s[4] == s[5]) {
		cout << "Yes\n";
	}
	else
		cout << "No\n";

	return 0;
}

Measured memory_bytes: 504
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    input! {
    a:usize,
    b:usize,
    c:isize,
    d:[isize;b],
    e:[[isize;b];a]
    }
    let mut ans:usize=0;
    let mut sum:isize=0;
    for i in 0..a {
        for j in 0..b {
            sum+=d[j]*e[i][j];
        }
        if sum+c>0 {ans+=1;}
        sum=0;
    }
    println!("{}",ans)
}

Measured memory_bytes: 2164
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a[3];
    for (int i = 0; i < 3; ++i)
        cin >> a[i];
    sort(a,a+3);
    if (a[0] == a[1] && a[1] != a[2])
        cout << "Yes\n";
    else if (a[0] != a[1] && a[1] == a[2])
        cout << "Yes\n"; 
    else
        cout << "No\n";
}


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

using ll = long long;
using ull = unsigned long long;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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; }
int ctoi(char c){return c-'0';}




int dp[(int)1e5];
bool flag[(int)(1e5)];
vector<vector<int>> xy;
int f(int x){
  if(flag[x])return dp[x];
  flag[x] = true;
  int fans = 0;
  for(int y : xy[x])chmax(fans,f(y)+1);
  return dp[x]=fans;
}

// TODO: write
int main() {
  int n,m;cin>>n>>m;
  xy = vector<vector<int>>(n);
  rep(i,m){
    int x,y;cin>>x>>y;
    x--;y--;
    xy[x].pb(y);
  }
  rep(i,1e5)flag[i] = false;
  int ans = 0;
  rep(i,n)ans = max(ans,f(i));
  print(ans);
  return 0;
}

Measured memory_bytes: 11080
import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.typecons;  // Tuple, Nullable, BigFlags
import std.regex;     // RegEx

void main()
{
  auto s = readln.chomp, n = s.length;

  auto calc(size_t k)
  {
    if (k < n/2) return true;

    auto m1 = s[n-k..k].matchFirst(r"^(0*)(1*)$");
    if (m1 && m1[2].length + n-k >= k) return true;

    auto m2 = s[n-k..k].matchFirst(r"^(1*)(0*)$");
    if (m2 && m2[2].length + n-k >= k) return true;

    auto m3 = s[$-k..$-(n-k)].matchFirst(r"^(0*)(1*)$");
    if (m3 && m3[1].length + n-k >= k) return true;

    auto m4 = s[$-k..$-(n-k)].matchFirst(r"^(1*)(0*)$");
    if (m4 && m4[1].length + n-k >= k) return true;

    return false;
  }

  auto bsearch = iota(1, n+1).map!(k => tuple(k, calc(k))).assumeSorted!"a[1]>b[1]";
  writeln(bsearch.lowerBound(tuple(0, false)).back[0]);
}


Measured memory_bytes: 508
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
#define int long double
using namespace std;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
signed main()
{
	int a,b;
	cin>>a>>b;
	int c=a*b;
	long long d=c;
	cout<<d;
	re 0;
}

Measured memory_bytes: 3736
#include <iostream>


int main() {
	int a, b, c;
	std::cin >> a >> b >> c;
	int max = a;
	if (max < b) {
		max = b;
	}
	if (max < c) {
		max = c;
	}
	std::cout << a + b + c - max << "\n";
}


Measured memory_bytes: 256
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<vector<vector<int>>> v3int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef vector<vector<vector<ll>>> v3ll;
typedef list<int> liint;
typedef pair<int, int> pint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, int>> vpll_int;
typedef vector<pair<int, ll>> vpint_ll;
typedef set<pair<int, int>> spint;
typedef set<pair<ll, int>> spll;
typedef unordered_map<int, unordered_set<int>> Graph;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

ll mod(ll val, ll m) {
    ll res = val % m;
    if (res < 0) res += m;
    return res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    ll p = 1000000007;
    ll sub = 1;
    ll all = 1;
    rep(i, N) {
        all *= 10;
        all %= p;
    }
    rep(i, N) {
        sub *= 9;
        sub %= p;
    }
    sub *= 2;
    sub %= p;
    ll add = 1;
    rep(i, N) {
        add *= 8;
        add %= p;
    }

    ll ans = mod(all - sub, p) + add;
    ans %= p;
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
//ヘッダー
#include<bits/stdc++.h>
using namespace std;
 
//型定義
typedef long long ll;
 
//定数
const int INF=1e+9;
const int MOD=1e+9+7;
 
//REPマクロ
#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 REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)
 
//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値
 
//グローバル変数
 
 
//ライブラリ挿入
// UnionFind
struct UnionFind {
    vector< int > data;
    
    UnionFind(int sz) {
        data.assign(sz, -1);
    }
 
    bool unite(int x, int y) {//要素xとyの各々の木を併合（もともと同じ木ならfalse）
        x = find(x), y = find(y);
        if(x == y) return (false);
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return (true);
    }
    
    int find(int k) {//要素kが属する木の根を得る
        if(data[k] < 0) return (k);
        return (data[k] = find(data[k]));
    }
    
    int size(int k) {//要素kが属する木の要素数
        return (-data[find(k)]);
    }
 
    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = find(x);
        int ry = find(y);
        return rx == ry;
    }
 
};
 
int main(){
    int N,M,K;
    cin>>N>>M>>K;
    UnionFind friends_candi(N);
    int a,b;
    vector<vector<int>> No(N);
    REP(i,M){
        cin>>a>>b;
        a--;
        b--;
        No[a].push_back(b);
        No[b].push_back(a);
        friends_candi.unite(a,b);
    }
 
    REP(i,K){
        cin>>a>>b;
        a--;
        b--;
        No[a].push_back(b);
        No[b].push_back(a);
    }
    int ans;
    REP(i,N){
        ans=friends_candi.size(i)-1;
        REP(j,No[i].size()){
            if(friends_candi.same(i,No[i][j])){
                ans--;
            }
        }
        cout<<ans;
        if(i!=N-1) cout << " ";
        else cout<<endl;
    }
 
 
}

Measured memory_bytes: 7936
#include <cstdio>

int main()
{
	char n[3];
	scanf("%s", n);

	for (int i = 0; i < 3; ++i)
	{
		if (n[i] == '1')
		{
			n[i] = '9';
		}
		else if (n[i] == '9')
		{
			n[i] = '1';
		}
	}

	printf("%s", n);
}

Measured memory_bytes: 128
//  Created by liszt on 2019/08/01.
#include<bits/stdc++.h>
using namespace std;

int main(){
    int a,b,c; cin>>a >>b >>c;
    if(a+b==c||b+c==a||c+a==b){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

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

    ll n,m;cin>>n>>m;
    string s,t;cin>>s>>t;
    ll g=gcd(n,m),l=(n/g)*m;
    bool f=true;
    if(s[0]!=t[0]) f=false;
    ll snum=0,tnum=0;
    while(snum<n && tnum<m){
        if(s[snum]!=t[tnum]) f=false;
        snum += n/g;
        tnum += m/g;
    }
    if(f){
        cout<<l<<endl;
    }
    else{
        cout<<-1<<endl;
    }
}


Measured memory_bytes: 640
N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(M)]

V = {}
v = [0,0]
for v[0],v[1] in AB:
  for i in range(2):
    if v[i] in V:
      V[v[i]] += 1
    else:
      V[v[i]] = 1
for val in V.values():
  if val % 2 == 1:
    print('NO')
    exit()
print('YES')

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

class Program{

  static string ans = "";

  static int Main() {

    string nyu =  Console.ReadLine();
    char[] nya = nyu.ToCharArray();

    if (nyu.Length==2) {
      ans = nyu;
    } else {
      char a = nya[0];
      nya[0] = nya[2];
      nya[2] = a;
      ans = new String(nya);
    }

    Console.WriteLine("{0}", ans);

    return 0;
  }

}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int n; cin >> n;
  int a[n],b[n];
  REP(i,n) {
    cin >> a[i];
    b[i]=a[i]-(i+1);
  }

  sort(b,b+n);
  int med = n%2 ? b[n/2] : (b[n/2] + b[n/2-1]) / 2;
  ll ans=0;
  REP(i,n) ans += abs(a[i] - (med+i+1));
  COUT(ans);

  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>

using namespace std;

int main(int argc, const char * argv[]) {
    // insert code here...
 
    
    int num;
    
    cin >> num;
    
    int a[num];
    
    for(int i=0; i<num; i++)
        cin >> a[i];

//    sort(a[0], a[num-1]);
    sort(a, a+num);
    
    cout << a[num-1]-a[0] << endl;
    
    return 0;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)(x).size())
#define mset(a,v) memset(a,v,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))
using namespace std;
typedef long long ll;

int tn;ll a,b,c,d;

int main(){
	scanf("%d",&tn);
	while(tn--){
		scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
		//printf("%lld%lld%lld%lld",a,b,c,d);
		if(b>d){puts("No");continue;}
		//if(a<b){puts("No");continue;}
		//if(a<b){puts("No");continue;}
		//a-=b;
		//if(a>c)a-=(a-c+b-1)/b*b;
		//assert(a<=c);
		//if(a<0){puts("No");continue;}
		//if(b==d){puts("Yes");continue;}
		bool r=true;
		fore(_,0,500000){
			if(a<b){r=false;break;}
			a-=b;
			if(a>c)a-=(a-c+b-1)/b*b;
			assert(a<=c);
			if(a<0){r=false;break;}
			if(b==d)break;
			a+=(c-a)/(d-b)*(d-b);
			a+=d;
			//printf(" %lld\n",a);
		}
		if(r)r=b<=c+__gcd(b,d);
		puts(r?"Yes":"No");
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+7;
const ll maxlg=65;
const int maxn=55;
ll num[maxlg][maxn][maxn],last[maxn][maxn],res[maxn][maxn];
void fl()
{
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
int main()
{
//    fl();
	int n;
	ll len;
	scanf("%d%lld",&n,&len);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			scanf("%lld",&num[0][i][j]);
	for(int lg=1;lg<=60;lg++)
		for(int k=1;k<=n;k++)
			for(int i=1;i<=n;i++)
				for(int j=1;j<=n;j++)
					num[lg][i][j]=(num[lg][i][j]+num[lg-1][i][k]*num[lg-1][k][j])%mod;
	bool flag=false;
	for(int lg=0;lg<=60;lg++,len/=2)
		if(len%2)
		{
			if(flag==false)
			{
				for(int i=1;i<=n;i++)
					for(int j=1;j<=n;j++)
						last[i][j]=num[lg][i][j];
				flag=true;
			}
			else 
			{
				memset(res,0,sizeof(res));
				for(int k=1;k<=n;k++)
					for(int i=1;i<=n;i++)
						for(int j=1;j<=n;j++)
							res[i][j]=(res[i][j]+last[i][k]*num[lg][k][j])%mod;
				for(int i=1;i<=n;i++)
					for(int j=1;j<=n;j++)
						last[i][j]=res[i][j];
			}
		}
	ll ans=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			ans=(ans+last[i][j])%mod;
	printf("%lld\n",ans);
	return 0;
}


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

// コンテスト中のみ
//#define int long long

#define ll long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define P pair<ll,ll>
int MOD = 1000000007;
const ll INF = 1LL << 60;

int q;
string s, t;
int dp[1010][1010];
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> q;
	rep(_, q) {
		cin >> s >> t;
		int n = s.size(), m = t.size();
		rep(i, n) {
			rep(j, m) {
				if (s[i] == t[j]) {
					dp[i + 1][j + 1] = dp[i][j] + 1;
				}
				else {
					dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
				}
			}
		}
		cout << dp[n][m] << endl;
	}
	return 0;
}


Measured memory_bytes: 7192
import java.util.*;

public class Main {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            HashSet<Integer> set = new HashSet<>();
            for(int i = 0; i < n; i++) {
                int num = sc.nextInt();
                if(set.contains(num)) {
                    set.remove(num);
                } else {
                    set.add(num);
                }
            }
            System.out.println(set.size());
        }
}


Measured memory_bytes: 61332
n=int(input())

a=0
b=0
c=0
d=0

for i in range(n):
    s=input()
    if s=="AC":
        a+=1
    elif s=="WA":
        b+=1
    elif s=="TLE":
        c+=1
    else:
        d+=1

print("AC x "+ str(a))
print("WA x "+str(b))
print("TLE x "+str(c))
print("RE x "+str(d))

Measured memory_bytes: 9204
from heapq import*
import sys
r=sys.stdin.readline
def g(n,E,S,G):
 F=[1e7]*-~n;F[S]=0;H=[(0,S)]
 while H:
  c,u=heappop(H)
  if u==G:return c
  for f,v in E[u]:
   if c+f<F[v]:F[v]=c+f;heappush(H,(c+f,v))
 return-1
def s(n,k):
 E=[[]for _ in[0]*-~n]
 for _ in[0]*k:
  f=r()
  if'0'==f[0]:print(g(n,E,*map(int,f[2:].split())))
  else:c,d,e=map(int,f[2:].split());E[c]+=[(e,d)];E[d]+=[(e,c)]
for e in iter(r,'0 0\n'):s(*map(int,e.split()))


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

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    
    int left, right, tight_left = 0, tight_right = N;
    for(int i = 1; i <= M; i++)
    {
        cin >> left >> right;

        if (right < tight_left || left > tight_right)
        {
            cout << 0;
            return 0;
        }

        if (left > tight_left)
        {
            tight_left = left;
        } 
        if (right < tight_right)
        {
            tight_right = right;
        }
    }

    cout << tight_right - tight_left + 1;
}


Measured memory_bytes: 256
until(n,m=gets.split.map(&:to_i))==[0,0]do
r,p,a=[],[],[]
n.times{r.unshift(gets.gsub("?",".").split)}
m.times{p<<gets.split}
p.each{|p|r.each{|r|if/#{r[1]}/=~p[0]&&p[1]=~/#{r[2]}/
a<<p*" "if/p/=~r[0]
break
end}}
puts a.size,a
end

Measured memory_bytes: 9384
#include <iostream>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int a,b,c;
    cin >> a >> b >> c;
    if (a+b+c > 21)
	cout << "bust" << endl;
    else
	cout << "win" << endl;


}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_h(const vector<T>& c, int n=INT_MAX)
{ rep(i, min(n, (int)c.size())) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define D1(a) cout<<#a<<":"<<a<<"\n"
#define D2(a,b) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<endl 
#define D3(a,b,c) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c <<endl
#define D4(a,b,c,d) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c<<","<<#d<<":"<<d<<endl 
#define MOD 1000000007

typedef vector<vpii> graph;

void dfs(graph& g, vi& c, int v=0, int w=0)
{
    if (c[v] != -1) return;
    c[v] = w % 2;

    for (int i = 0; i < g[v].size(); i++) {
        dfs(g, c, g[v][i].first, w + g[v][i].second%2);
    }
}

int main()
{
    int N; cin >>N;
    graph g(N);
    rep(i, N-1) {
        int u, v, w; cin >> u >> v >> w; u--; v--;
        g[u].push_back(make_pair(v, w));
        g[v].push_back(make_pair(u, w));
    }
    // rep(i, N) {
    //     cout << i << ": ";
    //     rep(j, g[i].size()) {
    //         cout << "(" << g[i][j].first << "," << g[i][j].second << ")";
    //     }
    //     cout << endl;
    // }
    vi col(N, -1);

    dfs(g, col);

    rep(i, N) { cout << col[i] << endl; }
}


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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

ll dp[10010][2][110];
const ll MOD = 1e9+7;

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

  string s;
  cin >> s;
  int D;
  cin >> D;

  rep(i, s.size()+1){
    rep(j, 2){
      rep(k, D){
        dp[i][j][k] = 0;
      }
    }
  }

  dp[0][0][0] = 1;

  rep(i, s.size()){
    int nd = s[i] - '0';
    rep(j, 2){
      rep(k, D){
        rep(d, 10){

          int nj, nk;
          nj = j, nk = k;
          if(nj == 0 && d > nd) continue;
          if(nj == 0 && d < nd) nj = 1;

          nk = (k + d) % D;

          dp[i+1][nj][nk] = (dp[i+1][nj][nk] + dp[i][j][k]) % MOD;

        }
      }
    }
  }

  cout << (dp[s.size()][0][0] + dp[s.size()][1][0] + MOD - 1LL) % MOD << endl;





  return 0;
}


Measured memory_bytes: 17408
#include <bits/stdc++.h>
using namespace std;
int n,i,j,a[210000],num;
long long ans;
bool cmp(int x,int y)
{
	return x>y;
}
int main()
{
	scanf("%d",&n);
	for (i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1,cmp);
	ans=a[1];
	num=n-2;
	for (i=2;i<=n;i++)
	{
		ans+=a[i]*min(2,num);
		num-=2;
		if (num<=0) break;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 4568
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define lf long double
#define F first
#define S second
typedef vector <ll> vi;
typedef pair <ll,ll> ii;
typedef vector <pair <ll,ll> >vii;
typedef vector <vector <ll> > vv;
typedef vector <string> vs;

bool possible(ll in,string &a)
{
    ll n=a.size();
    if(in+2<n)
    {
        if(a[in]=='A' && a[in+1]=='B' && a[in+2]=='C')
        {
            return true;
        }
    }
    return false;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin>>s;
    string a;
    for(ll i=0;i<s.size();i++)
    {
        if(s[i]=='A')
        {
            a.pb(s[i]);
        }
        else if(s[i]=='B' && i+1<(ll)s.size() && s[i+1]=='C')
        {
            a.pb('D');
            i++;
        }
        else
            a.pb(s[i]);
    }
    ll in=0;
    ll n=a.size();
    ll ans=0;
    while(in<a.size())
    {
        ll low=in;
        ll numd=0;
        while(low<n && (a[low]=='A' || a[low]=='D'))
        {
            if(a[low]=='D')
                numd++;
            low++;
        }
        if(low==in)
        {
            in++;
        }
        else
        {
            //in low-1 
            for(ll i=in;i<=low-1;i++)
            {
                if(a[i]=='A')
                {
                    ans+=numd;
                }
                else
                    numd--;
            }
            in=low;
        }
    }
    cout<<ans<<endl;
} 


Measured memory_bytes: 916
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	long long n,power=1;
	cin >> n;
	for (long long i = 1; i <= n; i++) {
		power = (power*i) % 1000000007;
	}
	cout << power<< endl;
	int x;
	cin >> x;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mod 1000000007
typedef long long ll;

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

    int n;
    cin >> n;
    string s = to_string(n);
    for(int i=0;i<s.length();i++){
        if(s[i]=='1')
            cout << '9';
        else if(s[i]=='9')
            cout << '1';
        else
            cout << s[i];
    }
}

Measured memory_bytes: 256
n, m = map(int, input().split())

ab = []
for i in range(m):
    a,b = map(int, input().split())
    ab.append((a,b))
    
def dfs(x):
    global flag
    flag[x] = True
    for k in range(n):
        if bridge[x][k] == True:
            bridge[x][k] = False
            dfs(k)
            
           
ans = 0
for i in range(m):
    bridge = [[False for i in range(n)] for i in range(n)]
    for j in ab[0:i] + ab[i+1:m]:
        bridge[j[0] - 1][j[1] - 1] = True
        bridge[j[1] - 1][j[0] - 1] = True   
    flag = [False for j in range(n)]
    dfs(0)
    if flag.count(False) > 0:
        ans += 1
        
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define DB(x) cerr << __LINE__ << ": " << #x << " = " << (x) << "\n"
using namespace std;
using ll = long long;

signed main() {
    IO;
    ll ans = 0;
    ll h, w, k;
    cin >> h >> w >> k;
    string s[h];
    for(int i = 0; i < h; ++i) cin >> s[i];
    for(ll r = 0; r < (1ll << h); ++r) {
        for(ll c = 0; c < (1ll << w); ++c) {
            int cnt = 0;
            for(ll i = 0; i < h; ++i) {
                for(ll j = 0; j < w; ++j) {
                    if((r & (1ll << i)) == 0 && (c & (1ll << j)) == 0) {
                        if(s[i][j] == '#') ++cnt;
                    }
                }
            }
            if(cnt == k) ++ans;
        }         
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define L long long

using namespace std;

L n,ans;

vector<L>v[100010],l[100010];

L chk[100010],sz[100010],up[100010],bu[100010];

void dfs(L x){
	sz[x]=1;
	L i;
	for(i=0;i<v[x].size();i++)
	{
		if(!chk[v[x][i]])
		{
			chk[v[x][i]]=1;
			up[v[x][i]]=l[x][i];
			bu[v[x][i]]=x;
			dfs(v[x][i]);
			sz[x]+=sz[v[x][i]];
		}
	}
}

int main()
{
	scanf("%lld",&n);
	L i;
	for(i=1;i<n;i++)
	{
		L s,e,d;
		scanf("%lld %lld %lld",&s,&e,&d);
		v[s].push_back(e);
		v[e].push_back(s);
		l[s].push_back(d);
		l[e].push_back(d);
	}
	chk[1]=1;
	dfs(1);
	L temp=1;
	while(1)
	{
		L ma=0,mad;
		//puts("1");
		for(i=0;i<v[temp].size();i++)
		{
			//printf("%lld %lld %lld %lld %lld %lld\n",temp,i,v[temp][i],bu[v[temp][i]],sz[v[temp][i]],ma);
			if(bu[temp]!=v[temp][i]&&sz[v[temp][i]]>ma)
			{
				//puts("123");
				ma=sz[v[temp][i]];
				mad=v[temp][i];
			}
		}
		temp=mad;
		//puts("123");
		if(sz[temp]<=n/2) break;
	}
	//puts("123");
	for(i=1;i<=n;i++)
	{
		ans+=up[i]*2*min(sz[i],n-sz[i]);	
	}
	if(n%2==0&&sz[temp]==n/2)
	{
		ans-=up[temp];
	}
	else
	{
		temp=bu[temp];
		L mi=up[temp];
		for(i=0;i<v[temp].size();i++)
		{
			if(l[temp][i]<mi)
			{
				mi=l[temp][i];
			}
		}
		ans-=mi;
	}
	printf("%lld",ans);
}

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

int main(void){
  int h,w;
  char s[111][111],t[111][111];
  scanf("%d %d",&h,&w);
  for(int i=0;i<h;i++)scanf("%s",s[i]);
  for(int i=0;i<111;i++){
    for(int j=0;j<111;j++)t[i][j]='#';
  }
  
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++)t[i][j]=s[i-1][j-1];
  }
  for(int i=0;i<=h+1;i++){
    for(int j=0;j<=w+1;j++){printf("%c",t[i][j]);}
    puts("");
  }
  return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong();
		long m = scan.nextLong();
		long ans = 0;
		if(m>=2*n){
			ans = n;
			ans = (m-2*n)/4+ans;
		}
		else{ans = m/2;}
		System.out.println(ans);
	}
}

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

int main() {
  int s;
  cin >> s;
  int s1 = s / 100;
  int s2 = (s - s1*100) / 10;
  int s3 = (s - s1*100 - s2*10) / 1;
  
  cout << s1 + s2 + s3 << endl;
}

Measured memory_bytes: 3528
#include "bits/stdc++.h"
using namespace std;
int main(){
    long long int n,m,i,ans=0,num=0;
    cin >> n >> m;
    vector<pair<long long int,long long int> > P(n);
    for(i=0;i<n;i++){
        cin >> P.at(i).first >> P.at(i).second;
    }
    sort(P.begin(),P.end());
    for(i=0;i<n;i++){
        if(num+P.at(i).second<=m){
            ans += P.at(i).first*P.at(i).second;
            num += P.at(i).second;
        }
        else if(num>=m) break;
        else{
            ans += P.at(i).first*(m-num);
            num += m-num;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdio>
using namespace std;
int n, k, x;
int main() {
     cin >> n >> k >> x ;
     if (n + k >= x){
     cout << "Yes" << endl;}
     else
    {cout << "No" << endl;}
     return 0;
}

Measured memory_bytes: 256
#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;

int main() {
    int N, K;
    cin >> N >> K;
    int ans = 0;
    while (N) {
        N /= K;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int a[1000100];
bool vis[1000100];
long long res;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i])
			vis[i]=true;
		res+=a[i]/2;
		a[i]%=2;
	}
	for(int i=1;i<=n;i++){
		if(a[i]&&a[i+1]){
			a[i]=a[i+1]=0;
			res++;
		}
		if(a[i-1]&&vis[i]){
			a[i]=1;
			a[i-1]=0;
		}
		if(a[i]&&a[i+1]){
			a[i]=a[i+1]=0;
			res++;
		}
	}
	cout<<res<<endl;
	return 0;
}


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

using namespace std;


#define MAXN 200001

template <class T>
struct sparse_table {
  const vector<T> &x;
  vector<vector<int>> table;
  int height;

  int lg2(int k) {  // returns largest p for which 2^p <= k
    return sizeof(int)*8 - 1 - __builtin_clz(k);
  }

  int argmin(int i, int j) {
    return x[i] < x[j] ? i : j;
  }

  sparse_table(const vector<T> &x) : x(x) {
    height = lg2(x.size());
    table.assign(height+1, vector<int>(x.size()));
    iota(table[0].begin(), table[0].end(), 0);
    for (int h = 0; h < height; ++h) {
      for (int i = 0; i+(1<<h) < x.size(); ++i) {
        table[h+1][i] = argmin(table[h][i], table[h][i+(1<<h)]);
      }
    }
  }

  T rmq(int i, int j) {
    int h = lg2(j-i);
    return x[argmin(table[h][i], table[h][j - (1<<h)])];
  }
};



int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, ind[MAXN];
  cin >> n;
  vector<int> a[2];
  a[0].assign(n, MAXN+10);
  a[1].assign(n, MAXN+10);
  for (int i = 0; i < n; ++i) {
    cin >> a[i%2][i];
    ind[a[i%2][i]] = i;
  }
  sparse_table<int> st[2] = {a[0], a[1]};
  priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<pair<int, pair<int, int>>> > pq;
  pq.push({st[0].rmq(0, n), {0, n}});
  int ans[MAXN];
  for (int i = 0; i < n/2; ++i) {
    auto el = pq.top();
    pq.pop();
    int x = el.second.first;
    int y = el.second.second;
    ans[2*i] = st[x%2].rmq(x, y);
    int I = ind[ans[2*i]];
    ans[2*i+1] = st[!(x%2)].rmq(I+1, y);
    int J = ind[ans[2*i+1]];
    if (x<I) pq.push({st[x%2].rmq(x, I), {x, I}});
    if (I+1<J) pq.push({st[!(x%2)].rmq(I+1, J), {I+1, J}});
    if (J+1<y) pq.push({st[x%2].rmq(J+1, y), {J+1, y}});
  }
  for (int i = 0; i < n; ++i) {
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 34032
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<complex>
 
#define INF (long long)1000000000
#define MOD 1000000007
#define EPS 1e-8
 
#define REP(i, m) for(long long i = 0; i < m; ++i)
#define FOR(i, n, m) for(long long i = n; i < m; ++i)
#define ALL(v) v.begin(), v.end()
#define pb push_back
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
 
int main() {
	int n;
	cin>>n;
	string s = to_string(n);
	if(s[0]==s[2]) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

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

int main() {

  while(1) {

    int H, W;
    cin >> H >> W;

    if (H == 0 && W == 0) {
      return 0;
    }

    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (i == 0 || i == H - 1 || j == 0 || j == W - 1) {
          cout << "#";
        } else {
          cout << ".";
        }
      }
      cout << endl;
    }
    cout << endl;

  }

  return 0;

}


Measured memory_bytes: 3000
<?php

list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
for($i = 100; $i > 0; $i--){
    if($a % $i == 0 && $b % $i == 0){
        $c--;
        if($c == 0){
            echo $i;
            exit;
        }
    }
}

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

int main()
{
  int n;
  string s, m;
  cin >> n;
  for(int i = 0; i < n; i++)
  {
    cin >> m >> s;
    for(int j = m.length() - 1; j >= 0; j--)
    {
      switch(m[j])
      {
        case 'C':
          s = s.substr(1, s.length() - 1) + s[0];
          break;
        case 'J':
          s = s[s.length() - 1] + s.substr(0, s.length() - 1);
          break;
        case 'E':
          {
            int a = s.length() / 2, b = s.length() % 2;
            s = s.substr(a + b, a) + s.substr(a, b) + s.substr(0, a);
          }
          break;
        case 'A':
          reverse(s.begin(), s.end());
          break;
        case 'M':
          for(int k = 0; k < s.length(); k++)
            if(s[k] >= '0' && s[k] <= '9')
              s[k] = (s[k] - '0' + 1) % 10 + '0';
          break;
        case 'P':
          for(int k = 0; k < s.length(); k++)
            if(s[k] >= '0' && s[k] <= '9')
              s[k] = (s[k] - '0' + 9) % 10 + '0';
          break;
      }
    }
    cout << s << endl;
  }
}

Measured memory_bytes: 1212
/* One original thought is worth a thousand mindless quotings */

#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<unordered_map>
#include<algorithm>
#include<bitset>
#include<queue>
#include <math.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout.precision(10);cout << fixed;
#define dbset(x) for(int i=0 ; i<x.size(); i++) cerr << x[i] << " "; cerr << endl;
#define inf 1000000007
#define INF 1000000000000000000LL
#define PI 3.14159265358979323846
#define mod 1000000007
#define mod1 1000696969
#define flusz fflush(stdout);
#define VI vector<int>
#define VPI vector < pair<int,int> >
#define PII pair<int, int>
#define PIII pair<pair<int,int>,int>
#define BIT bitset<N>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define M (L+R)/2
#define endl '\n'
#define REP(x, y) for(int x = 0; x < (y); ++x)
#define FOR(x, y, z) for(int x = y; x <= (z); ++x)
#define FORR(x, y, z) for(int x = y; x >= (z); --x)
using namespace std;

template<class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<","; _dbg(sdbg+1, a...);
}
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)

#define int long long
const int N = 1000*1000 + 7;

int test;

int n,k;

int res;

void solve()
{
	cin >> n >> k;

	FOR(i,1,n){
		int x = i % k;

		int y = (k-x)%k;

		if ((y*2)%k != 0)
			continue;

		if (i % k == 0){
			int ile = n / k;

			res += ile * ile;
		}else{
			int ile = n / k + (n%k >= y);

			res += ile * ile;
		}
	}

	cout << res;

    return;
}

int32_t main()
{
    boost

    test=1;

	for(int i=1; i <= test; i++){
        solve();
	}

    return 0;
}


Measured memory_bytes: 256
use std::cmp::{max, min};
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let (n, a, b) = input_three::<i64>().unwrap();

    let ans = n / (a + b) * a + min(n % (a + b), a);
    println!("{}", ans);
}

fn input<T: FromStr>() -> Result<T, T::Err> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    Ok(buf.trim().parse().ok().unwrap())
}

fn input_vec<T: FromStr>() -> Result<Vec<T>, T::Err> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    Ok(buf
        .trim()
        .split_whitespace()
        .map(|x| x.parse().ok().unwrap())
        .collect::<Vec<_>>())
}

fn input_two<T: FromStr>() -> Result<(T, T), T::Err> {
    let tmp = input_vec::<String>().unwrap();
    Ok((tmp[0].parse()?, tmp[1].parse()?))
}

fn input_three<T: FromStr + Clone>() -> Result<(T, T, T), T::Err> {
    let tmp = input_vec::<T>().ok().unwrap();
    // println!("{:?}", tmp);
    Ok((tmp[0].clone(), tmp[1].clone(), tmp[2].clone()))
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	ll n, k; cin >> n >> k;
	ll ans = 0;
	for( ll b = 1; b <= n; ++b ) ans += max(0ll, (n/b)*(b-k)) + max(0ll, n%b-k+1);
	if( k == 0 ) ans -= n;
	cout << ans << endl;
	return 0;
}

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

int main(){

  int r,i,j,x,tr,p=0;
  int *A;
  scanf("%d",&r);

  A = (int *)malloc(sizeof(int)*r);
  
  for(i = 0 ; i < r ; i++)
    scanf("%d",&A[i]);


  
  x = A[r-1];
  i = p-1;

  for(j = p ; j <= r-2 ; j++){
    if(A[j] <= x){
      i++;
      tr = A[i];
      A[i] = A[j];
      A[j] = tr;
    }
  }

  tr = A[i+1];
  A[i+1] = A[r-1];
  A[r-1] = tr;

  tr = i+1;
  
  for(i = 0 ; i < r ; i++){
    if(i == tr) printf("[");
    printf("%d",A[i]);
    if(i == tr) printf("]");
    if(i < r-1) printf(" ");
    
  }

  printf("\n");

  return 0;

}
  

Measured memory_bytes: 996
#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>;
template<typename T> void chmax(T &a, T b) { a = max(a, b); }
template<typename T> void chmin(T &a, T b) { a = min(a, b); }

// Sieve of Eratosthenes
// https://youtu.be/UTVg7wzMWQc?t=2774
struct Sieve {
    int n;
    vector<int> f, primes;
    Sieve(int n=1):n(n), f(n+1) {
        f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
  vector<pair<ll,int>> factor(ll x) {
    vector<pair<ll,int>> res;
    for (int p : primes) {
      int y = 0;
      while (x%p == 0) x /= p, ++y;
      if (y != 0) res.emplace_back(p,y);
    }
    if (x != 1) res.emplace_back(x,1);
    return res;
  }
};

const int MAX_N = 100005;

int main() {
    int q;
    cin >> q;
    Sieve s(MAX_N);
    vector<int> likes;

    for (int p : s.primes) {
        int q = (p+1) / 2;
        if (s.isPrime(q)) likes.push_back(p);
    }

    rep(i, q) {
        int l, r;
        cin >> l >> r;
        int ans = 0;

        for (int like : likes) if (l <= like && like <= r) ans++;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3904
mod utils {
    use std::error::Error;
    use std::io::stdin;
    use std::str::FromStr;

    #[allow(dead_code)]
    pub fn read_line<T>() -> Result<Vec<T>, Box<Error>>
    where
        T: FromStr,
        T::Err: 'static + Error,
    {
        let mut line = String::new();
        let _ = stdin().read_line(&mut line)?;
        let parsed_line = line.split_whitespace()
            .map(|x| x.parse::<T>())
            .collect::<Result<Vec<T>, T::Err>>()?;

        Ok(parsed_line)
    }

    #[allow(dead_code)]
    pub fn read_lines<T>(n: usize) -> Result<Vec<Vec<T>>, Box<Error>>
    where
        T: FromStr,
        T::Err: 'static + Error,
    {
        (0..n).map(|_| read_line()).collect()
    }
}

fn solve() -> Result<(), Box<std::error::Error>> {
    let header = utils::read_line::<usize>()?;
    let n_items = header[0];
    let maximum = header[1];
    let items = utils::read_lines::<usize>(n_items)?;

    let mut dp = vec![vec![0; maximum + 1]; n_items];

    if items[0][1] <= maximum {
        dp[0][items[0][1]] = items[0][0];
    }

    for i in 1..n_items {
        let v_i = items[i][0];
        let w_i = items[i][1];

        dp[i] = dp[i - 1].to_vec();

        if w_i <= maximum {
            dp[i][w_i] = std::cmp::max(dp[i - 1][w_i], v_i);
        }
        for j in 1..(maximum + 1) {
            if j + w_i <= maximum && dp[i - 1][j] != 0 {
                dp[i][j + w_i] = std::cmp::max(dp[i - 1][j + w_i], dp[i - 1][j] + v_i);
            }
        }
    }

    // println!("{:?}", dp);
    println!("{}", dp[n_items - 1].iter().max().unwrap());

    Ok(())
}

fn main() {
    match solve() {
        Err(err) => panic!("{}", err),
        _ => (),
    };
}



Measured memory_bytes: 13132
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, M = list(map(int, readline().split()))
pS = [readline().decode('utf-8').split() for _ in range(M)]
WA_cnt = [0] * (N + 1)
ACed_list = [False] * (N + 1)
pena = 0

for p_, s in pS:
    p_ = int(p_)

    if ACed_list[p_]:
        continue
    if s == "WA":
        WA_cnt[p_] += 1
    else:
        ACed_list[p_] = True
        pena += WA_cnt[p_]

print(sum(ACed_list), pena)


Measured memory_bytes: 42708
#include<stdio.h>

int main()
{
  int input[5],mod[5];
  int min_index = 0,sum = 0;
  for ( int i = 0; i < 5; i++ ) {
    scanf("%d",&input[i]);
    mod[i] = input[i] % 10;
    if ( mod[i] == 0 ) continue;
    if ( mod[min_index] >  mod[i] ) {
      min_index = i;
    }
  }

  for ( int i = 0; i < 5; i++ ) {
    if ( mod[i] == 0 || i == min_index) {
      sum += input[i];
    } else {
      sum +=  input[i] / 10 * 10 + 10;
    }
  }
  printf("%d\n",sum);

  return 0;
}

Measured memory_bytes: 128