akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plii pair<ll,pii>
#define vi vector<int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    fio;
   ll N; cin>>N;
  vector<int> f(N+1,0);
  for(int x=1;x<=100;x++)
  {
    for(int y=1;y<=100;y++)
    {
      for(int z=1;z<=100;z++)
      {
        int n=x*x+y*y+z*z+x*y+y*z+z*x;
        if(n<=N) f.at(n)++;
      }
    }
  }
  loop(i,0,N)
  {
    cout<<f.at(i+1)<<endl;
  }
    return 0;
}



Measured memory_bytes: 3604
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll n,p;
string s;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>n>>p;
    cin>>s;
    if(p==2){
        ll ans = 0;
        rep(i,n){
            ll num = s[i] - '0';
            if(num%2==0){
                ans += i+1;
            }
        }
        print(ans);
    }else if(p==5){
        ll ans = 0;
        rep(i,n){
            ll num = s[i] - '0';
            if(num%5==0){
                ans += i+1;
            }
        }
        print(ans);
    }else{
        Vi sum(n+1,0);
        ll ten = 1;
        map<ll,Vi> ma;
        ma[0].push_back(n); 
        for(ll i =n-1;i>=0;i--){
            sum[i] = (sum[i+1]+(s[i]-'0')*ten)%p;
            ma[sum[i]].pb(i);
            ten *= 10;
            ten %= p;
        }
        rep(i,p){
            reverse(all(ma[i]));
        }
        ll ans = 0;
        rep(i,n){
            //if()
            ll id = ma[sum[i]].end()- upper_bound(all(ma[sum[i]]),i);
            
            ans += id;
        }
        print(ans);
    }
    return 0;
}

Measured memory_bytes: 5780
#include<bits/stdc++.h>
#define ll long long
#define rep(i,l,r) for(int (i)=(l);(i)<(r);i++)
#define erep(i,l,r) for(int (i)=(l);(i)<=(r);i++)
#define MOD 1000000007
using namespace std;
struct data{
    long long s,c;
};
bool cmp(const data& m,const data& n){return m.s<n.s;}
int main(){
    int n,m;
    cin>>n>>m;
    vector<int> dig(n,-1);
    int ok=1,ans=0;
    rep(i,0,m){
        int s,c;
        cin>>s>>c;
        s--;
        if(dig[s]!=-1){
            if(dig[s]!=c){
                ok=0;
                break;
            }
            else{
                dig[s]=c;
                ok=1;
            }
        }
        else {
            dig[s]=c;
            ok=1;
        }
    }
    if(dig[0]==-1){
        if(n>1)dig[0]=1;
        else dig[0]=0;
    }
    if(dig[1]==-1)dig[1]=0;
    if(dig[2]==-1)dig[2]=0;
    
    if(n==3){
        ans=dig[0]*100+dig[1]*10+dig[2];
    }
    else if(n==2)ans=dig[0]*10+dig[1];
    else ans=dig[0];

    int buf=1;
    if(n>1&&dig[n-2])buf=2;
    if(n>2&&dig[n-3])buf=3;
    if(ok&&buf==n) cout<<ans<<endl;
    else cout<<-1<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (long long int i = (a); i < (b); i++)

using namespace std;
using ll = long long int;
using ld = long double;

auto p = [](auto s){
    cout << s << endl;
};

int main() {
    ll X;
    cin >> X;
    ll k = X / 500;
    X -= 500 * k;
    ll m = X / 5;
    p(k * 1000 + m * 5);
    return 0;
}

Measured memory_bytes: 256
X, K, D = map(int, input().split())

if int(abs(X) / D) < K:
    if int(K - int(abs(X) / D)) % 2 == 0:
            print(abs(X) % D)
    else:
        print(abs(abs(X) % D - D))
else:
    print(abs(X) - D * K)

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

using namespace std;

#define FaSt ios::sync_with_stdio(0),cin.tie(0);
#define random uniform_int_distribution<long long>(1, 2000000000000000LL)(rng)
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count() * ((uint64_t) new char | 1));

const int N = 100005;
int n, a[N];

int main() 
{
    FaSt
    int n, k;
    cin >> n >> k;
    cout << max(0, n - k + 1);
}

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

int main(){
  int N,M,AC,WA;
  cin>>N>>M;
  AC=0;
  WA=0;
  set<int> acnum;
  map<int,int> wanum;
  
  
  for(int i=0;i<M;i++){
    int p;
    string s;
    cin>>p>>s;
    if(acnum.count(p)){
    }
    else if(s=="AC"){
      AC++;
      acnum.insert(p);
      if(wanum.count(p)){
        WA+=wanum.at(p);
      }  
    }
    else if(s=="WA"){
      if(wanum.count(p)){
        wanum.at(p)+=1;
      }
      else{
        wanum[p]=1;
      }
    }
  }
  cout<<AC<<" "<<WA<<endl;
}


Measured memory_bytes: 4992
import java.util.*

fun main(args: Array<String>) {
    val (H, W) = readIntList()
    val map = Array(H) { readString() }
    val sumW =map.map { it.count{ it == '.'} }.sum()

    val dist = BFS(0 to 0, H-1 to W - 1, map)
    println(if (dist == null) -1 else sumW - dist - 1)
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
fun powInt(a: Int, b: Int) = Math.pow(a.toDouble(), b.toDouble()).toInt()


val DIR_4 = listOf(
    -1 to 0,
    1 to 0,
    0 to -1,
    0 to 1
)

fun Array<String>.mapSearch(ch: Char): Pair<Int, Int> {
    for ((h, line) in this.withIndex())
        for ((w, c) in line.withIndex())
            if (ch == c) return h to w
    return -1 to -1
}


fun BFS(
    s: Pair<Int, Int>,
    g: Pair<Int, Int>,
    map: Array<String>,
    wall:Char = '#',
    dir:List<Pair<Int, Int>> = DIR_4
):Int? {
    val set = mutableSetOf<Pair<Int, Int>>()
    val que = ArrayDeque<Pair<Int, Int>>()
    que.add(s)
    var res = 0

    while (que.isNotEmpty()) {
        val tmpQue = ArrayDeque<Pair<Int, Int>>()
        while (que.isNotEmpty()) {
            val hw = que.pop()
            val (h, w) = hw
            if (h !in map.indices || w !in map[0].indices) continue
            if (map[h][w] == wall) continue
            if (hw in set) continue
            if (hw == g) return res

            set.add(hw)
            tmpQue.addAll(dir.map { it.first + h to it.second + w })
        }
        que.addAll(tmpQue)
        res++
    }

    return null
}


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


N = int(input())
l = prime_factorize(N)
m = set(l)
l2 = list(m)
ans = 0

for i in range(len(l2)):
    x = l.count(l2[i])
    y = 1
    while x >= y:
        x = x - y
        y += 1
        ans += 1
print(ans)

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

int check(char *s, int l, int r);

int main()
{
  char s[99];
  
  scanf("%s", s);
  int n = strlen(s);
  if(check(s, 0, n - 1) == -1 || check(s, 0, (n - 1) / 2 - 1) == -1 || check(s, (n + 3) / 2 - 1, n - 1) == -1){
    printf("No\n");
  }else{
    printf("Yes\n");
  }
  
  return 0;
}

int check(char *s, int l, int r)//-1:回文でない
{
  int i, j;
  int n = 0;
  for(i = l, j = r; n < (r - l + 1) / 2; i++, j--, n++){
    if(s[i] != s[j]){
      return -1;
    }
  }
  return 1;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
	int r,c,i,j,k,tr,tc,tt;
	
	scanf("%d %d",&r,&c);
	
	int sheet[r+1][c+1];
	tt = 0;
	for(i=0;i<r;i++)
	{
		tr=0;
		for(j=0;j<c;j++)
		{
			scanf("%d",&sheet[i][j]);
			tr+=sheet[i][j];
			
			if(i== r-1)
			{
				tc = 0;
				for(k=0;k<r;k++)
					tc += sheet[k][j];
				
				sheet[k][j]=tc;
			}
		}
		sheet[i][j] = tr;
		tt += tr;
		
	}
	sheet[i][j]=tt;
	
	for(i=0;i<r+1;i++)
	{
		for(j=0;j<c+1;j++)
		{
			if(j!=c)
				printf("%d ",sheet[i][j]);
			else
				printf("%d",sheet[i][j]);
		}
		printf("\n");
	}
	
	
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

string s;
int n,k;

int main(){
  cin>>s>>k;
  n=s.size();
  vector<string> ss;
  rep(i,n){
    ss.push_back(s.substr(i,n-i));
  }
  sort(all(ss));
  set<string> st;
  rep(i,ss.size()){
    rep(j,ss[i].size()){
      st.insert(ss[i].substr(0,j+1));
      if(st.size()>=k)break;
    }
    if(st.size()>=k)break;
  }
  cout<<*st.rbegin()<<endl;
  return 0;
}


Measured memory_bytes: 16128
#include <bits/stdc++.h>
using namespace std;
#define rep(it,st,en) for(int it=(st);it<(int)(en);++it)
#define allof(c) (c).begin(), (c).end()
#define mt make_tuple
#define mp make_pair
#define pb push_back
#define X first
#define Y second
typedef long long int ll; 
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
const int INF=(int)1e9; 
const double EPS=(ld)1e-7;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k,x;
    int mx = 0;
    cin>>n>>k;
    int g = 0;
    rep(i,0,n){
        cin>>x;
        mx = max(x,mx);
        g = __gcd(x,g);
    }
    if(k%g == 0 && k <= mx) cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
X = sum(A)
ans = float("inf")
x = 0
for i in range(N):
    x += A[i]
    if i < N-1:
        ans = min(ans, abs(X - 2 * x))
print(ans)

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

int main() {
  int N;
  cin >> N;

  cout << setprecision(10) << (double)(N - N / 2) / (double)N << endl;
  return 0;
}

Measured memory_bytes: 3756
#include <stdio.h>

int main(void)
{

    int n,k;
    char dif;
    
    scanf("%d",&n);
    char array[n];
    scanf("%s",array);
    scanf("%d",&k);

    dif=array[k-1];

    for(int i=0;i<n;i++){
        if(array[i]!=dif){
            array[i]='*';
        }
    }

    for(int i=0;i<n;i++){
        printf("%c",array[i]);
    }

    return 0;
}

Measured memory_bytes: 128
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())

N = I()
K = I()
X = I()
Y = I()

ans = 0
for i in range(N):
    if i >= K:
        ans += Y
    else:
        ans += X

print(ans)


Measured memory_bytes: 5768
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <typename Arg1>
	void __f(const char* name, Arg1&& arg1)
	{
		cerr << name << " = " << arg1 << endl;
	}
	template <typename Arg1, typename... Args>
	void __f(const char* names, Arg1&& arg1, Args&&... args)
	{
		const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " = " << arg1 << " || ";
		__f(comma+1, args...);
	}
#else
#define debug(...)
#endif

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ; ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
	return os << "[ " << p.first << ", " << p.second << "]" ;
}

#define FAST_IO std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double
#define sz(a) (ll)(a).size()
#define endl "\n"

// priority_queue<ll, vector<ll>, less<ll>>pq;     // Max Heap
// priority_queue<ll, vector<ll>, greater<ll>>pq;  // Min Heap

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//K-th smallest
//cout << k << "kth (1 based indexing) smallest: " << *A.find_by_order(k - 1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;

int main()
{
	FAST_IO;

	ll n, ans = 0;
	cin >> n;
	ll a[n];
	for(int i=0;i<n;i++) cin >> a[i]; 	   
    for(int i=0;i<n;i++)
    	for(int j=i+1;j<n;j++)
    		for(int k=j+1;k<n;k++)
    		{
    			if(a[i] == a[j] ||  a[j] == a[k] || a[i] == a[k]) continue;
    			vector<ll>v;
    			v.pb(a[i]);
    			v.pb(a[j]);
    			v.pb(a[k]);
    			sort(v.begin(), v.end());
    			if(v[0] + v[1] > v[2]) ans +=1;
    		}
   	cout << ans << endl;
    return 0;
}

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

using namespace std;

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

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

template<typename A, size_t N, typename T>
void array_fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

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

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

    int n, minus_cnt = 0;
    ll abs_sum = 0;
    cin >> n;
    vector<ll> nums(n);
    rep(i, n){
        ll num;
        cin >> num;
        nums[i] = abs(num);
        minus_cnt += (num < 0);
        abs_sum += abs(num);
    }

    if(minus_cnt % 2 == 0) cout << abs_sum << endl;
    else{
        cout << abs_sum - *min_element(all(nums)) * 2 << endl;
    }
}

Measured memory_bytes: 1024
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define free  freopen ("input.txt", "r", stdin);freopen ("output.txt", "w", stdout);
#define Fast  ios::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second

bool vowel(char che)
{
    if (che == 'A' || che == 'E' || che == 'I' || che == 'O' || che == 'U' || che == 'Y')
        return true;
    else
        return false;
}

const int N = 1e5+5;
const int mod = 1e9+7;
ll a[N], b[N], c[N], d, dp, dis;
//pair <int, int> p[N];
char o;
bool mark[N], h;
string s, s1;
//stack <int> st;
//set <ll> st1, st2;
//deque <int> dq;
//vector <int> vt[N];
//int a1[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};



int main()
{
    Fast
    int t, n, m, k = 0, f = 0, sum = 0, ans = 0;
    cin >> s;
    for (int i = 0; i < s.size(); i++){
        ans += s[i]-'0';
    }
    if (ans % 9 == 0)
        cout << "Yes\n";
    else
        cout << "No\n";
}


Measured memory_bytes: 3688
#include <iostream>
#include <vector>
#include <chrono>
#include <random>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int n, q;
	std::cin >> n >> q;
	std::string str;
	std::cin >> str;
	std::vector<char> c(q), d(q);
	for(int i = 0; i < q; i++) {
		std::cin >> c[i] >> d[i];
	}
	auto simulate = [&](int pos) {
		//std::cout << "starting at " << pos << '\n';
		for(int i = 0; i < q && pos >= 0 && pos < n; i++) {
			if(str[pos] == c[i]) {
				pos += (d[i] == 'L' ? -1 : 1);
				//std::cout << "went to " << pos << '\n';
			}
		}
		//std::cout << "returning " << pos << '\n';
		return pos;
	};
	int l = 0, r = n;
	while(l != r) {
		int mid = (l + r + 1) / 2;
		if(simulate(mid - 1) == -1) {
			l = mid;
		} else {
			r = mid - 1;
		}
	}
	int left = l - 1;
	l = 0, r = n;
	while(l != r) {
		int mid = (l + r) / 2;
		if(simulate(mid) == n) {
			r = mid;
		} else {
			l = mid + 1;
		}
	}
	//std::cout << "got " << left << ", " << l << "\n";
	std::cout << std::max(0, l - left - 1) << '\n';
}

Measured memory_bytes: 976
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+5;
priority_queue<ll,vector<ll>,greater<ll> >q;
ll ans[N],cnt;
void init()
{
	for(int i=1;i<=9;i++)q.push(i);
	while(cnt<=1e5)
	{
		ans[++cnt]=q.top();
		ll qwq=q.top();q.pop();
		ll P=qwq*10+qwq%10;
		q.push(P);
		if(qwq%10!=0)q.push(P-1);
		if(qwq%10!=9)q.push(P+1);
	}
}
int main()
{
	init();
	int n;
	cin>>n;
	cout<<ans[n]<<"\n";
	return 0;
}

Measured memory_bytes: 2932
N, Y = [int(_) for _ in input().split()]
Y=int(Y/1000)
 
if Y<N or Y > 10* N:
    print("-1 -1 -1")
else:
    Y-=N
    a, b=0, 0
    while Y%9 != 0:
        b+=1
        Y-=4
    a=Y//9
    c=N-(a+b)
    if a>=0 and b>=0 and c>=0:
        print("{} {} {}".format(a,b,c))
    else:
        print("-1 -1 -1")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
int main()
{
    ll n;
    cin>>n;
    ll sum=0;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
        {
            for(ll k=1;k<=n;k++)
            {
                ll gcd1 = __gcd(i,j);
                ll gcd2 = __gcd(k,gcd1);
                sum+=gcd2;
            }
        }
    }
    cout<<sum;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define N 1000000007
#define ll long long
#define ull unsigned long long
#define mem(a) memset(a,0,sizeof(a))

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int x;
    cin >> x;
    int a = x/500;
    x -= a*500;
    int b = x/5;
    cout << a*1000+b*5 << endl;
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<pair<double,string>> data(n);
  
  double all=0.0;
  for(int i=0; i<n; i++) {
    cin >> data[i].first >> data[i].second;
    
    if(data[i].second=="JPY") all+=data[i].first;
    else all+=data[i].first*380000.0;
  }
  
  cout << all <<endl;
}

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

namespace ABC
{
    class ProgramC
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();
            var result = n;

            // 累積和
            var se = new int[n + 1];
            var sw = new int[n + 1];
            for (var i = 1; i < n + 1; i++)
            {
                se[i] = s[i - 1] == 'E' ? se[i - 1] + 1 : se[i - 1];
                sw[i] = s[i - 1] == 'W' ? sw[i - 1] + 1 : sw[i - 1];
            }

            for (var i = 0; i < (n + 1) - 1; i++)
            {
                var r1 = sw[i];
                var r2 = se[n] - se[i + 1];
                result = Math.Min(r1 + r2, result);
            }
            Console.WriteLine(result);
        }
    }
}

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

char S[100010], T[100010];
int q;
int a, b, c, d;
int SL, TL;
int SA[100010], SB[100010];
int TA[100010], TB[100010];

void pre()
{
	int i;
	SL = strlen(S);
	TL = strlen(T);
	if(S[0] == 'A')
		SA[0] = 1;
	else
		SB[0] = 1;
	for(i=1; i<SL; i++){
		SA[i] = SA[i-1];
		SB[i] = SB[i-1];
		if(S[i] == 'A')
			SA[i] ++;
		else
			SB[i] ++;
	}
	if(T[0] == 'A')
		TA[0] = 1;
	else
		TB[0] = 1;
	for(i=1; i<TL; i++){
		TA[i] = TA[i-1];
		TB[i] = TB[i-1];
		if(T[i] == 'A')
			TA[i] ++;
		else
			TB[i] ++;
	}
}

void solve()
{
	int sA, sB, tA, tB;
	sA = SA[b];
	sB = SB[b];
	if(a>0){
		sA -= SA[a-1];
		sB -= SB[a-1];
	}
	tA = TA[d];
	tB = TB[d];
	if(c>0){
		tA -= TA[c-1];
		tB -= TB[c-1];
	}
	int sv = sA+sB*2;
	int tv = tA+tB*2;
	if( abs(sv-tv) % 3 == 0)
		printf("YES\n");
	else
		printf("NO\n");
}

int main()
{
	int i;
	scanf("%s", &S);
	scanf("%s", &T);
	scanf("%d", &q);
	pre();
	for(i=0; i<q; i++){
		scanf("%d %d %d %d", &a, &b, &c, &d);
		a--, b--, c--, d--;
		solve();
	}
	return 0;
}

Measured memory_bytes: 2304
N, M = map(int, input().split())
id_cards = set(i for i in range(N))

l_lim = 1
r_lim = N
for j in range(M):
    li, ri = map(int, input().split())
    if l_lim < li:
        l_lim = li
    if r_lim > ri:
        r_lim = ri
if r_lim >= l_lim:
    print(r_lim-l_lim + 1)
else:
    print(0)

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

using namespace std;

template<class T>
T gcd(T a, T b) {
	while (b != 0) {
		a %= b;
		swap(a, b);
	}
	return a;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int x;
	cin >> x;
	cout << 360 / gcd(x, 360) << '\n';
	return 0;
}

Measured memory_bytes: 3636
#include <cstdio>

int main()
{
  int n;
  long long L;
  scanf("%d%lld",&n,&L);
  static long long a[100000];
  for(int i=0;i<n;i++){
    scanf("%lld",a+i);
  }
  int I=-1;
  for(int i=0;i<n-1;i++){
    if(a[i]+a[i+1]>=L){
      I=i;
      break;
    }
  }
  if(I==-1){
    puts("Impossible");
  }
  else{
    puts("Possible");
    for(int i=0;i<I;i++){
      printf("%d\n",i+1);
    }
    for(int i=n-2;i>=I;i--){
      printf("%d\n",i+1);
    }
  }
  return 0;
}


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

using namespace std;

const int INF = 1e9;
const int N = 1e4;
const int MOD = 1e9 + 7;
const double EPS = 1e-6;

const double PI = acos(-1);


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    long long n, a, b;
    cin >> n >> a >> b;
    long long c = a + b;
    long long ans = n / c * a;
    ans += min(n % c, a);
    cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <queue>
#include <algorithm> // sort


#define DEBUG 0

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll mod = 1000000007;
static const ll INF = 1000000000000000000LL;
                    //999999997000000003
                    //1000000000000000000

using namespace std;

int main(){
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    string S;
    cin >> S;
    ll K;
    cin >> K;

    REP(i,S.size())
    {
        if(S[i] == 'a')continue;
        //bが25になるa-> 0 z -> 1
        int sa = 'a' - S[i] + 26;
        if(K >= sa)
        {
            K -= sa;
            S[i] = 'a';
        }
    }

    //操作はちょうどK回行わないといけないため、帳尻をあわせる
    K %= 26;

    S[S.size() - 1] += K;
    if(S[S.size() -1] > 'z')
    {
        S[S.size()] -= 26;
    }

    cout << S << endl;  

    return 0;
}


Measured memory_bytes: 512
#include <set>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

typedef long long ll;

int read() {
	char ch;
	for(ch=getchar();ch<'0'||ch>'9';ch=getchar());
	int x=ch-'0';
	for(ch=getchar();ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

const int N=2e5+5;

#define L(x) (x==1?n:x-1)
#define R(x) (x==n?1:x+1)

set< pair<int,int> > s;

int n,a[N],b[N];

int main() {
	n=read();
	fo(i,1,n) a[i]=read();
	fo(i,1,n) b[i]=read();
	fo(i,1,n) s.insert(make_pair(-b[i],i));
	ll ans=0;
	while (!s.empty()) {
		pair<int,int> tmp=*s.begin();s.erase(s.begin());
		int x=tmp.second,cnt=b[L(x)]+b[R(x)];
		if (b[x]==a[x]) continue;
		if (b[x]<a[x]) {ans=-1;break;}
		int d=b[x]-a[x];
		if (d<cnt) {ans=-1;break;}
		ans+=d/cnt;b[x]-=d/cnt*cnt;
		s.insert(make_pair(-b[x],x));
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 11648
from collections import deque


def main():
    """
    ゲームの開始時点ではマス (1,1)
    上下左右の 4 方向のいずれかに 1 マスだけ動かすことを繰り返す
    白いマスだけを通って (H,W) にたどり着けばゲームクリア

    マス (i,j) 最初
    白で塗られている場合 .
    黒で塗られている場合 #

    いくつかの白いマス目の色を黒に変えることができる
    ただし, マス (1,1) と (H,W) の色を変えることはできず
    -> ルートの変更は不可能

    ゲームをクリアしたとき, ゲームの開始前にマスの色を変えた回数がすぬけ君のスコアとなる
    最大のスコアを求めなさい
    → 最短距離を求め,必要ない白マスを黒に変えれば高スコア(BFS?)
    → 経路を覚えておかないといけない
    """
    H, W = map(int, input().split())
    S = [
        input()
        for _ in range(H)
    ]

    bfs(S, H, W)


def bfs(S, H, W):
    # 距離を追加, 経路情報は必要ない
    q = deque([(0, 0, 0)])
    visited = [
        [False] * W
        for _ in range(H)
    ]
    visited[0][0] = True

    goal = False
    dist = 0
    while q:
        x, y, dist = q.popleft()
        if (x, y) == (W-1, H-1):
            goal = True
            break

        for dx in (-1, 1):
            nx = x+dx
            if 0 <= nx < W:
                if S[y][nx] == "." and not visited[y][nx]:
                    q.append((nx, y, dist+1))
                    visited[y][nx] = True
        for dy in (-1, 1):
            ny = y+dy
            if 0 <= ny < H:
                if S[ny][x] == "." and not visited[ny][x]:
                    q.append((x, ny, dist+1))
                    visited[ny][x] = True

    if goal:
        w_count = 0
        for s in S:
            w_count += s.count(".")
        # startは通ってないので距離に含まれない
        print(w_count - dist - 1)
    else:
        print(-1)


if __name__ == '__main__':
    main()


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

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

Measured memory_bytes: 3632
#include <iostream>
#include <set>

using namespace std;

int main() {
    int n, q, v, ans = 0;
    set<int> st;
    cin >> n;
    while(n--) {
        cin >> v;
        st.insert(v);
    }
    cin >> q;
    while (q--) {
        cin >> v;
        if (st.find(v) != st.end())
            ans++;
    }

    cout << ans << endl;

    return 0;
}


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

int main() {
	string n;
	ll k;
	cin >> n >> k;
	if(k == 3 && n.size() < 3){
		cout << "0" << endl;
		return 0;
	}
	if(k == 2 && n.size() < 2){
		cout << "0" << endl;
		return 0;
	}
	if(k == 1){
		cout << (n.size() - 1) * 9 + (ll) (n[0] - '0') << endl;
		return 0;
	}
	ll ans = 0;
	if(k == 2){
		for(ll i = 2; i < n.size(); i++){
			ans += (i-1) * 81;
		}
		ans += (int) (n[0] - '0' - 1) * (n.size() - 1) * 9;
		string tmp = n;
		for(int i = 1; i < n.size(); i++) tmp[i] = '0';
		
		for(int keta = n.size() - 1; keta > 0; keta--){
			for(int i = 1; i <= 9; i++){
				tmp[keta] = (char) (i + '0');
				if(tmp <= n) ans++;
				else{
					cout << ans << endl;
					return 0;
				}
			}
			tmp[keta] = '0';
		}
		cout << ans << endl;
		return 0;
	}
	if(k == 3){
		for(ll i = 3; i < n.size(); i++){
			ans += (i - 1) * (i - 2) / 2 * 729;
		}
		ans += (ll) (n[0] - '0' - 1) * (n.size() - 1) *(n.size() - 2) / 2* 81;
		string tmp = n;
		for(int i = 1; i < n.size(); i++) tmp[i] = '0';
		
		for(int keta1 = n.size() - 2; keta1 > 0; keta1--){
			for(int i = 1; i <= 9; i++){
				for(int keta2 = n.size() - 1; keta2 > keta1; keta2--){
					for(int j = 1; j <= 9; j++){
						tmp[keta1] = (char) (i + '0');
						tmp[keta2] = (char) (j + '0');
						if(tmp <= n) ans++;
						else{
							cout << ans << endl;
							return 0;
						}
					}
					tmp[keta2] = '0';
				}
			}
			tmp[keta1] = '0';
		}
		cout << ans << endl;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mkp make_pair
#define rep(i,s,f) for(i=s;i<f;i++)
#define db cout<<'h'<<'i'<<endl 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define PI 3.14159265
#define mod 1000000007
#define mod2 998244353
#define space 100005
//<<fixed << setprecision(9)

int main()
{
    int n,i,j,t;
    boost;

    cin>>n;
    double val=0;
    rep(i,0,n)
    {
        cin>>j;
        val+=1/(double)j;
    }
    cout<<fixed << setprecision(6)<<1/val;
    

    return 0;
}



Measured memory_bytes: 256
/*
#include<stdio.h>
int main(void){
    int S;
    scanf("%d",&S);
    printf("%d:%d:%d\n",S/3600,S%3600/60,S%3600%60);
    return 0;
}
*/

#include<stdio.h>
int main(void){
    int i,time[3];
    scanf("%d",&time[2]);
    for(i=2;0<i;i--)
        time[i-1]=time[i]/60,time[i]%=60;
    for(i=0;i<2;i++){
        printf("%d:",time[i]);
    }
    printf("%d\n",time[2]);
    return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
#define psp pair<string,pair<int,int>>
int main(){
  int n;
  cin>>n;
  vector<psp> v(n);
  for(int i=0;i<n;++i){
    cin>>v[i].first>>v[i].second.first;
    v[i].second.second=i+1;
  }
  sort(v.begin(),v.end(),[](psp a, psp b){return a.first==b.first?(a.second.first>b.second.first):a.first<b.first;});
  for(int i=0;i<n;++i)cout<<v[i].second.second<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <map>
#include <queue>
#include <unordered_set>
using namespace std;

int main() {
	int n, a, b, x = 0, y = 0;
	string s;
	cin >> n >> a >> b;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'c') {
			cout << "No" << endl; 
		}
		else if (s[i] == 'a') {
			if (x + y < a + b) {
				cout << "Yes" << endl;
				x++;
			}
			else {
				cout << "No" << endl;
			}
		}
		else if (s[i] == 'b') {
			if (x + y < a + b && y < b) {
				cout << "Yes" << endl;
				y++;
			}
			else {
				cout << "No" << endl;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 896
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int X, A;
  while (cin >> X >> A) {
    int res = X < A ? 0 : 10;
    cout << res << endl;
  }
  return 0;
}


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

int main() {
	long long x, y;
	cin >> x >> y;
	long long a = x, b = y;
	long long ans = 0, answer = 2000000001;
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 2; j++) {
			if (i == 1) {
				a *= -1;
				ans++;
			}
			if (j == 1) {
				b *= -1;
				ans++;
			}
			if (a > b) {
				ans = 0;
				a = x; b = y;
				continue;
			}
			else {
				ans += b - a;
			}
			answer = min(ans, answer);
			ans = 0;
			a = x; b = y;
		}
	}
	cout << answer << endl;
	return 0;
}

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

using namespace std;


int main()
{


/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/

  int s,w;
  cin>>s>>w;

  if(w>=s)
  {
  	cout<<"unsafe";
  }

  else
  	cout<<"safe";


}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main()
{
    int p[102];
    int x,n;
    cin>>x>>n;
    for(int i=0;i<=101;i++)
        p[i]=1;
    for(int i=0;i<n;i++)
    {
        int t;
        cin>>t;
        p[t]=0;
    }
    int l,r;
    for(int i=x;i>=0;i--)
    {
        if(p[i])
        {
            l=i;
            break;
        }
    }
    for(int i=x;i<=101;i++)
    {
        if(p[i])
        {
            r=i;
            break;
        }
    }
    if(x-l<=r-x)
        cout<<l<<endl;
    else
        cout<<r<<endl;
    return 0;
}

Measured memory_bytes: 3612
from collections import deque
from fractions import *

N = int(input())
W = deque(map(int, input().split(" ")))

S1 = [0]
S2 = [0]

S1.append(W.popleft())
S2.append(W.pop())

while len(W) > 0:
    if sum(S1) < sum(S2):
        S1.append(W.popleft())
    else:
        S2.append(W.pop())

ans = abs(sum(S1) - sum(S2))

print(int(ans))

Measured memory_bytes: 5056
l = []
n = int(input())
l = [int(i) for i in input().split()] 
ok = 0

for i in range(1,n):
	for j in range(i):
		if l[i] >= l[j]:
			if i -1 == j:
				ok += 1
			
		else:
			break

print(ok + 1)

Measured memory_bytes: 3060
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

#define MOD 1000000007;

int main(){
	stack<char> st;
	char c;
	int ans=0;
	while(cin >> c){
		if(st.empty() || st.top()==c)
			st.push(c);
		else{
			st.pop();
			ans+=2;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main () {
  int N, K;
  cin >> N >> K;
  
  int cnt = 1;
  while (N>=K) {
    N /= K;
    cnt++;
  }
  
  cout << cnt << endl;
}

Measured memory_bytes: 256
"""
A^5 - B^5
= (A - B)(A^4 + A^3*B + A^2*B^2 + A*B^3 + B^4)
= (A - B){(A + B) * (A^3 + B^3) + A^2*B^2}
= (A - B){(A + B)^2 * (A^2 - AB + B^2) + A^2*B^2}

-> (A + B)^2 > 1, (A^2 - AB + B^2) > 1, A^2*B^2 > 1.
"""


def main():
    print(*solve())


def solve():
    X = int(input())

    for a in range(-1000, 1000):
        for b in range(-1000, 1000):
            if a ** 5 - b ** 5 == X:
                return a, b


if __name__ == "__main__":
    main()


Measured memory_bytes: 9200
#include <cstdio>
#define p 1000000007
#define N 

inline int add(int x, int y) { return (x += y) >= p ? x - p : x; }
inline int sub(int x, int y) { return (x -= y) < 0 ? x + p : x; }
inline int mul(int x, int y) { return (long long)x * y % p; }
inline int power(int x, int y) { int ans = 1; for (; y; y >>= 1) { if (y & 1) ans = mul(ans, x); x = mul(x, x); } return ans; }
inline int inv(int x) { return power(x, p - 2); }

inline int fac(int n) { int ans = 1; for (int i = 1; i <= n; ++i) ans = mul(ans, i); return ans; }
inline int C(int n, int k) { int ans = 1; for (int i = n - k + 1; i <= n; ++i) ans = mul(ans, i); return mul(ans, inv(fac(k))); }

int n, a, b;

int main() {
    scanf("%d%d%d", &n, &a, &b);
    printf("%d\n", sub(power(2, n), add(add(C(n, a), C(n, b)), 1)));
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
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; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;

int main(){

  ll a,b;cin>>a>>b;
  out(a*b<<" "<<2*(a+b));

  return 0;
}



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

#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

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

    string s; cin >> s;
    string ans;
    for (int i = 0; i < s.length(); i++)
        if (i % 2 == 0) ans += s[i];
    cout << ans << endl;
}


Measured memory_bytes: 592
H, W, D = map(int, input().split())
xy = {}
for i in range(H):
    A = list(map(int, input().split()))
    for j in range(W):
        xy[A[j]] = (i + 1, j + 1)
 
d = [0] * (H * W + 1)
for i in range(D + 1, H * W + 1):
    x1, y1 = xy[i]
    x2, y2 = xy[i - D]
    d[i] = d[i - D] + abs(x1 - x2) + abs(y1 - y2)
 
Q = int(input())
for _ in range(Q):
    L, R = map(int, input().split())
    ans = d[R] - d[L]
    print(ans)

Measured memory_bytes: 22984
#include <iostream>
#include <math.h>
using namespace std;
int main() {
  int A,B,C,D,hidari,migi;
  cin >> A;
  cin >> B;
  cin >> C;
  cin >> D;
  hidari=A+B;
  migi=C+D;
  if(hidari>migi){
    cout<<"Left"<<endl;
    }else if(hidari<migi){
    cout<<"Right"<<endl;
    }else{
      cout<<"Balanced"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<fstream>
#include<utility>
#include<bitset>
#include<map>
#include<deque>
#include<cmath>
#include<random>
#include<string.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

int main() {
	makei(N);
	vi a;
	a.push_back(0);
	rep(N) {
		int A;
		cin >> A;
		a.push_back(A);
	}
	a.push_back(0);
	int preans = 0;
	Rep(1, N + 2) {
		preans += abs(a[i] - a[i - 1]);
	}
	Rep(1, N + 1) {
		say(preans - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) + abs(a[i + 1] - a[i - 1]));
	}
}

Measured memory_bytes: 1784
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    int n,m;cin>>n>>m;
    map<int, vector<int>> mp;
    priority_queue<int> pq;
    rep(i,n) {
        int a,b;cin>>a>>b;
        mp[a].push_back(b);
    }

    ll ans = 0;

    for (int i = 1; i <= m; ++i) {
        for (auto &&e: mp[i]) pq.push(e);
        if (!pq.empty()) ans+=pq.top(), pq.pop();
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10880
#include <stdio.h>

int max(int a, int b){
  if( a > b) return a;

  return b;
}

int min(int a, int b){
  if( a < b) return a;
  return b;
}


int main(int argc, char const *argv[]) {
  int weight, height,i=0;
  int x1,x2,y1,y2;
  int num;
  int a[101]={};
  int x[101]={}, y[101]={};

  scanf("%d %d %d",&weight, &height, &num );
  x1=0;x2=weight;y1=0;y2=height;

  for(i=0;i<num;i++)scanf("%d %d %d",&x[i], &y[i], &a[i] );

  for(i=0;i<num;i++){
      switch (a[i]) {
        case 1://x<xi
          x1 = max(x1, x[i]);
          break;
        case 2://x > xi
          x2 = min(x2, x[i]);
          break;
        case 3://y < yi
          y1 = max(y1,y[i]);
          break;
        case 4://y > yi
          y2 = min(y2,y[i]);
          break;
        default:
          break;
      }

  }
    if( (weight=(x2-x1)) < 0)weight = 0;
    if( (height=(y2-y1)) < 0)height = 0;

    printf("%d\n", weight*height);
  return 0;
}


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

int N,K;
vector<int> H;
int main(){
  cin >> N >> K;
  rep(i,N){
    int tmp;
    cin >> tmp;
    H.push_back(tmp);
  }
  if(N <= K){
    cout << "0" << endl;
    return 0;
  }
  sort(H.begin(),H.end());
  ll ans = 0;
  rep(i,N-K) ans += H[i];
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int w[100002], v[100002];
long long dp[2][100002];

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

    int n, K;
    cin >> n >> K;

    for(int i = 0; i < n; i++) {
        cin >> w[i] >> v[i];
    }

    for(int pos = 0; pos < n; pos++) {
        for(int W = 0; W <= K; W++) {
            if(pos == 0) {
                if(W >= w[pos]) dp[pos & 1][W] = 1LL * v[pos];
                else dp[pos & 1][W] = 0;
            }
            else {
                dp[pos & 1][W] = max(dp[(pos - 1) & 1][W],  (W >= w[pos] ? 1LL * v[pos] + dp[(pos - 1) & 1][W - w[pos]] : 0));
            }
        }
    }

    cout << dp[(n - 1) & 1][K] << endl;

}

/**
 * Knapsack 1
 */

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
main(){
    int n,h,w;
    cin >> h >> w >> n;
    int ans = h+w;
    for(int a = 0; a <= h; a++)
        for(int b =0; b <= w; b++){
            if(a*w+b*h-a*b >= n) ans = min(ans, a+b);
        }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
S = input()
T = input()


min_diff = 10000
window = len(T)
for i in range(0, len(S) - window + 1):
    x = S[i: i+window]
    count = 0
    for a, b in zip(T, x):
        if a != b:
            count += 1
    min_diff = min(count, min_diff)
print(min_diff)

Measured memory_bytes: 67756
var input = require('fs').readFileSync('/dev/stdin', 'utf8');

var Arr=(input.trim()).split("\n\n");
var arrA=(Arr[0].split("\n")).map(function(v){return v.replace(/\,.*/,"")-0;});
var arrB=(Arr[1].split("\n")).map(function(v){return v.replace(/\,.*/,"")-0;});
arrA.sort(function(a,b){a-b;});
var c={};

arrA.forEach(function(v){
if(arrB.indexOf(v)!==-1)c[v]=0;
});

arrA.forEach(function(v){
   if(c[v]!==undefined)c[v]++;
});
arrB.forEach(function(v){
   if(c[v]!==undefined)c[v]++;
});

for(var i in c)console.log(i+" "+c[i]);

Measured memory_bytes: 7640
package main

import (
	"fmt"
)

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}
func main() {
	var N int
	var S string
	var l, r [26]int
	var ans, temp int
	fmt.Scanf("%d", &N)
	fmt.Scanf("%s", &S)

	for i := 0; i < N; i++ {
		r[S[i]-'a'] += 1
	}
	for i := 0; i < N; i++ {
		l[S[i]-'a'] += 1
		r[S[i]-'a'] -= 1
		temp = 0
		for j := 0; j < 26; j++ {
			if l[j] > 0 && r[j] > 0 {
				temp += 1
			}
		}
		ans = max(ans, temp)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512