akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>

int main()
{
    char a[200],o[9999];
    int scount, i, oi = 0, x, y = 0;
    scanf("%s", &a);

    while(strcmp("-",a) != 0) {
        scanf("%d", &scount);
        for(i = 0; i < scount; i++){
            scanf("%d", &x);
            y += x;
        }
        y %= strlen(a);
        for(i = y; i < strlen(a); i++) {
            o[oi++] = a[i];
        }
        for(i = 0; i < y; i++) {

            o[oi++] = a[i];
        }
        scanf("%s", &a);
        y = 0;
        o[oi++] = '\n';
    }
    o[oi++] = '\0';
    printf("%s", o);
    return 0;
}



Measured memory_bytes: 2044
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric>
#include <regex>
#include <climits>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define RREP(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define forin(i, a) for(auto i: (a))
#define p(...) printf(__VA_ARGS__); cout << endl;
#define in(...) __VA_ARGS__; input__(__VA_ARGS__);
#define input(...) in(__VA_ARGS__)
#define out(...) output__(__VA_ARGS__);
#define output(...) out(__VA_ARGS__)
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](auto const &a, auto const &b){ return c ;}
#define key(t, x, compare) [](const t &a, const t &b){ return a x compare b x ;}
#define unless(a) if(!(a))

using namespace std;

using pii = pair<int, int>;

template <class... T>
void input__(T &...a) {
  for(auto v: {&a...}) {
    cin >> *v;
  }
}

void output__(){
  cout << endl;
}

template <class Head, class... T>
void output__(Head const &v, T const &...a) {
  if(sizeof...(a) == 0) {
    cout << v;
  } else {
    cout << v << " ";
  }
  output__(a...);
}

int main(){
  int c[3][3];
  rep(i, 3) rep(j, 3) {
    cin >> c[i][j];
  }

  int a[3];
  int b[3];
  rep(i, 3) {
    a[i] = c[0][i];
    b[i] = c[i][0] - a[0];
  }

  rep(i, 3) rep(j, 3) {
    if(c[j][i] != a[i] + b[j]) {
      out("No") exit(0);
    }
  }
  out("Yes");
}


Measured memory_bytes: 256
<?php
	$s=fgets(STDIN);
	$a="None";
	for($c='a';$c<='z'&&strlen($c)==1;$c++){
		$f=0;
		for($i=0;$i<strlen($s);$i++)$f|=$s[$i]==$c;
		if(!$f){
			$a=$c;
			break;
		}
	}
	echo $a;


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

N, W = [int(i) for i in input().split()]

def ans(N, W):
    d = [W+1] * (N * 1000 + 1)
    d[0] = 0
    V = 0

    for i in range(N):
        wi, vi = [int(i) for i in input().split()]
        V = V + vi

        for v in range(V, vi-1, -1):
            w_ = d[v - vi] + wi
            if w_ < d[v]:
                d[v] = w_

    for v in range(V, -1, -1):
        if d[v] <= W:
            return v

print(ans(N, W))

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

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

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

  if(a*b==2) cout << 3;
  else if(a*b==3) cout << 2;
  else if(a*b==6) cout << 1;
}

Measured memory_bytes: 256
import sys
N = int(input())
A = list(map(int, input().split()))
ans = 1
mod = 1000000007
cnt = 0
maxA = max(A)
dp = [0] * (max(A) + 1)
for i in A:
    if i == 0:
        dp[0] += 1
        cnt += 1
    else:
        if dp[i-1] <= 0:
            print(0)
            sys.exit()
        else:
            ans *= dp[i-1]
            ans %= mod
            dp[i-1] -= 1
            dp[i] += 1
if cnt == 1 and sum(dp) == 1:
    print((ans * 3)%mod)
elif cnt ==2 and sum(dp) == 2:
    print((ans * 6)%mod)
elif cnt == 3 and sum(dp) == 3:
    print((ans * 6)%mod)
else:
    print(0)

Measured memory_bytes: 52824
// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //

// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define ain(a,n) for(ll i=0;i<(n);++i)	cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
#define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 1000005
#define PP pair<pair<ll,ll>,pair<pair<ll,ll>,ll>>
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 1e9;
ll binexp(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
ll lcm(ll a, ll b)
{
	return ((1LL * a * b) / (__gcd(a, b)));
}

signed main() {

	fast
	// cases
	{
		ll a;
		cin >> a;
		string b;
		cin >> b;
		ll B = (b[0] - '0') * 100 + (b[2] - '0') * 10 + (b[3] - '0');
		ll ans = (a * B) / 100;
		cout << ans << END;
	}


// #ifndef ONLINE_JUDGE
// 	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
// #endif
	return 0;
}

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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int k, x;
    cin >> k >> x;
    if(k*500 >= x) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int a,b;

	scanf("%d %d",&a,&b);

	if (a>=b)
	{
		while(a--)
		printf("%d",b);
		printf("\n");
		return 0;
	}
	else 
	{
		while(b--)
			printf("%d",a);
		printf("\n");
		return 0;
	}
}


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

int main() {
  int k;
  string s;
  cin >> k >> s;
  
  int n = (int)s.size();

  if(n <= k){
    cout << s << endl;
  }else{
    cout << s.substr(0, k) << "..." << endl;
  }
  return 0;
}


Measured memory_bytes: 3624
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class TaskB {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            int ans = 0;
            int max = 0;
            for (int i = 0; i < n; i++) {
                int cn = in.nextInt();
                ans += cn;
                max = cn > max ? cn : max;
            }
            ans -= max / 2;
            out.println(ans);
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public long nextLong() {
            long n = 0;

            int b = readByte();
            while (isSpaceChar(b))
                b = readByte();

            boolean minus = (b == '-');
            if (minus)
                b = readByte();

            while (b >= '0' && b <= '9') {
                n *= 10;
                n += b - '0';
                b = readByte();
            }

            if (!isSpaceChar(b))
                throw new NumberFormatException();

            return minus ? -n : n;
        }

        public int nextInt() {
            long n = nextLong();

            if (n < Integer.MIN_VALUE || n > Integer.MAX_VALUE)
                throw new NumberFormatException();

            return (int) n;
        }

    }
}



Measured memory_bytes: 21332
/**
 *    author:  abhishekvtangod
 *    created: 
**/

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

#define mod 1000000007
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define bits(x) __builtin_popcountll(x)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define debug(x) cerr<<#x<<": "<<x<<" "<< endl;

typedef long long int ll;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// oset<pair<ll,ll>> indexed_set;

// struct HASH{
//   size_t operator()(const pair<int,int>&x)const{
//     return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
//   }
// };

void solve(){
	int n,k;
	cin >> n >> k;
	vector<int> v(n);
	ll dp[n+1];
	for(int i = 0;i<n;i++){
		cin >> v[i];
		dp[i] = 1000000000000;
	}
	dp[0] = 0;
	for(int i =0;i<n;i++){
		for(int j=i-1;j>=0 && j>=i-k;j-- ){
			dp[i] = min({dp[i],dp[j]+ abs(v[i]-v[j])}) ;
		}
		// cout<<dp[i]<<" ";
	}
	cout<<dp[n-1]<<" ";

}


int main()
{   
	IOS;

	#ifndef ONLINE_JUDGE
		freopen("C:\\Users\\Thangod\\Desktop\\zAbhi\\input.txt", "r", stdin);
		freopen("C:\\Users\\Thangod\\Desktop\\zAbhi\\output.txt", "w", stdout);
	#endif


	// ll t;cin>>t;
	// while(t--){
		solve();
	// }
	

    return 0;
}

Measured memory_bytes: 4476
import math

S = input()
K = int(input())

n1 = 0
first_non1 = 0
for s in S:
    sint = int(s)
    if sint == 1:
        n1 += 1
    else:
        first_non1 = sint
        break


if K <= n1:
    print(1)
else:
    print(first_non1)


Measured memory_bytes: 2940
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		String a = sc.next();
		String b = sc.next();
		
		// 計算
		String result = "EQUAL";
		if(a.length() > b.length()) result = "GREATER";
		if(a.length() < b.length()) result = "LESS";
		if(a.length() == b.length()){
		    if(a.compareTo(b) > 0) result = "GREATER";
		    if(a.compareTo(b) < 0) result = "LESS";
		}
		
		// 出力
		System.out.println(result);
	}
}



Measured memory_bytes: 21712
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - AtCoDeerくんとボール色塗り / Painting Balls with AtCoDeer
            var lines = ReadLines<int>(1).ToList();
            int n = lines[0][0];
            int k = lines[0][1];

            int combination = CalcCombinationCount(n, k);
            Console.WriteLine(combination);
        }

        static int CalcCombinationCount(int n, int k)
        {
            int count = k;

            for(int i = 1; i < n; i++)
            {
                count *= (k - 1);
            }

            return count;
        }
                               
        static IEnumerable<List<T>> ReadLines<T>(int count = 0, char separator = ' ')
        {
            //[summary]コンソールの値を読み込んで、List<T>のコレクションを返却

            //読み込む行数が未指定のときは、1行目の値を"count"とみなす
            if (count == 0)
            {
                string line = Console.ReadLine().TrimEnd();
                count = int.Parse(line);
            }

            for (int i = 0; i < count; i++)
            {
                //コンソールを1行読み込み
                string line = Console.ReadLine().TrimEnd();

                //char型のときは1文字ずつに分割
                if (typeof(T) == typeof(char))
                {
                    var list = line.ToCharArray().ToList();
                    yield return (List<T>)(object)list;
                }
                else
                {
                    //読み込んだ値を"separator"で区切る
                    var list = line.Split(separator).ToList();

                    //int型のときは数値に変換
                    if (typeof(T) == typeof(int))
                    {
                        var numbers = list.ConvertAll(int.Parse);
                        yield return (List<T>)(object)numbers;
                    }
                    else
                    {
                        yield return (List<T>)(object)list;
                    }
                }
            }
        }
    }
}


Measured memory_bytes: 13268
#include<stdio.h>

int main(){
    int A,B;
    int sum=0;
    scanf("%d %d",&A,&B);
    B -= 1;
    if( B >= 0){
        sum += B/(A-1);
        if(B % (A-1) != 0){
            sum++;
        }
    }
    
    printf("%d",sum);
    return 0;
}

Measured memory_bytes: 128
require 'prime'

q = gets.strip.to_i
lr = readlines.map {|line| line.strip.split.map(&:to_i) }

max_r = lr.map(&:last).sort.last

cum = Array.new(max_r+1, 0)

1.step(max_r, 2) do |num|
  cum[num]+=1 if num.prime? && ((num+1)/2).prime?
end

(cum.length-1).times do |i|
  cum[i+1] = cum[i] + cum[i+1]
end

lr.each do |cl, cr|
  p cum[cr] - cum[cl-1]
end




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

using ld=double;
#define REP(i,s,n) for(long long i=s;i<n;i++)
ld ans;
//[競プロのための高速フーリエ変換](https://www.creativ.xyz/fast-fourier-transform/)
// Cooley–Tukey FFT algorithm
const ld PI=acos(-1);
complex<ld> W,S,T;
inline vector<complex<ld>> fft(vector<complex<ld>> a,bool inverse=false) {
  int n=a.size(),h=0;
  for(int i=0;(1<<i)<n;i++)h++;
  REP(i,0,n){
    int j=0;
    REP(k,0,h)j|=(i>>k&1)<<(h-1-k);
    if(i<j)swap(a[i],a[j]);
  }
  for(int b=1;b<n;b*=2){
    REP(j,0,b){
      W=polar((ld)1.0,(2*PI)/(2*b)*j*(inverse?1:-1));
      for(int k=0;k<n;k+=b*2){
        S=a[j+k];
        T=a[j+k+b]*W;
        a[j+k]=S+T;
        a[j+k+b]=S-T;
      }
    }
  }
  if(inverse)REP(i,0,n)a[i]/=n;
  return a;
}
inline vector<complex<ld>> fft(vector<ld> a,bool inverse=false){
  vector<complex<ld>> a_complex(a.size());
  REP(i,0,a.size())a_complex[i]=complex<ld>(a[i],0);
  return fft(a_complex,inverse);
}
vector<ld> convolve(vector<ld> a,vector<ld> b){
  int s=a.size()+b.size()-1,t=1;
  while(t<s)t*=2;
  a.resize(t);
  b.resize(t);
  vector<complex<ld>> A=fft(a);
  vector<complex<ld>> B=fft(b);
  REP(i,0,t)A[i]*=B[i];
  A=fft(A,true);
  a.resize(s);
  REP(i,0,s)a[i]=A[i].real();
  return a;
}

int main(){
  long long n,d,x;cin>>n>>d>>x;
  ld temp=1;
  REP(i,1,n+1){
    temp*=(ld)(2*i-1)/(2*i);
    ans+=temp*(n-i+1);
  }
  vector<ld> a(n+1,0),b(n+1,0);
  a[1]=b[1]=0.5;
  REP(i,2,n+1)a[i]=a[i-1]*(2*i-1)*i/(ld)((2*i)*(i-1));
  REP(i,2,n+1)b[i]=b[i-1]*(2*i-3)/(ld)(2*i);
  vector<ld> c=convolve(a,b);
  REP(i,2,n+1)ans-=c[i]*(n-i+1)/(ld)i;
  ans*=(2*d+x*(2*n-1));
  cout<<fixed<<setprecision(12)<<ans<<endl;
}


Measured memory_bytes: 43728
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200025,inf=0x3f3f3f3f;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int n,m,q,las,ans;
set<int> a[N];
int main(){
//	freopen("balance.in","r",stdin);
//	freopen("balance.out","w",stdout);
	n=read();m=read();
	q=read();
	while (q--){
		int x=read(),y=read();
		a[y].insert(x);
	}
	for (int i=1;i<=m;i++) a[i].insert(n+1);
	ans=n;las=0;
	for (int i=1;i<=m;i++){
		las++;
		while ((las<=n)&&(a[i].count(las))) las++;
		if (las>n) break;
		int t=*a[i].upper_bound(las);
		ans=min(ans,t-1);
	}
	printf("%d\n",ans);
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> C(4);
    for(int i = 0; i < N; i++){
        string S;
        cin >> S;
        if (S == "AC") {
            C[0]++;
        } else if (S=="WA") {
            C[1]++;
        } else if (S== "TLE") {
            C[2]++;
        } else
        {
            C[3]++;
        }
        
    }

    cout << "AC x " << C[0] << endl;
    cout << "WA x " << C[1] << endl;
    cout << "TLE x " << C[2] << endl;
    cout << "RE x " << C[3] << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define iinf 2000000000
#define linf 1000000000000000000
#define ulinf 10000000000000000000ull
#define MOD 1000000007
#define lson(v) ((v)<<1)
#define rson(v) (((v)<<1)^1)
#define mpr make_pair
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned long UL;
typedef unsigned short US;
typedef pair < int , int > pii;
clock_t __stt;
inline void TStart(){__stt=clock();}
inline void TReport(){printf("\nTaken Time : %.3lf sec\n",(double)(clock()-__stt)/CLOCKS_PER_SEC);}
template < typename T > T MIN(T a,T b){return a<b?a:b;}
template < typename T > T MAX(T a,T b){return a>b?a:b;}
template < typename T > T ABS(T a){return a>0?a:(-a);}
template < typename T > void UMIN(T &a,T b){if(b<a) a=b;}
template < typename T > void UMAX(T &a,T b){if(b>a) a=b;}
int n,a[100005],b[100005];
LL res;
int main(){
    // inputing start
    scanf("%d",&n);
	int xb,x2;
	for(xb=0;xb<n;++xb){
		scanf("%d%d",a+xb,b+xb);
		a[xb]%=b[xb];
	}
    #ifdef LOCAL
        TStart();
    #endif
    // calculation start
    reverse(a,a+n);
	reverse(b,b+n);
	for(xb=0;xb<n;xb++){
		LL aa=a[xb],bb=b[xb];
		if(bb==1) continue;
		aa+=(LL)res;
		aa%=(LL)bb;
		if(aa!=0)res+=(LL)(bb-aa);
	}
	cout<<res;
    #ifdef LOCAL
        TReport();
    #endif
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<double,double> pdd;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) ll(i.size())
#define FOR(i, j, k, in) for (ll i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (ll i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
// const ll MAXN = 

ll a,b;
/********** Good Luck :) **********/
int main()
{
    IOS();
    cin >> a >> b;
    if (b % a == 0) {
        cout << a + b << endl;
    } else{
        cout << b - a << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

// inf
constexpr ll infl = 10000000000000000LL;
constexpr int inf = 1000000000;

int main() {
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    string s;
    cin >> s;

    --a;
    --b;
    --c;
    --d;

    for (int i = a; i <= min((int)s.size() - 2, max(c, d)); ++i) {
        if (s[i] == '#' && s[i + 1] == '#') {
            cout << "No" << endl;
            return 0;
        }
    }

    if (c < b || c < d) {
        cout << "Yes" << endl;
    } else {
        for (int i = max(b, 1); i <= min((int)s.size() - 2, d); ++i) {
            if (s[i] == '.' && s[i + 1] == '.' && s[i - 1] == '.') {
                cout << "Yes" << endl;
                return 0;
            }
        }
        cout << "No" << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll; 
typedef pair<int, int> pii;

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

const int mod = 1000000007;
long long r[310000];
long long fac[310000];
long long ifac[310000];
int h,w,a,b;

long long C(int n, int k) {
	long long p = (fac[n] * ifac[k])%mod;
	return (p*ifac[n-k])%mod;
}

int main() {
	scanf("%d %d %d %d", &h, &w, &a, &b);

	fac[0]=fac[1]=ifac[0]=ifac[1]=1;
	r[1] = 1;

	long long m = mod;
	for (int i=2; i<=200100; ++i) {
		fac[i] = (i * fac[i-1]) % mod;
		r[i] = (m - (m/i) * r[m%i] % m) % m;
		ifac[i] = (r[i] * ifac[i-1]) % mod;
	}

	int ans = 0;
	for (int i = 1; i <= h-a; i++) {
		long long th = C( (b-1)+(i-1), i-1 ) % mod;
		th = (th * 1ll * C( (w-b-1)+(h-i), h-i ) ) % mod;
		ans = (ans + th) % mod;
	}
	
	printf("%d\n", ans);
}

Measured memory_bytes: 4992
#include <iostream>
#include <stdio.h>
using namespace std;

int mem[2500000];
int da[2][4]={{0,1,2,3},{4,5,6,7}},dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};

int cal() {	return da[0][0]*262144+da[0][1]*32768+da[0][2]*4096+da[0][3]*512+da[1][0]*64+da[1][1]*8+da[1][2]; }

void make(int n,int x,int y) {
  int i,c;	 
  mem[cal()]=n;
  for (i=0;i<4;i++) {
	  if (x+dx[i]>-1 && x+dx[i]<4 && y+dy[i]>-1 && y+dy[i]<2) {
		  swap(da[y][x],da[y+dy[i]][x+dx[i]]);
		  c=cal();
		  if (mem[c]>n+1) make(n+1,x+dx[i],y+dy[i]);
		  swap(da[y][x],da[y+dy[i]][x+dx[i]]);
	      }
     }
  return;
}

int main() {
 int i;
 for (i=0;i<2500000;i++) mem[i]=99;
 make(0,0,0);
 while(cin >>da[0][0]>>da[0][1]>>da[0][2]>>da[0][3]>>da[1][0]>>da[1][1]>>da[1][2]>>da[1][3]) cout << mem[cal()] << endl;
 return 0;	
}

Measured memory_bytes: 10932
#include<stdio.h>

int main(void){
	int n;
	scanf("%d",&n);
	int i,temp,count=0;
	
	for(i=0;i<n;i++){
		scanf("%d",&temp);
		if((temp*(i+1))%2){
			count++;
		}
	}
	printf("%d",count);
}

Measured memory_bytes: 1728
#include <iostream>
#include <cstring>
using namespace std;
int main(){
	int tmp, num[35];
	memset(num, -1, sizeof(num));
	for (int i = 0; i < 28;i++){
		cin >> tmp;
		num[tmp] =	1;
	}
	for (int i = 1; i < 31; i++){
		if (num[i] == -1)
			cout << i << endl;
	}
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

const int MOD = 100000;
const int INF = 1000000000;
const ll LINF = 1000000000000000000L;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const int ddx[] = {1, 1, 0, -1, -1, -1, 0, 1};
const int ddy[] = {0, 1, 1, 1, 0, -1, -1, -1};

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

int extgcd(int a, int b, int& x, int&y) {
    int d = a;
    if(b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }else {
        x = 1;
        y = 0;
    }
    return d;
}

int inv(int a) {
    int x, y;
    extgcd(a, MOD, x, y);
    return (x + MOD) % MOD;
}

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

    int ans = 0;
    for(int i = 1; i < n; i++) {
        int tmp = 0;
        int kari = 0;
        for(int j = 0; i + j < n; j++) {
            if(s[j] == s[i + j]) tmp++;
            else {
                kari = max(kari, tmp);
                tmp = 0;
            }
        }
        kari = max(kari, tmp);
        ans = max(ans, min(kari, i));
    }

    cout << ans << endl;
}


Measured memory_bytes: 384
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        sa: chars,
        sb: chars,
        sc: chars
    }
    let la = sa.len();
    let lb = sb.len();
    let lc = sc.len();
    let mut ia = 0;
    let mut ib = 0;
    let mut ic = 0;
    let mut t = 'a';
    let mut win = '?';
    while win == '?' {
        match t {
            'a' => {
                if ia == la {
                    win = 'A';
                } else {
                    t = sa[ia];
                    ia += 1;
                }
            },
            'b' => {
                if ib == lb {
                    win = 'B';
                } else {
                    t = sb[ib];
                    ib += 1;
                }
            },
            _ => {
                if ic == lc {
                    win = 'C';
                } else {
                    t = sc[ic];
                    ic += 1;
                }
            }
        }
    }
    println!("{}", win);
}


Measured memory_bytes: 4352
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <queue>
#include <utility>
#include <vector>

const int N = 1e5 + 10;
int n, Q, k;
int64_t dis[N];
std::vector<std::pair<int, int64_t>> to[N];
bool v[N];

inline void dfs(int cur, int64_t d) {
    dis[cur] = d;
    v[cur] = true;
    for (auto p : to[cur])
        if (!v[p.first])
            dfs(p.first, d + p.second);
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i < n; i++) {
        static int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        to[a].push_back(std::make_pair(b, c));
        to[b].push_back(std::make_pair(a, c));
    }

    scanf("%d%d", &Q, &k);

    dfs(k, 0);

    while (Q--) {
        static int x, y;
        scanf("%d%d", &x, &y);
        printf("%lld\n", dis[x] + dis[y]);
    }
    
    return 0;
}



Measured memory_bytes: 12288
def solve(string):
    a, b, c, x, y = map(int, string.split())
    if a + b <= 2 * c:
        return str(a * x + b * y)
    if 2 * c <= a and 2 * c <= b:
        return str(2 * c * max(x, y))
    base = 2 * c * min(x, y)
    diff = abs(x - y)
    return str(base + min(a, 2 * c) * diff if x >= y else base + min(b, 2 * c) * diff)


if __name__ == '__main__':
    print(solve(input()))


Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

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


signed main(){
  int h,w,n;
  map< pair<int,int> ,int> mp;
  int ans[10]={0};
  int dx[9]={1,1,1,0,-1,-1,-1,0,0};
  int dy[9]={1,0,-1,-1,-1,0,1,1,0};
  
  cin>>h>>w>>n;
  ans[0]=(h-2)*(w-2);
  rep(i,n){
    int a,b;
    cin>>a>>b;
    rep(j,9){
      if(a+dx[j]>1 && a+dx[j]<h && b+dy[j]>1 && b+dy[j]<w){
	pair<int,int> p=make_pair(a+dx[j],b+dy[j]);
	mp[p]++;
	ans[mp[p]-1]--;
	ans[mp[p]]++;
      }
    }
  }
  rep(i,10){
    cout<<ans[i]<<endl;
  }

  return 0;
}


Measured memory_bytes: 56448
#include <bits/stdc++.h>
using namespace std;
int d,t,s;
int ok() {
    if(s*t>=d)return 1;
    return 0;
}
int main() {
    cin>>d>>t>>s;
    if(ok()) cout<<"Yes";
    else cout<<"No";
	return 0;
}


Measured memory_bytes: 3596
N = int(input())
A = [int(hoge) for hoge in input().split()]
Money = 1000
Kabu = 0
for n,a in enumerate(A):
    if n>0:
        if a>=A[n]:#値上がりした
            Money += a*Kabu
            Kabu = 0
        else:
            Kabu += Money//a
            Money %= a
    if n<N-1:
        if a>=A[n+1]:#値下がりする
            Money += a*Kabu
            Kabu = 0
        else:
            Kabu += Money//a
            Money %= a
Money += A[-1] * Kabu
print(Money)

            

Measured memory_bytes: 61940
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n, m = map(int, input().split())
ans = 0
if n >= 2:
	ans += combinations_count(n, 2)
if m >= 2:
    ans += combinations_count(m, 2)
print(ans)

Measured memory_bytes: 9120
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,k;
    cin>>n;
    ll a[n],b[n],c[n];
    for(int i=0;i<n;i++)
    {cin>>a[i];cin>>b[i];cin>>c[i];
    
    }
        ll dp[n][3];
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];
    for(int i=1;i<n;i++)
    {
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
         dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
          dp[i][2]=max(dp[i-1][1],dp[i-1][0])+c[i];
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}



Measured memory_bytes: 8248
#include "iostream"
#include "algorithm"
#include "cstring"
#include "cstdio"
#include "cmath"
#include "vector"
#include "map"
#include "set"
#include "queue"
using namespace std;
#define MAXN 200006
#define int long long
#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define all(x) (x).begin() , (x).end()
#define mem( a ) memset( a , 0 , sizeof a )
typedef long long ll;
int n , m , q;
void solve() {
	cin >> n;
	int cur = 100 , res = 0;
	while( cur < n ) 
		cur = floor(cur * (long double)(1.01)) , ++ res;
	cout << res << endl;
}

signed main() {
//    int T;cin >> T;while( T-- ) solve();
    solve();
}

Measured memory_bytes: 3632
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define LB(c, x) lower_bound(c.begin(), c.end(), x)
#define UB(c, x) upper_bound(c.begin(), c.end(), x)
#define LI(c, x) distance(c.begin(), LB(c, x))
#define UI(c, x) distance(c.begin(), UB(c, x))

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
ll modpow(ll a, ll b, ll m) {
    if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll h = modpow(a, b / 2, m);
        return h * h % m;
    } else {
        return a * modpow(a, b - 1, m) % m;
    }
}
ll comb(ll a, ll b, ll m) {
    if (b > a - b) {
        return comb(a, a - b, m);
    }
    ll c = 1, d = 1;
    REP(i, b) {
        c *= (a - i);
        d *= (b - i);
        c %= m;
        d %= m;
    }
    return c * modpow(d, m - 2, m) % m;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    int cnt = (N - 1) * (N - 2) / 2;
    if (cnt < K) {
        cout << -1 << endl;
        return 0;
    }
    int res = 0;
    vector<vector<bool>> G(N, vector<bool>(N, false));
    FOR(i, 1, N, 1) {
        G[0][i] = true;
        res++;
    }
    int s = 1, t = 2;
    REP(i, cnt - K) {
        G[s][t] = true;
        res++;
        if (t < N - 1) {
            t++;
        } else {
            s++;
            t = s + 1;
        }
    }
    cout << res << endl;
    REP(i, N) {
        REP(j, N) {
            if (G[i][j]) {
                cout << i + 1 << " " << j + 1 << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())


# for _ in range(ii()):
    
a=li()
for i in range(5):
    if a[i]==0:
        print(i+1)
        break

Measured memory_bytes: 61892
// Practice AtCoder
// author: Leonardone @ NEETSDKASU
// 他の人の答え見て参考にした

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(&mut std::io::stdin(), &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let s = get().as_bytes();
    let k = get!();
    let n = s.len();
    
    let mut c = 0;
    for i in 0 .. n {
        if s[0] == s[i] {
            c += 1;
        }
    }
    if c == n {
        let ans = n as i64 * k / 2;
        println!("{}", ans);
        return;
    }
    
    let mut c = 1;
    let mut sum1 = 0;
    for i in 0 .. n-1 {
        if s[i] == s[i+1] {
            c += 1;
        } else {
            sum1 += c / 2;
            c = 1;
        }
    }
    sum1 += c / 2;
    
    let mut s2 = s.to_vec();
    s2.extend_from_slice(&s);
    let s = s2;
    let n = s.len();
    let mut c = 1;
    let mut sum2 = 0;
    for i in 0 .. n-1 {
        if s[i] == s[i+1] {
            c += 1;
        } else {
            sum2 += c / 2;
            c = 1;
        }
    }
    sum2 += c / 2;
    let diff = sum2 - sum1;
    let ans = sum1 + diff * (k - 1);
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<string.h>

typedef int32_t i32;
typedef int64_t i64;

#define F 2

const i32 prime[2] = {1000000033, 1000000087};
const i32 rad = 27;

typedef struct hashNode {
  i32 val[F];
} node;

int cmp (const void *a, const void *b) {
  node *p = (node *) a;
  node *q = (node *) b;
  for (i32 i = 0; i < F; ++i) {
    i32 d = p->val[i] - q->val[i];
    if (d != 0) {
      return d < 0 ? -1 : 1;
    }
  }
  return 0;
}

i32 modPow (i32 r, i32 n, i32 mod) {
  i32 t = 1;
  i32 s = r;
  while (n > 0) {
    if (n & 1) t = (i64) t * s % mod;
    s = (i64) s * s % mod;
    n >>= 1;
  }
  return t;
}

void run (void) {
  char *s = (char *) calloc (100000 + 1, sizeof (char));
  scanf("%s", s);
  const i32 n = strlen (s);
  node *p = (node *) calloc (n, sizeof (node));
  i32 l = 0;
  i32 r = n;
  while (r - l > 1) {
    const i32 m = (l + r) / 2;
    const i32 len = m;
    i32 inv[F];
    node t;
    for (i32 i = 0; i < F; ++i) {
      t.val[i] = 0;
      inv[i] = modPow (rad, len - 1, prime[i]);
    }
    for (i32 i = 0; i < len - 1; ++i) {
      i32 d = s[i] - 'a' + 1;
      for (i32 k = 0; k < F; ++k) {
	t.val[k] = ((i64) t.val[k] * rad + d) % prime[k];
      }
    }
    i32 plen = 0;
    for (i32 i = len - 1; i < n; ++i) {
      i32 d = s[i] - 'a' + 1;
      for (i32 k = 0; k < F; ++k) {
	t.val[k] = ((i64) t.val[k] * rad + d) % prime[k];
      }
      p[plen++] = t;
      d = s[i - len + 1] - 'a' + 1;
      for (i32 k = 0; k < F; ++k) {
	t.val[k] = (t.val[k] - (i64) d * inv[k] % prime[k] + prime[k]) % prime[k];
      }
    }
    qsort (p, plen, sizeof (node), cmp);
    i32 i;
    for (i = 0; i < plen - 1; ++i) {
      if (cmp (p + i, p + i + 1) == 0) {
	break;
      }
    }
    if (i < plen - 1) {
      l = m;
    } else {
      r = m;
    }
  }
  printf("%" PRIi32 "\n", n - r + 1);
}

int main (void) {
  run ();
  return 0;
}


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

#define ll long long

using namespace std;
const int MX = 200'000 + 5; // check bounds!
typedef vector<int> vi;

int main() {
    int n;
    cin >> n;
    vi a(n);
    for (auto &x : a)
        cin >> x;

    ll sol = 0;

    vi b(n);
    for (int i = 0; i < n; ++i) {
        b[i] = - a[i] - i;
//        cout << b[i] << " ";
    }
//    cout << endl;

    map<int, int> m;
    for (auto x : b)
        m[x]++;  

    for (int i = 0; i < n; ++i)
        if (m.count(a[i] - i))
            sol += m[a[i] - i];
    
    cout << sol;
    return 0;
}


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

typedef long long ll;
 
using tpl = tuple<int, int, int>;
typedef pair<int,int> pii;

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


const int MAX_N=2011;
// 1baseでs1,...,snの和を計算
class BIT{
private:
  ll bit[MAX_N];
  int n;
public:
  BIT(int sz){
    n=sz;
    for(int i=0;i<=n;i++)
      bit[i]=0;
  }
  ll sum(int i){
    ll s=0;
    while(i>0){
      s+=bit[i];
      i-=i&-i;
    }
    return s;
  }
  // from-to間の総和を求める
  ll rangeSum(int from,int to){
    ll res=0;
    res=(sum(to)-sum(from-1));
    return res;
  }
  void add(int i,ll x){
    while(i<=n){
      bit[i]+=x;
      i+=i&-i;
    }
  }
  // sumとaddを組み合わせて、iの場所にxの値を代入
  void insert(int i,ll x){
    add(i,-(sum(i)-sum(i-1))+x);
  }
};


int N;
char C[4010];
int A[4010];
int dp[2010][2010];
int wfreq[2010][2010]; // wfreq[i][j] -> 黒をj個置いた状態で、i個目の白を置いた時の、転置数
int bfreq[2010][2010]; // bfreq[i][j] -> 白をj個置いた状態で、i個目の黒を置いた時の、転置数

int rec(int w, int b){
    if(dp[w][b] >= 0) return dp[w][b];
    int res = 1<<29;
    if(w == 0 && b == 0){
        res = 0;
    }
    else{
        if(w > 0){
            res = min(res, rec(w - 1, b) + wfreq[w][b]);
        }
        if(b > 0){
            res = min(res, rec(w, b - 1) + bfreq[b][w]);
        }
    }
    
    return dp[w][b] = res;
}

int main(){
    cin >> N;
    for(int i = 0; i < 2*N; i++)
        cin >> C[i] >> A[i];

    memset(dp, -1, sizeof(dp));

    // wfreq, bfreqを計算
    for(int i = 0; i <= N; i++){
        BIT wbit(N);
        BIT bbit(N);
        for(int j = 2 * N - 1; j >= 0; j--){
            if(C[j] == 'W'){
                wfreq[A[j]][i] = bbit.sum(i) + wbit.sum(A[j]);
                wbit.add(A[j], 1);
            }
            else{
                bfreq[A[j]][i] = wbit.sum(i) + bbit.sum(A[j]);
                bbit.add(A[j], 1);
            }
        }
        // cout << i << endl;
        // for(int j = 1; j <= N*2; j++){
        //     cout << bfreq[j][i] << " ";
        // }
        // cout << endl;
    }

    cout << rec(N, N) << endl;
    
}


Measured memory_bytes: 47872
import java.util.*;	
public class Main {
	public static void main(String[] args) {
					Scanner in =new Scanner(System.in);
					String str = in.nextLine();
					str=str.toUpperCase(); //只对英文字母有效 对其他字符无效
					System.out.println(str);
					in.close();
			}
	}


Measured memory_bytes: 26296
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_map>
#include<stack>
#include<random>
#include<set>
#include<map>
#include<functional>
using namespace std;
#define int long long
#define inf 1145141919
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int>P;
typedef pair<int, P> PP;
struct edge { int to, cost; };
const long long mod = 10000000;
vector<int>G[200001];
int vst[200001];

int dfs(int now) {
	rep(i, G[now].size()) {
		if (vst[G[now][i]] == 0) {
			vst[G[now][i]] = 1;
			dfs(G[now][i]);
		}
	}
	return 0;
}
signed main() {
	int n, m; cin >> n >> m;
	rep(i, n) {
		int k; cin >> k;
		rep(j, k) {
			int l; cin >> l;
			G[i].push_back(n + l - 1);
			G[n + l - 1].push_back(i);
		}
	}
	dfs(0);
	int sum = 0;
	rep(i, n)sum += vst[i];
	if (sum == n)puts("YES");
	else puts("NO");
}

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

#define YES(condition) if(condition) cout << "YES" << endl; else cout << "NO" << endl
#define Yes(condition) if(condition) cout << "Yes" << endl; else cout << "No" << endl
#define POSS(condition) if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl
#define Poss(condition) if(condition)cout << "Possible" << endl; else cout << "Impossible" << endl
#define First(condition) if(condition)cout << "First" << endl; else cout << "Second" << endl
#define negative(condition, num) if(condition)cout << -1 << endl; else cout << num << endl
int character_count(string text, char character){ int ans = 0; for(int i = 0; i < text.size(); i++){ ans += (text[i] == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
long gcd(long a, long b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }}
#define mod long(1e9 + 7)
#define bitcount(n) __builtin_popcount(n)

long K(long I, long O, long J, long L){
    return I / 2 * 2 + O + J / 2 * 2 + L / 2 * 2;
}

int main(){
    long I, O, T, J, L, S, Z;
    cin >> I >> O >> T >> J >> L >> S >> Z;
    if(I % 2 + J % 2 + L % 2 >= 2 && I && J && L){
        cout << K(I - 1, O, J - 1, L - 1) + 3 << endl;
    }else{
        cout << K(I, O, J, L) << endl;
    }
}



Measured memory_bytes: 256
#include <iostream>

int main(void){

	int h, w;
	std::cin >> h >> w;

	char** mass;
	mass = new char*[h];
	for(int y = 0; y < h; y++){
		mass[y] = new char[w];
		
		for(int x = 0; x < w; x++){
			std::cin >> mass[y][x];
		}
	}

	// 番号に置きかえる
	for(int y = 0; y < h; y++){
		for(int x = 0; x < w; x++){
			
			if(mass[y][x] == '.'){

				int tmp = 0;
				for(int dy = y - 1; dy <= y + 1; dy++){
					for(int dx = x - 1; dx <= x + 1; dx++){

						if(dy == y && dx == x){ continue; }

						if(	dy >= 0 && dy < h &&
							dx >= 0 && dx < w &&
							mass[dy][dx] == '#'){

							tmp++;
						}
					}
				}

				mass[y][x] = '0' + tmp;
			}
		}
	}

	// 出力
	for(int y = 0; y < h; y++){
		for(int x = 0; x < w; x++){
			std::cout << mass[y][x];
		}
		std::cout << std::endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>

using namespace std;

int main()
{
    char h[3];
    scanf("%c%c%c",&h[0],&h[1],&h[2]);
    if(h[1]=='B')
        printf("ARC");
    else
    {
        printf("ABC");
    }
    
    return 0;
}

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

using namespace std;

void solve()
{
    int n;
    while (cin >> n && n)
    {
        vector<double> s(n);
        for (auto &v : s)
            cin >> v;
        double mu = accumulate(s.begin(), s.end(), (double)0) / n, var = 0;
        for (auto &v : s)
        {
            var += (v - mu) * (v - mu);
        }
        var /= n;
        cout << setprecision(9) << sqrt(var) << endl;
    }
}

int main()
{
    solve();
    return 0;
}



Measured memory_bytes: 3280
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <algorithm>
#include <array>
#include <string.h>
#include <vector>




int main() {
	char S[4];

	scanf("%s", &S);

	int tmp, tmp2;
	int sum = 700;

	
	if (S[0] == 111) {
		sum += 100;
	}
	if (S[1] == 111) {
		sum += 100;
	}
	if (S[2] == 111) {
		sum += 100;
	}


	printf("%d", sum);

	return 0;
}

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

//数列 B の全ての項の積が偶数 ⇔ 数列 B の項のうち少なくとも１つは偶数
//これを全て列挙するのは大変なので、あり得る「似ている項」の総数から、全て奇数項となる数列の総数を引くことで答えを求める
//数列 A に似ている数列とは、数列 A の各項に対し、+1, +0, -1 のいずれかを行うので、似ている数列の総数は３のN乗
//全て奇数列となるとき、数列 A の奇数項は +0 で、偶数項は +1, -1 となるので、その総数は (偶数項の数)の2乗
//これより 3^N - (偶数項数)^2 で答えが求められる

int main(){
    int N;
    scanf("%d", &N);
    vector<int> A(N);
    int even = 0;//偶数項の数
    for(int i = 0; i < N; i++){
        scanf("%d", &A[i]);
        if(A[i] % 2 == 0)even++;
    }
    int ans = pow(3, N);//似ている数列の総数
    ans -= pow(2, even);//全て奇数項となる場合を引く
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
import math

h, n = map(int, input().split())
a = [0] * n
b = [0] * n
#print(a, b)
for i in range(n):
    a[i], b[i] = map(int, input().split())

#print(a)
#print(b)
INF = int(1e10)
dp = [[INF] * (h+1) for i in range(n+1)]
for i in range(h+1):
    dp[0][i] = math.ceil(i / a[0]) * b[0]
for i in range(n):
    dp[i][0] = 0
for i in range(n):
    for j in range(h+1):
        if j < a[i]:
            dp[i+1][j] = min(-(-j // a[i]) * b[i], dp[i][j])
        else:
            dp[i+1][j] = min(-(-j // a[i]) * b[i], dp[i][j], dp[i+1][j - a[i]] + b[i])
#print(dp)
print(dp[n][h])


Measured memory_bytes: 122604
import copy
N = int(input())
T = list(map(int, input().split()))
copy_T = copy.deepcopy(T)
M = int(input())
P_list = []
X_list = []
lists = []
for i in range(M):
    P, X = map(int, input().split())
    P_list.append(P)
    X_list.append(X)
for i in range(M):
    copy_T = copy.deepcopy(T)
    tmp = P_list[i]
    copy_T[tmp - 1] = X_list[i]
    print(sum(copy_T))


Measured memory_bytes: 3444