akhauriyash/Code-Regression huggingface dataset:
def check(card_set):
    for i in card_set:
        if len(i)%3!=0:
            return 0
        i.sort()
        for j in range(int(len(i)/3)):
            if i.count(i[0])>=3:
                a=i[0]
                i.remove(a)
                i.remove(a)
                i.remove(a)
            else:
                a=i[0]
                try:
                    i.remove(a)
                    i.remove(a+1)
                    i.remove(a+2)
                except ValueError:
                    return 0       
    return 1




n=int(input())

for count in range(n):
    number=[int(i) for i in input().split(" ")]
    color=input().split(" ")
    R=[]
    G=[]
    B=[]
    for i in range(9):
        if color[i]=="R":
            R.append(number[i])
        elif color[i]=="G":
            G.append(number[i])
        else:
            B.append(number[i])
    print(check([R,G,B]))

Measured memory_bytes: 7772
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string s;
    cin >> s;
    if(s == "Sunny"){
        cout << "Cloudy" << endl;
    }else if(s == "Cloudy"){
        cout << "Rainy" << endl;
    }else{
        cout << "Sunny" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    debug("debug test\n");
    int n,m;cin>>n;
    double sum = 0;
    vector<int> a(n);
    rep(i, n){
        cin>>a[i];sum+= a[i];
    }
    sum /= n;
    int av = round(sum);
    int ans = 0;
    rep(i, n){
        ans += (a[i]-av)*(a[i]-av);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

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

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll x,n;
    cin >> x >> n;
    vector<ll> z(n);
    for (int i = 0; i < n; i++) {
        cin >> z[i];
    }
    sort(z.begin(), z.end());
    ll flag = 0;
    for (int i = 0; i < n; i++) {
        if (z[i] == x)flag = 1;
    }
    if (flag = 0)cout << x << endl;
    else {
        ll a = 0;
        for (int j = 0; j < 34567; j++) {
            ll aa = 0;
            for (int i = 0; i < n; i++) {

                if (z[i] == x - j) {
                    aa = 1;
                }
            }
            if (aa == 0) {
                cout << x - j << endl;
                break;
            }
            ll a = 0;
            for (int i = 0; i < n; i++) {
                
                if (z[i] == x+j) {
                    a = 1;
                }
            }
            if (a == 0) {
                cout << x+j << endl;
                break;
            }

        }
    }
}

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

red = []
blue = []


for i in range(n):
  x,y = map(int, input().split())
  red.append([x,y])
  
for i in range(n):
  x,y = map(int, input().split())
  blue.append([x, y])


red.sort(key=lambda x: x[1], reverse=True)
blue.sort()

ans = 0

for i in red.copy():
  for j in blue.copy():
    p,q = i
    r,s = j
    if p < r and q < s:
      ans += 1
      red.remove([p, q])
      blue.remove([r, s])
      break
      
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
using ll = long long;
using namespace std;
int main() {
    int n; cin >> n;
    vector<int> a(n); repeat (i,n) cin >> a[i];
    whole(sort, a);
    ll acc = 0;
    int l = 0, r = 0;
    while (true) {
        if (r == l) {
            acc += a[l];
            ++ r;
        }
        while (r < n and a[r] <= 2*acc) {
            acc += a[r];
            ++ r;
        }
        if (r == n) break;
        ++ l;
    }
    cout << r - l << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
using namespace std;
// type alias
typedef long long LL;
typedef vector < int > VI;
typedef unordered_map < int, int > MAPII;
typedef unordered_set < int > SETI;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// minmax
#define SMAX(a,b) a = max(a,b)
#define SMIN(a,b) a = min(a,b)
// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }

/*
 
 4/23/2018
 
 11:28-12:00 give up
 
 O(N^2) algorithm doesn't work. I tried to find O(N) or O(N*lg N) algorithms. However no luck.
 What I tried...
  - Fixing one end. Trying to query number of same pattern in O(1)
  - N*(N+1)/2 - { number of duplicated ones }
  - Using palindrome?
 
 I couldn't reach solution from them... 😞
 
 21:30-22:30 Read editorials
 
 Editorials:
  - https://atcoder.jp/img/agc019/editorial.pdf
  - https://youtu.be/9OiB8ot3a0w?t=700
  -
 
 Proof uses Contraposition.
 
 */

// $ g++ -std=c++11 -Wall -O2 -D_GLIBCXX_DEBUG x.cpp && ./a.out
LL solve(string S) {
  LL C[26]={};
  FORR(c,S) C[c-'a']++;
  LL res=0;
  REP(j,26) REP(i,j) res+=C[i]*C[j];
  return res+1;
}

int main() {
  string S;
  cin >> S;
  cout << solve(S) << endl;
  return 0;
}


Measured memory_bytes: 772
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define In_The_Name_Of_Allah_The_Merciful ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define Alhamdulillah return 0;
#define loop(i,k,n) for (ll i = k ; i < n ; ++i)
#define all(v) v.begin(),v.end()
#define debug(n) cerr << "[" << #n << " = " << n << "]" << endl

void Suhaib_Sawalha (){

    string s , t;
    cin >> s >> t;
    int ans =0 ;
    for (int i = 0 ; i < s.size() ; ++i){
        ans += (s[i] != t[i]);
    }

    cout << ans;
}

int main(){
                                In_The_Name_Of_Allah_The_Merciful   /* بسم الله الرحمن الرحيم  */
#ifndef ONLINE_JUDGE
    freopen("SuhaibSawalha1.txt","r",stdin);
#endif
//int _;for(cin>>_;_;--_,cout<<endl)
        Suhaib_Sawalha();
                                         Alhamdulillah                    /* الحمد لله */
}


Measured memory_bytes: 3776
def abc082_b():
    s = sorted(input())
    t = sorted(input(), reverse=True)

    for i in range(min(len(s), len(t))):
        if ord(s[i]) < ord(t[i]):
            print("Yes")
            return 0

    if len(s) < len(t):
        for c in s:
            if c in t:
                t.remove(c)
            else:
                print("No")
                return 0
        print("Yes")
        return 0

    print("No")


abc082_b()

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

char mat[500][500];
int dp[500][500];
int h, w;

int solve(){
    int ret = -1;

    for(int i = 0; i < h; i++){
        // 長方形の左端、高さを積む
        stack<pair<int,int>> s;
        for(int j = 0; j < w; j++){
            if(s.empty()){
                s.push({j, dp[i][j]});
            }else if(s.top().second < dp[i][j]){
                s.push({j, dp[i][j]});
            }else if(s.top().second > dp[i][j]){
                int lastl;
                while(!s.empty() && s.top().second > dp[i][j]){
                    pair<int,int> out = s.top(); s.pop();
                    ret = max(ret, (j-out.first)*(out.second));
                    lastl = out.first;
                }
                s.push({lastl, dp[i][j]});
            }else if(s.top().second == dp[i][j]){
                // do nothing.
            }
        }

        while(!s.empty()){
            pair<int,int> out = s.top(); s.pop();
            ret = max(ret, (w-out.first)*out.second);
        }
    }

    return ret;
}

int main(){
    while(cin >> h >> w){
        if(w + h == 0)  break;

        // input
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                cin >> mat[i][j];
            }
        }

        // preparation
        for(int j = 0; j < w; j++){
            if(mat[0][j]=='.')  dp[0][j] = 1;
            else                dp[0][j] = 0;
        }
        for(int i = 1; i < h; i++){
            for(int j = 0; j < w; j++){
                if(mat[i][j]=='.')  dp[i][j] = dp[i-1][j]+1;
                else                dp[i][j] = 0;
            }
        }

        cout << solve() << endl;
    }

    return 0;
}


Measured memory_bytes: 4200
fun main(args: Array<String>) {
    val n = readInt()
    val a = readIntList()

    var tmp = 0.0
    for (i in 0 until n) {
        tmp += 1.0 / a[i]
    }
    println(1.0/tmp)
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

Measured memory_bytes: 37888
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cout << #x " => " << (x) << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  int n;
  cin >> n;
  string s;
  cin >> s;
  allrep (c, s) c = ((c - 'A') + n) % 26 + 'A';
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

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

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	string s;
	cin >> s;
	int pos = s.find('7');
	cout << (~pos?"Yes":"No") << '\n';
}


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

// using
using namespace std;

// typedef
typedef long long ll;

// define
#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 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)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, 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;
}

// main
int main() {
    int X, Y, Z;
    cin >> X >> Y >> Z;
    cout << ((X - Z) / (Y + Z)) << endl;
    return 0;
}


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

int main() {
  
  string a,b;
  cin >> a >> b;
  
  if(a>b) cout << ">" << endl;
  else if(a<b) cout << "<" << endl;
  else cout << "=" << endl;
  
  
}


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

int main() {
	// your code goes here
	unsigned long long int a,b,x;

    cin>>a>>b>>x;

    long long na = a/x;
    long long nb = b/x;
    long long answer = nb - na;
    
    if(a%x==0)
    	answer++;
    	
    	cout << answer << endl;
		
	
	
	return 0;
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.List

main :: IO ()
main = solve <$> readLn >>= print

solve :: Int -> Int
solve n = length . takeWhile (<=n) . sort $ xs ++ ys
  where xs = nub $ do
          let as = [3,5,7,11,13]
          a <- as
          let bs = delete a as
          b <- bs
          let cs = delete b bs
          c <- cs
          let d = a * b * c
          guard $ d <= 200
          return d
        ys = do
          a <- [5,7,11,13]
          let b = 27 * a
          guard $ b <= 200
          return b


Measured memory_bytes: 508
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric> 
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll alpha = 0;
    ll sum = 0;
    while(1)
    {
        if(n / 10 == 0)
        {
            sum += n - alpha;
            break;
        }
        ll back = n % 10 - alpha;
        if(back != 9)
        {
            alpha = 1;
        }
        sum += 9;
        n /= 10;
    }
    cout << sum << endl;
	return 0;
}



Measured memory_bytes: 256
a = list(map(int,input().split()))
order = [[0,1,2],[0,2,1],[1,0,2],[1,2,0],[2,0,1],[2,1,0]]
ans = 10000000
for i in range(len(order)):
    cost = abs(a[order[i][1]] - a[order[i][0]]) + abs(a[order[i][2]] - a[order[i][1]])
    if(ans > cost):
        ans = cost
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < int(n); ++ (i))
using namespace std;
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

int main() {
    // input
    int h, w, d; scanf("%d%d%d", &h, &w, &d);
    vector<int> y(h * w);
    vector<int> x(h * w);
    REP (j, h) REP (i, w) {
        int a; scanf("%d", &a);
        -- a;
        y[a] = j;
        x[a] = i;
    }

    // solve
    vector<vector<int> > acc = vectors(d, h * w / d + 1, int());
    REP (i, h * w - d) {
        acc[(i + d) % d][(i + d) / d] = acc[i % d][i / d]
            + abs(y[i + d] - y[i])
            + abs(x[i + d] - x[i]);
    }
    auto solve = [&](int l, int r) {
        return acc[r % d][r / d] - acc[l % d][l / d];
    };

    // output
    int q; scanf("%d", &q);
    while (q --) {
        int l, r; scanf("%d%d", &l, &r);
        -- l;
        -- r;
        printf("%d\n", solve(l, r));
    }
    return 0;
}


Measured memory_bytes: 6016
using System;
using System.Linq;

namespace AtCoderDwango
{
	class Program
	{
		static void Main(string[] args)
		{
			var number = int.Parse(Console.ReadLine());
			var songs = new Song[number];
			for (var i = 0; i < number; i++)
			{
				var tmp = Console.ReadLine().Split(' ');
				songs[i] = new Song(tmp[0], int.Parse(tmp[1]));
			}
			var title = Console.ReadLine();

			var flag = false;
			var time = 0;
			for (var i = 0; i < number; i++)
			{
				if (flag)
				{
					time += songs[i].Time;
				}

				if (songs[i].Title == title)
				{
					flag = true;
				}
			}

			Console.WriteLine(time);
		}

		private class Song
		{
			public string Title { get; }

			public int Time { get; }

			public Song(string title, int time)
			{
				this.Title = title;
				this.Time = time;
			}
		}
	}
}


Measured memory_bytes: 13140
N = int(input())
D = [int(d) for d in input().split()]
length = dict()
maxD = max(D)
mod = 998244353
for i in range(maxD + 1):
    length[i] = 0
for d in D:
    length[d] += 1
if D[0] != 0 or length[0] > 1:
    print(0)
else:
    ans = 1
    for i in range(1, maxD + 1):
        if length[i] == 0:
            print(0)
            break
        else:
            ans *= (length[i-1] ** length[i]) % mod
            ans %= mod
    else:
        print(ans)



Measured memory_bytes: 20704
#include <bits/stdc++.h>
using namespace std;
int main() {
	cin.tie(0); cin.sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	int ret;
	if (a >= 13) ret = b;
	else if (a >= 6) ret = b / 2;
	else ret = 0;
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7/*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
int main(){
    int N, W;
    cin >> N >> W;
    vector<vector<ll>> pro(N, vector<ll>(2)), dp(N + 1, vector<ll>(W + 1));
    for(int i = 0; i < N; i++) cin >> pro[i][1] >> pro[i][2];
    for(int i = 0; i < N; i++){
        int w = pro[i][1], v = pro[i][2];
        for(int j = 1; j <= W; j++){
            if(j < w) dp[i + 1][j] = dp[i][j];
            else{
                dp[i + 1][j] = max(dp[i][j], dp[i][j - w] + v);
            }
        }
    }
    cout << dp[N][W];
}

Measured memory_bytes: 80256
s = input()

if(len(s) == 1):
    print(0)
    exit()

ans = 0

tmp = s[0]

for i in s[1:]:
    if(tmp == i):
        ans += 1
        if(i == "0"): tmp = "1"
        else: tmp = "0"
    else:
        tmp = i

print(ans)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#include<cmath>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) cout << (x) << endl;
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
 
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};

ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}




const int mod = 1e9 + 7;


int main(void){
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    char c;
    cin >> c;
    char newc = c + 1;
    print(newc);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
#include <math.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

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

  int a = (s[0] - '0') * 10 + s[1] - '0';
  int b = (s[2] - '0') * 10 + s[3] - '0';

  if (a == 0 || a > 12) {
    if (b == 0 || b > 12) cout << "NA" << endl;
    else if (0 < b && b <= 12) cout << "YYMM" << endl;
  } else if (0 < a && a <= 12) {
    if (b == 0 || b > 12) cout << "MMYY" << endl;
    else if (0 < b && b <= 12) cout << "AMBIGUOUS" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
from collections import deque
k = int(input())
que = deque()
for i in range(k+9):
    if i < 9:
        que.append(i+1)
    else:
        x = que.popleft()
        if x % 10 != 0:
            que.append(10*x+(x%10) -1)
        que.append(10*x+(x%10))
        if x % 10 != 9:
             que.append(10*x+(x%10) +1)
            
print(x)


Measured memory_bytes: 40816
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include<limits>
#include<iomanip>

using namespace std;

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

const long double pi = 3.141592653589793;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repi(i, j, n) for(int i = j;i < n;i++)
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define F first
#define S second

// #define COMMENT

/*

const int NN = 200090;
ll fact[NN];
ll finv[NN];
ll inv[NN];

void inverse_modulao() {
  fact[0] = fact[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;

  for(int i = 2;i < NN;i++) {
    fact[i] = fact[i-1]*i%mod;
    inv[i] = mod-mod/i*inv[mod%i]%mod;
    finv[i] = finv[i-1]*inv[i]%mod;
  }
}

ll nCr(int n, int r) {
  return fact[n]*finv[r]%mod*finv[n-r]%mod;
}

*/

string s;

int main() {

//  freopen("input.in","r",stdin);
//  freopen("output.out","w",stdout);
  cin>>s;
  if(s=="ABC") cout<<"ARC";
  else cout<<"ABC";


  return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> v(N);
  for(int i=0;i<N;i++)
    cin >> v[i];
  vector<int> max_from_right(N, 1);
  for(int i=N - 2;i>=0;i--) {
    if(v[i] >= v[i + 1])
      	max_from_right[i] = max_from_right[i + 1] + 1;
  }
  int ans = INT_MIN;
  for(int element: max_from_right)
        ans = max(ans, element);
  cout << ans - 1;    
  return 0;
}

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

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

    if (s[k-1] == 'A') s[k-1] = 'a';
    else if (s[k-1] == 'B') s[k-1] = 'b';
    else if (s[k-1] == 'C') s[k-1] = 'c';
    cout << s << endl;

}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e9;
#define sz              3000005
#define Fast            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

string s,p;

int arr[sz];

int solve(int k){

    int res=-1;
    int cnt=1;
    int rem=7;

    while(arr[rem]==0 && cnt<10000001){
        if(rem%k==0)return cnt;
        rem=rem*10+7;
        rem=rem%k;
        cnt++;
    }
    return -1;
}


int main(){
    Fast;
    int k;

    cin>>k;
    cout<<solve(k)<<endl;


    return 0;
}



Measured memory_bytes: 3636
#演習2－10

n = int(input())
mat = [[0 for _ in range(n)] for _ in range(n)]

for i in range(n):
    cmd = input().split();
    m = int(cmd[1])
    for j in range(m):
        mat[i][int(cmd[2+j])-1] = 1

for i in mat:
    print(*i)





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

vector<long> calc(long x) {
	vector<long> dat;
	for (int i = 1; i * i <= x; i++) {
		if (x % i == 0) dat.push_back(i);
	}
	return dat;
}

int main() {
	long n, m;
	cin >> n >> m;
	vector<long> dat = calc(m);
	// for (auto e : dat) {
	// 	cout << e << endl;
	// }
	long ans = 1;
	for (int i = 0; i < dat.size(); i++) {
		if (dat[i] <= m / n) {
			ans = max(ans, dat[i]);
		}
		if (dat[i] >= n) {
			ans = max(ans, m / dat[i]);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#define llint long long

using namespace std;

llint n;
llint a[200005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	llint ans = 0;
	for(int i = 1; i <= n; i++){
		if(a[i] == ans+1) ans++;
	}
	if(ans == 0){
		cout << -1 << endl;
		return 0;
	}
	cout << n-ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define ld long double
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

const int MAX=1e5+5;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    //int n; cin >> n;

    vb isprime(1e5+5,true);
    isprime[0]=isprime[1]=false;
    FOR(i,2,1e5+5){
        if(isprime[i]){
            for(int j=2*i; j<1e5+5; j+=i){
                isprime[j]=false;
            }
        }
    }
    
    vint a(MAX,0);
    rep(i,MAX){
        if(isprime[i]==true && isprime[(i+1)/2]==true){
            a[i]=1;
        }
    }
    //rep(i,100) cout<<a[i]<<' ';
    vint s(MAX+1,0);
    rep(i,MAX){
        s[i+1]=s[i]+a[i];
    }

    int q; cin >> q;
    rep(i,q){
        int l,r; cin >> l >> r;
        cout<<s[r+1]-s[l]<<endl;
    }

}

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

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

fn main() {
    input! {
    a:String,
    }
    let a=a.chars().collect_vec();
    let mut v:Vec<char>=Vec::new();
    for i in 0..a.len() {
        if a[i]=='0' {v.push('0')}
        if a[i]=='1' {v.push('1')}
        if a[i]=='B' {v.pop();}
    }
    let v:String=v.iter().collect();
    println!("{}",v)
}

Measured memory_bytes: 2132
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//CODE


void solve(void)
{
  int X,Y,Z,K;
  cin>>X>>Y>>Z>>K;
  vector<int>A(X),B(Y),C(Z);
  for (int i = 0; i < X; i++)
  {
    cin>>A[i];
  }
  sort(ALL(A),greater<int>());
  for (int i = 0; i < Y; i++)
  {
    cin>>B[i];
  }
  sort(ALL(B),greater<int>());
    for (int i = 0; i < Z; i++)
  {
    cin>>C[i];
  }
  sort(ALL(C),greater<int>());
  vector<int> vec;
  for (int i = 0; i < X; i++)
  {
    for (int j = 0; j < Y; j++)
    {
      for (int k = 0; k < Z; k++)
      {
        if((i+1)*(j+1)*(k+1) <= K) vec.push_back(A[i]+B[j]+C[k]);
        else break;
      }
      
    }
    
  }
  sort(ALL(vec),greater<int>());
  for (int i = 0; i < K; i++)
  {
    cout<<vec[i]<<endl;
  }
  
  
  

  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


Measured memory_bytes: 1404
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  int N;
  cin>>N;
  vector<int64_t>X(N),Y(N),h(N);
  for(int i=0;i<N;i++){
    cin>>X[i]>>Y[i]>>h[i];
  }
  for(int x=0;x<=100;x++){
    for(int y=0;y<=100;y++){
      int64_t H=0;
      for(int i=0;i<N;i++){
        if(h[i]==0){continue;}
        H=h[i]+abs(x-X[i])+abs(y-Y[i]);
        break;
      }
      bool ok=true;
      for(int i=0;i<N;i++){
        if(max(H-abs(x-X[i])-abs(y-Y[i]),(int64_t)0)!=h[i]){
          ok=false;
        }
      }
      if(ok){cout<<x<<" "<<y<<" "<<H<<endl;return 0;}
    }
  }
  return 0;
}

Measured memory_bytes: 3620
function main()
    n = parse(Int, readline())
    s = readline()
    count = 0
    counts = [Int[], Int[], Int[]] #RGB
    x,y,z = 0,0,0
    hoge = 0
    for i in 1:n
        aa = min(i-1, n-i)
        @simd for j in 1:aa
            if s[i] != s[i-j] != s[i+j] != s[i]
                # println(s[i], s[i-j], s[i+j])
                hoge += 1
            end
        end
        c = s[i]
        if c == 'R'
            x += 1
        elseif c == 'G'
            y += 1
        else
            z += 1
        end
    end
    println(x*y*z-hoge)
end

main()

Measured memory_bytes: 167552
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a,s;
	cin>>s;
	int z=s.size(),c=0;
	for(int i=0;i<z;i++){
		if(s[i]=='0'||s[i]=='1'){
			a[c]=s[i];
			c++;
		}
		else if(s[i]=='B'&&c!=0){
			c--;
		}
	}
	for(int k=0;k<c;k++){
		cout<<a[k];
	}
	cout<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,ans=0,cnt=0;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++)cin >> a[i];
  for(int i=0;i<n-1;i++){
    if(a[i]>=a[i+1])cnt++;
    else{
      ans=max(ans,cnt);
      cnt=0;
    }
  }  
  ans=max(ans,cnt);
  cout << ans << endl;
}

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

int main() {
    vector<int> A(5);
    for(int i=0; i<5; i++){
        cin >> A.at(i);
        if(A.at(i)!=i+1){
            cout << i+1 << endl;
        }
    }

   
}


Measured memory_bytes: 3540
#include <iostream>
#define INF 1e+9
using namespace std;

int n,w[1000],c[1000],imos[1001] = {};
bool dp1[1000][1000];
int dp2[1000][1000];

int dfs(int l,int r){
	if(dp2[l][r] >= 0) return dp2[l][r];
	int mi = INF;
	for(int i = l;i < r;i++) mi = min(mi,dfs(l,i) + dfs(i + 1,r));
	return dp2[l][r] = mi;
}

int main(){
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> c[i] >> w[i];
		imos[i + 1] = imos[i] + w[i];
		dp1[i][i] = true;
		for(int j = 0;j < n;j++) dp2[i][j] = -1;
		dp2[i][i] = 1;
	}
	for(int i = 1;i < n;i++){
		for(int j = 0;j < n - i;j++){
			if((c[j + i] >= imos[j + i] - imos[j] && dp1[j][j + i - 1]) || (c[j] >= imos[j + i + 1] - imos[j + 1] && dp1[j + 1][j + i])) dp1[j][j + i] = true;
			else dp1[j][i + j] = false;
			if(dp1[j][i + j]) dp2[j][i + j] = 1;
		}
	}
	cout << dfs(0,n - 1) << endl;
	return 0;
}

Measured memory_bytes: 8056
#include<bits/stdc++.h>
//iostreamじゃなくてbitsでのincludeだと"¥n"が改行されないかも？
//正直しんどい。bitsの場合はendlを使いましょうねって話。
using namespace std;
int main(){
  int N = 0;
  cin >> N;
  int tmp;
  int max = 0;
  for(int i = 0; i < N; i++){
    cin >> tmp;
    if(tmp > max){
      max = tmp;
    }
    if(tmp < max && max-1 > tmp){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
    return 0;
}

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

typedef long long int ll;
typedef long double ld;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define mod 1000000007
#define lp(start,end) for(ll i=start;i<=end;i++) 
#define deb1(a) cout<<#a<<" = "<<(a)<<endl;
#define deb2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define deb3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;


ll modu(ll a, ll b)
{
	ll ans =1;
	while(b>0)
	{
		if(b&1)
		ans = (ans*a)%mod;
		b/=2;
		a = (a*a)%mod;
	}
	return ans;
}
ll n;
ld p[3001];
ld dp[3007][3007];

ld fun(ll x , ll y)
{
	if(dp[x][y]!=-1)
		return dp[x][y];
	if(x>0)
	{
		if(y==n)
		{
			dp[x][y] = 1;
		}
		else
			dp[x][y] = fun(x-1,y+1)*(1-p[y]) + fun(x,y+1)*p[y];
	}
	else
	{
		if(y==n)
		{
			dp[x][y] = p[y];
		}
		else
			dp[x][y] = fun(x,y+1)*p[y];
	}
	return dp[x][y];
//	if(x==1 && y==0)

}
int main()
{
	fastio
	cin >> n;
	for(ll i=1;i<=n;i++)
		cin >> p[i] ;

	for(ll i=0;i<=n;i++)
		for(ll j=0;j<=n;j++)
			dp[i][j]=-1;
	//ld ans=0;
	ld ans = fun(n/2 , 1);
	cout <<fixed << setprecision(10) << ans << endl;
	return 0;	
}


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

using namespace std;
const int N = 3e5 + 3, M = 2019;
int main() {
#ifndef ONLINE_JUDGE
//	freopen("input.in", "r", stdin);
#endif
	int l, r;
	scanf("%d %d", &l, &r);
	if (r - l - 1 > M) {
		puts("0");
		return 0;
	}
	long long res = 2e18;
	for (int i = l; i <= r; ++i) {
		for (int j = i + 1; j <= r; ++j) {
			res = min(res, (1LL * i * j) % M);
		}
	}
	printf("%lld\n", res);
	return 0;
}

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

int main() {
  ll n;
  cin>>n;
  string s;
  cin>>s;
  if(n<3){
    cout<<0<<endl;
    return 0;
  }
  int vec[n][3]={0};
  vec[0][0]=0;
  vec[0][1]=0;
  vec[0][2]=0;
  if(s[0]=='R'){
    vec[0][0]++;
  }
  if(s[0]=='G'){
    vec[1][0]++;
  }
  if(s[0]=='B'){
    vec[2][0]++;
  }
  for(int i=1;i<n;i++){
    if(s[i]=='R'){
      vec[i][0]=vec[i-1][0]+1;
      vec[i][1]=vec[i-1][1];
      vec[i][2]=vec[i-1][2];
    }
    if(s[i]=='G'){
      vec[i][0]=vec[i-1][0];
      vec[i][1]=vec[i-1][1]+1;
      vec[i][2]=vec[i-1][2];
    }
    if(s[i]=='B'){
      vec[i][0]=vec[i-1][0];
      vec[i][1]=vec[i-1][1];
      vec[i][2]=vec[i-1][2]+1;
    }
  }
    
  int k;
  ll ans=0;
  for(int i=0;i<=n-2;i++){
    for(int j=i+1;j<=n-1;j++){
      if(s[i]==s[j]){
        continue;
      }
      if(s[i]=='R'&&s[j]=='G'){
        ans+=vec[n-1][2]-vec[j][2];
        k=j*2-i;
        if(k<n){
          if(s[k]=='B'){
            ans--;
          }
        }
      }
      if(s[i]=='R'&&s[j]=='B'){
        ans+=vec[n-1][1]-vec[j][1];
        k=j*2-i;
        if(k<n){
          if(s[k]=='G'){
            ans--;
          }
        }
      }
      if(s[i]=='G'&&s[j]=='R'){
        ans+=vec[n-1][2]-vec[j][2];
        k=j*2-i;
        if(k<n){
          if(s[k]=='B'){
            ans--;
          }
        }
      }
      if(s[i]=='G'&&s[j]=='B'){
        ans+=vec[n-1][0]-vec[j][0];
        k=j*2-i;
        if(k<n){
          if(s[k]=='R'){
            ans--;
          }
        }
      }
      if(s[i]=='B'&&s[j]=='R'){
        ans+=vec[n-1][1]-vec[j][1];
        k=j*2-i;
        if(k<n){
          if(s[k]=='G'){
            ans--;
          }
        }
      }
      if(s[i]=='B'&&s[j]=='G'){
        ans+=vec[n-1][0]-vec[j][0];
        k=j*2-i;
        if(k<n){
          if(s[k]=='R'){
            ans--;
          }
        }
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3648
#include<iostream>
#include<string>
#include<vector>
#include<tuple>
#include<set>
#include<map>
#include<algorithm>
using namespace std;

struct Record {
  int tid, pid, time;
  bool correct;
};

struct Team {
  Team() {
    penalty = 0;
  }
  set<int> solved;
  map<int, int> WA;
  int penalty;
};

// Solved Problems, Penalty, Team ID
typedef tuple<int, int, int> Score;

int main() {
  int T, P, R;
  while (cin >> T >> P >> R && T) {
    vector<Record> records(R);
    for (int i = 0; i < R; i++) {
      int tid, pid, stime;
      string message;
      cin >> tid >> pid >> stime >> message;
      records[i].pid = --pid;
      records[i].tid = --tid;
      records[i].time = stime;
      records[i].correct = (message == "CORRECT");
    }

    vector<Team> teams(T);
    for (Record r : records) {
      if (teams[r.tid].solved.find(r.pid) != teams[r.tid].solved.end()) {
        continue;
      } else if (r.correct) {
        teams[r.tid].solved.insert(r.pid);
        teams[r.tid].penalty +=
          teams[r.tid].WA[r.pid] * 1200 + r.time;
      } else {
        teams[r.tid].WA[r.pid]++;
      }
    }

    vector<Score> team_result(T);
    for (int i = 0; i < T; i++) {
      get<0>(team_result[i]) = -teams[i].solved.size();
      get<1>(team_result[i]) = teams[i].penalty;
      get<2>(team_result[i]) = i;
    }

    sort(team_result.begin(), team_result.end());

    for (Score s : team_result) {
      cout << get<2>(s)+1 << " " << -get<0>(s) << " " << get<1>(s) << endl;
    }
  }
}

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

#define st first
#define nd second
#define ll long long
#define ld long double
#define pb push_back
#define emp emplace_back
#define pii pair<int, int>
#define usg unsigned
#define sg signed
#define mp make_pair

using namespace std;

void setIO(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

const ld PI = 4*atan((ld)1);
const int INF = 1e9+7;

int main(){
	setIO();
	int x, y, z;
	cin>>x>>y>>z;
	cout<<z<<" "<<x<<" "<<y<<endl;
}

Measured memory_bytes: 3636
<?php
    /*
        Problem URL : http://arc058.contest.atcoder.jp/tasks/arc058_a
 
        Score  :
        Result :
        Time   : ms
        Memory : KB
     */
 
    ini_set('error_reporting', E_ALL & ~E_NOTICE);
    // define('DEBUG', true);
    define('DEBUG', false);
 
    // N“ú‚ÅKŸ
    fscanf(STDIN, "%d %d", $N, $K);
    $D = explode(" ", trim(fgets(STDIN)));

    for ($i = $N; $i < 100000; $i++) {
        $str = str_split($i);
        // var_dump($str);
        $len = count($str);
        $bool = true;
        for ($j = 0; $j < $len; $j++) {
            if (in_array($str[$j], $D) === true) {
                $bool = false;
            }
        }
        if ($bool === true) {
            echo $i . PHP_EOL;
            exit;
        }
    }



Measured memory_bytes: 3832
N = int(input())
li = list(map(int,input().split()))
count = -1
han = True
while han:
    count += 1
    for i in range(N):
        if li[i] % 2 == 1:
            han = False
            break
        else:
            li[i] = li[i] / 2 
print(count)


Measured memory_bytes: 2940
#coding=UTF-8

N=int(input())
a=[]
b=[]
c=[]

for idx in range(0,N-1,1):
    mozir=input()
    hyo=mozir.split(' ')
    a.append(int(hyo[0])-1)
    b.append(int(hyo[1])-1)
    c.append(int(hyo[2]))

mozir=input()
hyo=mozir.split(' ')
Q=int(hyo[0])
K=int(hyo[1])-1

#process
#first half
keiro=[]
for idx in range(0,N,1):
    keiro.append([])
    
for idx in range(0,N-1,1):
    keiro[a[idx]].append((b[idx],c[idx]))
    keiro[b[idx]].append((a[idx],c[idx]))

fare=[None]*N

fare[K]=0
shirabe=[(K,0)]
while shirabe :
    tugi_shirabe=[]
    for (node,tmpcost) in shirabe:
        for (kouho,c) in keiro[node]:
            if fare[kouho]==None:
                fare[kouho]=tmpcost+c
                tugi_shirabe.append((kouho,tmpcost+c))
                
    shirabe=tugi_shirabe

#print(fare)
#exit(0)
for idx in range(0,Q,1):
    mozir=input()
    hyo=mozir.split(' ')
    x=int(hyo[0])-1
    y=int(hyo[1])-1
    print(fare[x]+fare[y])
    


Measured memory_bytes: 52000
#define P(x) cout << #x " = " << x << endl
#define PP(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define PPP(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl

#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>

using namespace std;
int na = 0;
int ba = 0;
int bn = 0;
int n;

int main()
{
    cin >> n;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        string si;
        cin >> si;
        if (si[0] == 'B' && si[si.size() - 1] == 'A') {
            ba++;
        } else if (si[0] == 'B') {
            bn++;
        } else if (si[si.size() - 1] == 'A') {
            na++;
        }
        if (na >= 2 && bn >= 2) {
            ba++;
            na--;
            bn--;
        }
        string::size_type pos = 0;
        while((pos = si.find("AB", pos)) != string::npos) {
            ans++;
            pos += 2;
        }
    }
    // PPP(na, ba, bn);
    int add = ba + 1;
    if (na == 0) {
        add--;
    }
    if (bn == 0) {
        add--;
    }
    add = max(0, add);
    cout << ans + add<< endl;
}

Measured memory_bytes: 256
N = int(input())
L = [list(map(int,input().split())) for i in range(N)]
NOW = [0,0,0]
NEXT = [None,None,None]

for i in range(N) :
    NEXT[0] = max(NOW[1],NOW[2]) + L[i][0]
    NEXT[1] = max(NOW[2],NOW[0]) + L[i][1]
    NEXT[2] = max(NOW[0],NOW[1]) + L[i][2]
    
    NOW = NEXT.copy()
print(max(NOW))


Measured memory_bytes: 30580
package main

import (
	"fmt"
)

func sum(a []int) int {
	s := 0
	for _,e := range a {
		s += e
	}
	return s
}

func abs(a int) int {
	if a<0 {
		return -a
	}
	return a
}

func main() {
	var n int
	fmt.Scan(&n)

	w := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&w[i])
	}

	s1,s2 := 0,sum(w)
	ans := s2 - s1
	for i := 0; i < n; i++ {
		s1 += w[i]
		s2 -= w[i]
		if ans > abs(s2-s1) {
			ans = abs(s2-s1)
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>

#define MAX_N 200'000

using namespace std;

int main() {
  int N;
  cin >> N;
  int x = MAX_N + 1;
  int cnt = 0;
  for (int i = 0; i < N; ++i) {
    int p;
    cin >> p;
    if (p < x) {
      ++cnt;
      x = p;
    }
  }
  printf("%d\n", cnt);
}

Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
const int N=4005,M=1e9+7;
using namespace std;
int sum[N],n,m,k,f[N];
int main(){
	scanf("%d%d%d",&n,&m,&k);
	k--;
	int ans=0;
	for (int i=0;i<=m;i++)sum[i]=1;
	for (int i=1;i<=(n+m)/k;i++){
		for (int j=1;j<=m;j++){
			if (j>k)f[j]=(sum[j-1]-sum[j-k-1]+M)%M;
			else f[j]=sum[j-1];
			if (j%k==m%k&&i*k<=n+j-1&&(n+j-1)%k==0)
			(ans+=f[j])%=M;
		}
		for (int j=1;j<=m;j++){
			(f[j]+=f[j-1])%=M;
			(sum[j]+=f[j])%=M;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ll long long
const int MX=200010;
int N, M, k, x;
int arr[MX];
int C[4][4];
int a[4];
int D(int a, int b, int c)
{
  ///  set<int> st;
    vector<int> v;
    v.pb(a);
    v.pb(b);
    v.pb(c);
    for(int i=0;i<3;i++)
    {
        int d=-1;
        for(int j=0;j<3;j++)
        {
            if(d == -1) d=C[i][j]-v[j];
            if(d != C[i][j] - v[j]) return 0;
        }
    }
    return 1;
}
int main()
{
    for(int i=0;i<3;i++) for(int j=0;j<3;j++) cin>>C[i][j];
    for(int i=-100;i<=100;i++)
    {
        for(int j=-100;j<=000;j++)
        {
            for(int k=-100;k<=100;k++)
            {
                if(D(i, j, k))
                {
                    cout<<"Yes\n";
                    return 0;
                }
            }
        }
    }
    cout<<"No\n";
}


Measured memory_bytes: 256