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

int main(){
    int n;
    cin >> n;
    int num[n];
    for(int i=0; i<n; i++){
        cin >> num[i];
    }
    for(int i=n-1; i>=0; i--){
        if(i>0){
            cout << num[i] << " ";
        }
        else {
            cout << num[i];
        }
    }
    cout << endl;
}



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

int main(){
	int a, b, k;
	cin >> a >> b >> k;
	int ans[100], i, j = 0;
	for(i = 1; i <= 100; i++){
		if((a % i == 0) && (b % i == 0)){
			ans[j++] = i;
		}
	}
	cout << ans[j - k] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define compress(v) sort(all(v)), v.erase(unique(all(v)), v.end())
using namespace std;

typedef long long ll;

struct Seg{
    int tree[1 << 19], tmp[1 << 19];
    Seg(){
        memset(tree, 0x3f, sizeof tree);
        memset(tmp, 0x3f, sizeof tmp);
    }
    void push(int node, int s, int e){
        if(tmp[node] >= 1e9) return;
        tree[node] = min(tree[node], tmp[node]);
        if(s != e){
            tmp[node << 1] = min(tmp[node << 1], tmp[node]);
            tmp[node << 1 | 1] = min(tmp[node << 1 | 1], tmp[node]);
        }
        tmp[node] = 1e9+7;
    }
    void update(int node, int s, int e, int l, int r, int v){
        push(node, s, e);
        if(r < s || e < l) return;
        if(l <= s && e <= r){
            tmp[node] = min(tmp[node], v); push(node, s, e); return;
        }
        int m = s + e >> 1;
        update(node << 1, s, m, l, r, v);
        update(node << 1 | 1, m+1, e, l, r, v);
        tree[node] = min(tree[node << 1], tree[node << 1 | 1]);
    }
    int query(int node, int s, int e, int l, int r){
        push(node, s, e);
        if(r < s || e < l) return 1e9+7;
        if(l <= s && e <= r) return tree[node];
        int m = s + e >> 1;
        return min(query(node << 1, s, m, l, r), query(node << 1 | 1, m+1, e, l, r));
    }
    void update(int l, int r, int v){ update(1, 1, 202020, l, r, v); }
    int query(int l, int r){ return query(1, 1, 202020, l, r); }
} seg_i, seg_j;

ll n, q, ans;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    cin >> n >> q; ans = (n-2) * (n-2);
    seg_i.update(1, n, n); seg_j.update(1, n, n);
    seg_i.update(n, n, 1); seg_j.update(n, n, 1);
    while(q--){
        int op, a; cin >> op >> a;
        if(op == 1){
            int t = seg_i.query(a, a);
            ans -= t-2;
            seg_j.update(1, t, a);
        }
        else{
            int t = seg_j.query(a, a);
            ans -= t-2;
            seg_i.update(1, t, a);
        }
    }
    cout << ans;
}

Measured memory_bytes: 11848
#include <bits/stdc++.h>
#define FOR(i,a,b) for(register int i=(a);i<(b);++i)
#define ROF(i,a,b) for(register int i=(a);i>=(b);--i)
#define pi pair<int,int>
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef double db;
const int maxn = 5005;
const int maxm = 100;
const int inf = 2147483647;
typedef long long ll;
const double eps = 1e-9;
const long long INF = 9223372036854775807ll;
ll qpow(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c;b>>=1;}return ans;}


int main(){
	ll a,b;
	scanf("%lld%lld",&a,&b);
	ll c=__gcd(a,b);
	int cnt=1;
	for(register ll i=2;i*i<=c;++i){
		if(c%i==0){
			cnt++;
			while(c%i==0)c/=i;
		} 
	}
	if(c>1)cnt++;
	printf("%d\n",cnt);
}


Measured memory_bytes: 3824
import java.util.Arrays;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k, t;
		int[] numberOfEach;
		k = sc.nextInt();
		t = sc.nextInt();
		numberOfEach = new int [t];
		for (int i=0; i<t ;++i) {
			numberOfEach[i] = sc.nextInt();
		}
		Arrays.sort(numberOfEach);
			int type = t-2;
			int max = t-1;
			eatThroughDay(max, type, numberOfEach);
			System.out.println(numberOfEach[t-1]);
	}
	
	private static int eatUp(int type, int[] numberOfEach, int max) {
		if (type < 0) {
			return 1;
		}
		if (numberOfEach[max] == 0){
			return 0;
		}
		if (numberOfEach[type] == 0) {
			return 1;
		}
		--numberOfEach[max];
		--numberOfEach[type];
		return -1;
	}
	
	private static void eatThroughDay(int max, int type, int[] numberOfEach) {
		int result = -1;
		while ((result = eatUp(type, numberOfEach, max) )== -1) {
			--type;
			if (type < 0) {
				++type;
			}
			if (type == max) {
				return;
			}
		}
		if (result==0) {
			--max;
			if (max < 0) {
				return;
			}
			eatThroughDay(max, type, numberOfEach);
		}
		if (result==1) {
			--type;
			boolean isAllZero = true;
			if (type < 0) {
				++type;
				for (int i=type; i<numberOfEach.length-1; ++i){
					if (i < 0) {
						--numberOfEach[max];
						return;
					}
					if (numberOfEach[i] != 0) {
						isAllZero = false;
						type = i;
						break;
					}
				}
				if (isAllZero) {
					--numberOfEach[max];
					return;
				}
			}
			if (type == max) {
				return;
			}
			eatThroughDay(max, type, numberOfEach);
		}
	}

}


Measured memory_bytes: 16188
#include <stdio.h>
#include <iostream>
#include <string>

int main(void) {
	int a = 0;
	int b = 0;
	std::cin >> a >> b;

	char* str = "";
	if (a > b) {
		str = ">\0";
	}
	else if (a < b) {
		str = "<\0";
	}
	else {
		str = "==\0";
	}

	printf("a %s b\n", str);
	return 0;
}


Measured memory_bytes: 3200
#include <stdio.h>
 
int main()
{
  int nn, mm;
  scanf("%d %d", &nn, &mm);
  int aa[nn];
  for(int ii = 0;ii < nn;ii++)
  {
    scanf("%d", &aa[ii]);
  }
  int sum = 0;
  for(int ii = 0;ii < nn;ii++)
  {
    sum += aa[ii];
  }
  int max, old_max = 1001;
  for(int ii = 1;ii <= mm;ii++)
  {
    max = 0;
    for(int jj = 0;jj < nn;jj++)
    {
      if(aa[jj] > max && aa[jj] < old_max)
      {
        max = aa[jj];
      }
    }
    old_max = max;
  }
  float hikaku = sum / (4.0 * mm);
  if(max >= hikaku)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

int main() {
	int N;
	cin >> N;
	
	bool ans = false;
	REP(i, N) {
		string s;
		cin >> s;
		ans |= s == "Y";
	}
	puts(ans ? "Four" : "Three");
	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int a,b;
    int d,r;
    double f;
    
    scanf("%d %d",&a,&b);
    d = a / b;
    r = a % b;
    f = (double)a / (double)b;
    
    printf("%d %d %f\n",d,r,f);
    return 0;
}


Measured memory_bytes: 2104
list = [int(i) for i in input().split(" ")]
n = list[0]
m = list[1]
c = list[2]
b_list = [int(i) for i in input().split(" ")]
count = 0
for i in range(n):
    a_list = [int(i) for i in input().split(" ")]
    total = 0
    for a,b in zip(a_list,b_list):
        total += a*b
    total += c
    if total > 0:
        count += 1
print(count)


Measured memory_bytes: 3064
def main():
    import sys
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines
    sys.setrecursionlimit(10 ** 7)

    from copy import deepcopy

    d = int(readline())
    c = list(map(int, readline().split()))
    s = [list(map(int, readline().split())) for _ in range(d)]
    memo = [0] * 26
    check = 0
    for i in range(d):
        ans = 0
        tmp = deepcopy(check)
        check = -float('inf')
        for idx, ss in enumerate(s[i]):
            v = tmp + ss
            for j, (m, cc) in enumerate(zip(memo, c)):
                if j == idx:
                    continue
                v -= cc * (i + 1 - m)
            if check < v:
                ans = idx + 1
                check = v
        print(ans)
        memo[ans - 1] = i + 1


if __name__ == '__main__':
    main()


Measured memory_bytes: 9580
N,L=map(int,input().split())
S=[input() for n in range(N)]
S=sorted(S)
"""for num in range(L):
    ans1=S[num]
    for num2 in range(L):

        ans2=S[num2]
        for i in range(L):
            if ans1[i]>ans2[i]:
                break
            elif ans1[i]==ans2[i]:
                continue
            else :
                S[num],S[num2]=S[num2],S[num]
                break
"""
print("".join(S))

Measured memory_bytes: 3060
#include <cstdio>

typedef long long ll;

int sum(ll x) {
    int result = 0;
    while (x) {
        result += x % 10;
        x /= 10;
    }
    return result;
}

int main(void) {
    ll x;
    scanf("%lld", &x);

    int best = sum(x);
    for (ll y = 10; y <= x; y *= 10) {
        if (x / y % 10 > 0) {
            int curr = sum((x / y - 1) * y + y - 1);
            if (curr > best) best = curr;
        }
    }

    printf("%d\n", best);

    return 0;
}


Measured memory_bytes: 128
a,b,c,d = map(int,input().split())
if ((b<=a)and(b<=c))or((b>=a)and(b>=c)):
    if abs(a-c)<=d:
        print('Yes')
    else:
        print('No')
else:
    if (abs(a-b)<=d)and(abs(c-b)<=d):
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    int gesum=0,zyosum=0;
    int tamesi,ans;
    vector<int> ge(105);
    vector<int> zyo(105);

    cin>>N;

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

    for(int i=0;i<N;i++){
        cin>>ge[i];
        gesum=gesum+ge[i];
    }
    zyosum=zyosum+ge[N-1];

    tamesi=zyosum;
    if(zyosum>gesum){
        ans= zyosum;
    }else{
        ans=gesum;
    }


   for(int i=N-1;i>0;i--){
        tamesi=tamesi-zyo[i]+ge[i-1];
        if(ans<tamesi)ans=tamesi;

    }

    cout<<ans<<endl;

}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	int count[11] = { 0 };
	count[a]++;
	count[b]++;
	count[c]++;
	if (count[5] == 2 && count[7] == 1) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define puba push_back
#define pufro push_front
#define poba pop_back
#define pofro pop_front

using namespace std;
typedef long long ll;
const ll M=1e9+7;
const double PI=acos(-1);
const double EPS=1e-12;
const ll arrSize=2000005;
ll arr[arrSize];
ll grid[505][505];
int main(){
	int tc=1,kasus=1;
	//scanf("%d",&tc);
	while(tc--){
		int r,c;
		scanf("%d %d",&r,&c);
		
		bool carry=false;
		vector<pair<pair<ll,ll>,pair<ll,ll> > >vec;
		pair<int,int>prev;
		for(int i=0;i<r;i++) for(int j=0;j<c;j++) scanf("%lld",&grid[i][j]);
		for(int i=0;i<r;i++){
			if(i%2==0){
				for(int j=0;j<c;j++){
					if(carry){
						if(grid[i][j]&1){
							carry=false;
						}
						vec.puba(mp(prev,mp(i+1,j+1)));
						prev=mp(i+1,j+1);
					}
					
					else{
						if(grid[i][j]&1){
							carry=1;
							prev=mp(i+1,j+1);
						}
					}
				}
			}
			
			else{
				for(int j=c-1;j>=0;j--){
					if(carry){
						if(grid[i][j]&1){
							carry=false;
						}
						vec.puba(mp(prev,mp(i+1,j+1)));
						prev=mp(i+1,j+1);
					}
					
					else{
						if(grid[i][j]&1){
							carry=1;
							prev=mp(i+1,j+1);
						}
					}
				}
			}
			
		}
		
		
		printf("%d\n",(int)vec.size());
		
		for(int i=0;i<vec.size();i++){
			printf("%lld %lld %lld %lld\n",vec[i].fi.fi,vec[i].fi.se,vec[i].se.fi,vec[i].se.se);
		}
		
	}
}

Measured memory_bytes: 8432
def ii(): return int(input())


def mi(): return map(int, input().split())


def li(): return list(map(int, input().split()))


n = ii()

ps = []

xmin = (1e9, 0)
xmax = (-1e9, 0)
ymin = (0, 1e9)
ymax = (0, -1e9)

for _ in range(n):
    x, y = mi()
    ps.append((x, y))

l1 = list(sorted(ps, key=lambda p: p[0] + p[1]))
l2 = list(sorted(ps, key=lambda p: p[0] - p[1]))


def d(p1, p2):
    return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])


a1 = d(l1[0], l1[n-1])
a2 = d(l2[0], l2[n-1])

print(max(a1, a2))


Measured memory_bytes: 48380
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

template<typename T> vector<T> make_vector(size_t sz){
	return vector<T>(sz);
}

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

template<typename T,typename U,typename... V> 
typename enable_if<is_same<T, U>::value!=0>::type 
fill_value(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_value(U &u, const V... v){
	for(auto &e:u){
		fill_value<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};

const pid_t pid = getpid();
// Problem Specific Parameter:

int main(void){
	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;

	const int from = h1 * 60 + m1;
	const int to = h2 * 60 + m2;
	const int ans = max(0, to - from - k);
	cout << ans << endl;
	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007LL
#define maxn 200005
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 28
#define off 1
#define sq(x) ((x)*(x))

using namespace __gnu_pbds;
using namespace std ;

// typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// typedef pair<i64, i64> pii;

int a[maxn] , b[maxn] ;

int main()
{
    int i , j , k , l , m , n ;

    scanf("%d",&n) ;

    for(i=1 ; i<=n ; i++) scanf("%d",&a[i]) ;
    for(i=1 ; i<=n ; i++) scanf("%d",&b[i]) ;

    int ans = 0 ;

    int mask1 = (1<<ln) , mask2=(1<<(ln+1)) ;
    int mask3 = mask1|mask2 , mask4=(1<<(ln+2)) ;
    int mask = (1<<(ln+1)) - 1 ;

    for(i=ln ; i>=0 ; i--)
    {
        for(j=1 ; j<=n ; j++)
        {
            a[j] = (a[j]&mask) ;
            b[j] = (b[j]&mask) ;
        }

        sort(b+1,b+n+1) ;

        for(j=1 ; j<=n ; j++)
        {
            int ret = lower_bound(b+1,b+n+1,mask2-a[j]) - lower_bound(b+1,b+n+1,mask1-a[j]) ;
            ret += lower_bound(b+1,b+n+1,mask4-a[j]) - lower_bound(b+1,b+n+1,mask3-a[j]) ;
            if(ret%2) ans ^= (1<<i) ;
        }

        mask1 = mask1>>1 ; mask2 = mask2>>1 ; mask3 = mask3>>1 ; mask4 = mask4>>1 ; mask = mask>>1 ;
    }

    printf("%d\n",ans) ;

    return 0 ;
}


Measured memory_bytes: 1792
#include <stdio.h>
int main(void){

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

int s=a-b;

if(s>0){
printf("a > b\n");
}

else if(s<0){
printf("a < b\n");
}
else{
printf("a == b\n");
}
return 0;
}

Measured memory_bytes: 580
#include <stdio.h>
     
    int main(void)
    {
    	char str1[3] = "", str2[3] = "";
    	
    	scanf("%s", str1);
    	scanf("%s", str2);
    	
    	if (str1[0] == str2[2] && str1[2] == str2[0] && str1[1] == str2[1]){
    		printf("YES\n");
    	}
    	else {
    		printf("NO\n");
    	}
    	return (0);
    }

Measured memory_bytes: 128
def grid_coloring(H: int, W: int, N: int, A: list)->list:
    h, w = 0, 0
    dw = 1
    ret = [[''] * W for _ in range(H)]
    for i, a in enumerate(A):
        for _ in range(a):
            ret[h][w] = str(i+1)
            if w + dw == W:
                h += 1
                dw = -1
            elif w + dw == -1:
                h += 1
                dw = 1
            else:
                w += dw
    return ret


if __name__ == "__main__":
    H, W = map(int, input().split())
    N = int(input())
    A = [int(s) for s in input().split()]
    ans = grid_coloring(H, W, N, A)
    print('\n'.join(map(' '.join, ans)))


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

   typedef long long ll;

   const double EPS = (1e-7);
   const ll INF =(1e9);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   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 dump(x) cerr<< #x << "= " << (x) << endl;

   int gcd(int a,int b){return b?gcd(b,a%b):a;};

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string S;
    cin >> S;
    if (S.size() == 2) cout << S << endl;
    else cout << S[2] << S[1] << S[0] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  int i;
  int d[n];
  for(i=0;i<n;i++){
    cin >> d[i];
  }
  sort(d,d+n,greater<>());
  int kmin,kmax;
  kmax = d[n/2 - 1];
  kmin = d[n/2];
  cout << kmax - kmin;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> P;
typedef unsigned long long int ull;
const ll MOD=1e9+7;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=1e18;

int main(){
    int N,C;cin>>N>>C;
    int D[C][C];
    for(int i=0;i<C;i++){
        for(int j=0;j<C;j++) cin>>D[i][j];
    }
    int c[N][N];
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            cin>>c[i][j];
            c[i][j]--;
        }
    }
    map<int,ll> m0,m1,m2;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if((i+j)%3==0) m0[c[i][j]]++;
            else if((i+j)%3==1) m1[c[i][j]]++;
            else m2[c[i][j]]++;
        }
    }
    ll  ans=INF;
    for(int i=0;i<C;i++){
        for(int j=0;j<C;j++){
            for(int k=0;k<C;k++){
                if(i==j||j==k||k==i) continue;
                ll sum=0;
                for(auto it:m0){
                    sum+=D[it.first][i]*it.second;
                }
                for(auto it:m1){
                    sum+=D[it.first][j]*it.second;
                }
                for(auto it:m2){
                    sum+=D[it.first][k]*it.second;
                }
                ans=min(ans,sum);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main()
{
	int r, c, s, b ;
	s = 0;
	b = 0;
	cin >> r >> c;
	
	int A[101][101];
	for (int i = 0; i < 101; i++)
	for (int j = 0; j < 101; j++)
	{
		if (i >= r)continue;
		if (j >= c)continue;
		cin >> A[i][j];
		s += A[i][j];
	}

	for (int i = 0; i <= 101 * 101 - 1; i++){
		int j = i / 101;
		if (i == r * 101 + c) cout << s << endl;
		else if (i >= j * 101 && i <= j * 101 + c - 1 && j < r) cout << A[j][i - j * 101] << " ";
		else if (i == j * 101 + c && j <= r)
		{
			int d;
			d = 0;
			for (int k = 0; k < c; k++)  d += A[j][k];
			cout << d << endl;
		}
		else if (j == r && i - j * 101 <= c - 1){

			int e;
			e = 0;
			for (int f = 0; f < r; f++)  e += A[f][i - j * 101];
			cout << e << " ";
		}
	}
	return 0;
}



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

int main(){
	long long a,v,b,w,t,ans;
	cin>>a>>v>>b>>w>>t;
	if(v-w>0)
	{
		ans=(v-w)*t;
		if(ans>=abs(a-b))
		{
			cout<<"YES"<<endl; 
		}
		else
		{
			cout<<"NO"<<endl;
		}
	}
	else
	{
		cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3580
# Beginner 50 D
s = list(input())

#文字数の偶奇
cont = len(s) % 2

#両端が同じ文字かどうか
edge = 0
if s[0] == s[-1]:
    edge = 0
else:
    edge = 1

def judge(a,b):
    key = str(a) + str(b)
    winner = {
        "00" : "First",
        "01" : "Second",
        "10" : "Second",
        "11" : "First"
    }
    print(winner[key])

judge(cont, edge)

Measured memory_bytes: 4084
N, K = map(int, input().split())
a = list(map(int, input().split()))
dp = [0 for i in range(K+1)]
# dp[K] := 残りKこで初めて、先手が勝つような場合 1 ,後手 が勝つような場合 0
for i in range(1, K+1):
    is_first_win = False
    for v in a:
        if i-v >= 0 and dp[i-v] == 0:
            is_first_win = True
            break
    if is_first_win:
        dp[i] = 1
if dp[K]:
    print("First")
else:
    print("Second")


Measured memory_bytes: 9872
#include<bits/stdc++.h>
using namespace std;
class UnionFindTree{
 public:
  UnionFindTree(int size){
    groups=vector<int>(size);
    for(int i=0;i<groups.size();++i)groups[i]=i;
  }
  int getRoot(int v){
    if(groups[v]==v)return v;
    return groups[v]=getRoot(groups[v]);
  }
  void unite(int u,int v){
    u=getRoot(u);
    v=getRoot(v);
    groups[max(u,v)]=min(u,v);
  }
  bool isSameGroup(int u,int v){
    return getRoot(u)==getRoot(v);
  }
 private:
  vector<int>groups;
};
main(){
  int N,M;
  cin>>N>>M;
  UnionFindTree t(N+1);
  vector<int>p(N+1);
  for(int i=1;i<=N;++i)cin>>p[i];
  for(int i=1;i<=M;++i){
    int x,y;
    cin>>x>>y;
    t.unite(x,y);
  }
  int count_=0;
  for(int i=1;i<=N;++i){
    if(t.isSameGroup(i,p[i]))++count_;
  }
  cout<<count_<<endl;
}


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

const int MAXN = 1e4 + 5;

int n, a[MAXN];

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf("%d", a + i);
	
	int now = n, ans = 0;
	for (int i = 2; i <= n; ++i) {
		if (a[i] == a[i - 1]) {
			++ans;
			a[i] = ++now;
		}
	}
	
	std::cout << ans << std::endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long int find(vector<pair<int,long long int> >&arr,int W,int i,vector<vector<long long int> >&memo)
{
	if(i<0 || W<=0)
	   return 0;
	if(memo[i][W]!=-1)
	   return memo[i][W];
	else
	{
		if(W<arr[i].first){
		    memo[i][W]=find(arr,W,i-1,memo);
		    return memo[i][W];
		}
		else{
			memo[i][W]=max(find(arr,W,i-1,memo),find(arr,W-arr[i].first,i-1,memo)+arr[i].second);
			return memo[i][W];
		}
	}
}
int main()
{
	int n,W;
	cin>>n>>W;
	vector<pair<int,long long int> >arr;
	vector<vector<long long int> >memo(n+1,vector<long long int> (W+1,-1));
	for(int i=0;i<n;i++)
	{
		long long int w,v;
		cin>>w>>v;
		arr.push_back(make_pair(w,v));
	}
	cout<<find(arr,W,n-1,memo)<<"\n";
	
}


Measured memory_bytes: 80256
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while(true) {
			String str = sc.next();
			int sum=0;

			if(str.equals("0")) {
				break;
			}

			for(int i=0; i<str.length(); i++) {
				String s=str.substring(i,i+1);
				sum += Integer.valueOf(s);
			}
			System.out.println(sum);
		}

	}
}


Measured memory_bytes: 26648
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    k = int(input())
    keta = 1
    mod = 7%k
    while keta < 10**7:
        if mod==0:
            print(keta)
            break
        keta += 1
        mod = (mod*10 + 7)%k
    else:
        print(-1)


if __name__=='__main__':
    main()

Measured memory_bytes: 9168
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using Pi_i = pair<int, int>;
using VI = vector<int>;
using VD = vector<double>;
using VLL = vector<ll>;
using VS = vector<string>;
using VC = vector<char>;
using VB = vector<bool>;

const int MOD = 1000000007;
const int INF = 1000000000;

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




int main(){
    int n; cin >> n;
    int ans = -2 * INF, minv = 2 * INF;
    REP(i, n){
        int R; cin >> R;
        chmax(ans, R - minv);
        chmin(minv, R);
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 3116
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for (int i=0;i<(n);i++)

using namespace std;

int main() {
	long long n, a, b;
	cin >> n >> a >> b;
	long long ans = 0;
	long long tmp = a * (n / (a + b));
	if (n % (a + b) < a) {
		ans = tmp + n % (a + b);
	}
	else ans = tmp + a;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3548
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
 
     String[] nyu=sc.nextLine().split(" ");

String[] nyuA=nyu[0].split("");
String[] nyuB=nyu[1].split("");
String[] nyuC=nyu[2].split("");

//     String nyu=sc.nextLine();
//int A=Integer.parseInt(nyu[0]);
//int B=Integer.parseInt(nyu[1]);
//int C=Integer.parseInt(nyu[2]);
//int D=Integer.parseInt(nyu);



//StringBuffer sb = new StringBuffer(nyu);
//		String dst = sb.reverse().toString();

//     String nyu2=sc.nextLine();
//int E=Integer.parseInt(nyu2);



//double A=Double.parseDouble(nyu[0]);
//double B=Double.parseDouble(nyu[1]);
/*
switch(C){
case 7:
case 5:
case 3:
System.out.println("YES") ;
break;
default:
System.out.println("NO") ;

break;
}
*/

//int res=Math.min((A*B),C);

//for(String tem:nyu){
//if(tem.equals("1"))res++;
//}
//int res=0;
//for(int i=0;i<300;i++){
//if(num[i]==1)res=i;
//}

//char[] c = nyu.toCharArray();


//System.out.println(nyu+"-"+line_r_2+"-"+nyu2+"-"+line_r_1);



//if(nyuA[nyuA.length-1].equals(nyuB[0]) && nyuB[nyuB.length-1].equals(nyuC[0])){
//double res=Math.ceil((AB)/2);

//System.out.println("YES");
//}else if((C-B)<A){
//System.out.println("safe");

//}else{
System.out.println(nyuA[0].toUpperCase()+nyuB[0].toUpperCase()+nyuC[0].toUpperCase());

//}




	}
}

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

#define all(x) (x).begin(),(x).end()
#define endl '\n'
#define int long long



signed main() { //[J][O][L][S][K][E][Y]
        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int n; cin >> n;
        vector<int> vec(n);
        map<int,int> freq;
        map<int,bool> went;
        for (int i = 0; i < n; i++)  {
                cin >> vec[i];
                freq[vec[i]]++;
        }

        int cnt = 0;
        for (int i = 0; i < n; i++) {
                if (!went.count(vec[i])) {
                        cnt += freq[vec[i]] * (freq[vec[i]] - 1) / 2;
                        went[vec[i]] = true;
                }
        }

        for (int i = 0; i < n; i++) {
                int temp = cnt;
                temp -= freq[vec[i]] * (freq[vec[i]] - 1) / 2;
                temp += (freq[vec[i]] - 1) * (freq[vec[i]] - 2) / 2;
                cout << temp << endl;
        }


        return 0;
}

Measured memory_bytes: 18944
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>
#include<iostream>
#include<cmath>

struct Dish {
	int time, taste;
};
int main() {
	int n, t; std::cin >> n >> t;
	std::vector<Dish> dishes(n); for (auto& d : dishes) std::cin >> d.time >> d.taste;
	std::sort(dishes.begin(), dishes.end(), [](const Dish a, const Dish b) {return a.time < b.time; });
	std::vector<int> max_taste(t + 3000, 0);
	for (const auto dish : dishes) {
		for (int i = t - 1; i >= 0; --i) {
			if (max_taste[i + dish.time] < max_taste[i] + dish.taste) {
				max_taste[i + dish.time] = max_taste[i] + dish.taste;
			}
		}
	}
	std::cout << *std::max_element(max_taste.begin(), max_taste.end()) << '\n';
}


Measured memory_bytes: 256
import collections

H,W=map(int,input().split())
S=[[10**10 for j in range(W)] for i in range(H)]

Q=collections.deque([])
S[0][0]=1

s=[]
cnt=0
for i in range(H):
  s=input()
  for j in range(W):
    if s[j]=="#":
      S[i][j]=-1
      cnt+=1
#print(S)

def bfs(i,j):
  if 0<=i+1<H and S[i][j]+1<S[i+1][j] and S[i+1][j]!=-1:
    Q.append([i+1,j])
    S[i+1][j]=S[i][j]+1
  if 0<=i-1<H and S[i][j]+1<S[i-1][j] and S[i-1][j]!=-1:
    Q.append([i-1,j])
    S[i-1][j]=S[i][j]+1
  if 0<=j+1<W and S[i][j]+1<S[i][j+1] and S[i][j+1]!=-1:
    Q.append([i,j+1])
    S[i][j+1]=S[i][j]+1
  if 0<=j-1<W and S[i][j]+1<S[i][j-1] and S[i][j-1]!=-1:
    Q.append([i,j-1])
    S[i][j-1]=S[i][j]+1

Q.append([0,0])
while len(Q):
  q=Q.popleft()
  bfs(q[0],q[1])
  #for i in range(H):
  #  print(S[i])
  #print("")
print(H*W-S[-1][-1]-cnt if S[-1][-1]!=10**10 else -1)

Measured memory_bytes: 3316
import java.util.*;

public class Main {
    public static void main(String[] args) {
        /*
        n: 5
        S: 1 2 3 4 5 
        q: 3
        T: 3 4 1
        out: 3
        */
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] s = new int[n+1];
        for (int i = 0; i < n; i++) {
            s[i] = sc.nextInt();
        }
        int q = sc.nextInt();
        int ans = 0;
        for (int i = 0; i < q; i++) {
            if(search(sc.nextInt(),n,s))ans++;;
        }
        System.out.println(ans);
    }
    
    static boolean search(int key, int n, int[] s) {
        s[n] = key;
        int i = 0;
        while(s[i] != key){
            i++;
        }
        return i != n;
    }
}


Measured memory_bytes: 39944
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
	int H,W;
	cin>>H>>W;
	int i,j;
	string S;
	for (i=0;i<H;i++){
		for (j=0;j<W;j++){
			cin>>S;
			if (S.compare("snuke")==0){
				
				cout<<char('A'+j)<<i+1<<endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>
 
using namespace std;
typedef long long ll;
 
const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
 
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,A,B,C,D;
  string S,ans;
  cin>>N>>A>>B>>C>>D>>S;
  S.push_back('#');
  S.push_back('#');
  S.push_back('#');
  
  A--;B--;C--;D--;
 
  int su_right=A, hu_right=B;
 
  bool tmp_flag=false;
  for(int i=B-1;i<=D-1;i++){
    if(S[i]=='.' && S[i+1]=='.' && S[i+2]=='.'){
      tmp_flag=true;
    }
  }
 
  for(int i=A;i<N+2;i++){
    if(S[i-1]=='#' && S[i] =='#'){
      su_right=i-2;
      break;
    }
  }
 
  for(int i=B;i<N+2;i++){
    if(S[i-1]=='#' && S[i] =='#'){
      hu_right=i-2;
      break;
    }
  }
  if(C<D){
    if(C<=su_right && D<=hu_right){
      ans="Yes";
    }else{
      ans="No";
    }
  }else{
    if(su_right==hu_right && tmp_flag==true && C<=su_right && D<=hu_right){
      ans="Yes";
    }else{
      ans="No";
    }
  }
 
  cout<<ans<<endl;
 
}


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

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


ll n;
cin>>n;
if (n%2==0) {
		cout << -1 << "\n";
}

else{
ll t=0;
ll ans=-1;
for(int i=0;i<=2*1000000;i++){
    t=t*10;
    t+=7;
    t=t%n;
    if(t==0){
        ans=i+1;
        break;
    }
   // cout<<t<<endl;
}
cout<<ans;
}



}










Measured memory_bytes: 3656
#include <iostream>
#include <iomanip>
#include <queue>
#include <deque>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <bitset>

#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define FILL(x, y) memset(x, y, sizeof(x))
#define pb push_back
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

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;
}

using namespace std;
using ll = long long;

const int kInf = 2e9;
const ll kLInf = 2e18;
const ll kMod = 1000000007;

long long modinv(long long a, long long m) {
   long long b = m, u = 1, v = 0;
   while (b) {
      long long t = a / b;
      a -= t * b; swap(a, b);
      u -= t * v; swap(u, v);
   }
   u %= m;
   if (u < 0) u += m;
   return u;
}

ll myPow(ll a, ll b)
{
   if (b == 1) {
      return a;
   }
   ll halfPow = myPow(a, b / 2) % kMod;
   if (b % 2) {
      return a * halfPow % kMod * halfPow % kMod;
   } else {
      return halfPow * halfPow % kMod;
   }
}

ll cmb(ll a, ll b)
{
   b = min(a - b, b);
   ll r = 1;
   for (int i = 1; i <= b; i++) {
      r = r * ((a - b + i)%kMod) %kMod * modinv(i, kMod) % kMod;
      r %= kMod;
   }
   return r;
}

int gcd (int a, int b) {
   return b ? gcd(b, a % b) : a;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
ll n, a, b;
int main()
{
   cout << fixed << setprecision(10);
   cin >> n >> a >> b;
   ll power = myPow(2, n) % kMod;
   ll comb1 = cmb(n, a) % kMod;
   ll comb2 = cmb(n, b) % kMod;
   power -= 1;
   if (power < 0) power += kMod;
   power %= kMod;
   power -= comb1;
   if (power < 0) power += kMod;
   power %= kMod;
   power -= comb2;
   if (power < 0) power += kMod;
   power %= kMod;
   cout << power << endl;
   return 0;
}



Measured memory_bytes: 256
class in{struct myIterator{int it;const bool rev;explicit constexpr myIterator(int it_, bool rev=false):it(it_),rev(rev){}int operator*(){return it;}bool operator!=(myIterator& r){return it!=r.it;}void operator++(){rev?--it:++it;}};const myIterator i,n;public:explicit constexpr in(int n):i(0),n(n){}explicit constexpr in(int i,int n):i(i,n<i),n(n){}const myIterator& begin(){return i;}const myIterator& end(){return n;}};

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

template<class T>
using minHeap = priority_queue<T, vector<T>, greater<T>>;
const int INF = 1e9;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<pair<int, int>> taxi(n);
    for(int i : in(n)) {
        int c, r;
        cin >> c >> r;
        taxi[i] = make_pair(c, r);
    }
    vector<vector<int>> adj(n);
    for(int _ : in(k)) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        adj[u].emplace_back(v);
        adj[v].emplace_back(u);
    }
    vector<vector<int>> graph(n);
    bitset<5000> used;
    // BFS
    for(int cur : in(n)) {
        auto& res = graph[cur];
        used.reset();
        queue<pair<int, int>> que;
        que.emplace(cur, 0);
        used[cur] = 1;
        while(!que.empty()) {
            int v, depth;
            tie(v, depth) = que.front(); que.pop();
            if(depth >= taxi[cur].second) break;
            for(int nv : adj[v]) if(!used[nv]) {
                res.emplace_back(nv);
                que.emplace(nv, depth + 1);
                used[nv] = 1;
            }
        }
    }
    //dijikstra
    vector<int> dist(n, INF);
    dist[0] = 0;
    minHeap<pair<int, int>> que;
    que.emplace(0, 0);
    while(!que.empty()) {
        int dis, v;
        tie(dis, v) = que.top(); que.pop();
        if(dist[v] < dis) continue;
        for(int nv : graph[v]) {
            if(dist[nv] > dist[v] + taxi[v].first) {
                dist[nv] = dist[v] + taxi[v].first;
                que.emplace(dist[nv], nv);
            }
        }
    }
    cout << dist[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 70616
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        sc.close();

        // 主処理
        String result = s.replaceAll(",", " ");

        // 出力
        System.out.println(result);
    }
}


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

void solve() 
{
    int a,b,h,m;cin>>a>>b>>h>>m;
    double s1=h*30+30*(m/60.0);
    double s2=m*6;
    double s=fabs(s1-s2);
    if(s>=180)s=360-s;
    cout<<setprecision(20)<<sqrt(a*a+b*b-2*a*b*cos(s/180*M_PI))<<endl;
}

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

Measured memory_bytes: 4236
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
import java.util.LinkedHashMap;

class Deck{
    private LinkedHashMap<Integer, Integer> frequency = new LinkedHashMap<>();
    public Deck(){
        for (int i = 1; i <= 9; i++){
            frequency.put(i, 0);
        }
    }

    public void add(int i){
        frequency.replace(i, frequency.get(i)+1);
    }

    public int consec(){
        int sets = 0;
        for (Map.Entry<Integer, Integer> entry: frequency.entrySet()){
            if (entry.getValue() >= 3){
                sets++;
                frequency.replace(entry.getKey(), frequency.get(entry.getKey()) - 3);
            }
        }
        return sets;
    }

    public int row(){
        int sets = 0;
        Iterator<Integer> key_iter = frequency.keySet().iterator();
        Iterator<Integer> iter = frequency.values().iterator();
        int first_key = key_iter.next(), mid_key = key_iter.next();
        int first = iter.next(), mid = iter.next();
        while(iter.hasNext()){
            int last = iter.next(), last_key = key_iter.next();
            while (last >= 1 && mid >= 1 && first >= 1){
                sets++;
                last--; mid--; first--;
            }
            frequency.replace(last_key, last);
            frequency.replace(mid_key, mid);
            frequency.replace(first_key, first);
            first_key = mid_key; mid_key = last_key;
            first = mid; mid = last;
        }
        return sets;
    }
}

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        for (int i = 0; i < k; i++) {
            LinkedHashMap<Character, Deck> colorDeck = new LinkedHashMap<>();
            colorDeck.put('R', new Deck()); colorDeck.put('G', new Deck()); colorDeck.put('B', new Deck());
            int number_list[] = new int[9];
            for (int j = 0; j < 9; j++) number_list[j] = sc.nextInt();
            for (int j = 0; j < 9; j++) colorDeck.get(sc.next().charAt(0)).add(number_list[j]);
            int sets = 0;
            for (Deck deck: colorDeck.values()){
                sets += deck.consec();
                sets += deck.row();
            }
            System.out.println(((sets >= 3)? 1:0));
        }
    }
}

Measured memory_bytes: 29020
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <array>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;

typedef  pair<int,int> P;
typedef long long LL;

const LL  INF=1<<31;



int main(){
     int n,k=2;
     cin>>n;
     int h[100000];
     for(int i=0;i<n;++i){
          cin>>h[i];
     }
     LL dp[100001];

      for(int i=0;i<n;++i){
           dp[i]=INF;
      }
            dp[0]=0;
            dp[1]=abs(h[0]-h[1]);



     for(int i=2;i<n;++i){
          dp[i]=dp[i-1]+abs(h[i-1]-h[i]);
          for(int j=2;j<=k;++j){

               if(j<=i)dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));
          }
     }     

     cout<<dp[n-1]<<endl;


}

Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<vector>
#include<cassert>
#include<bitset>
#include<cmath>
#include<set>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<28)
 
using namespace std;
 
struct Puzzle
{
  char t,r,b,l;
  Puzzle(char t='$',char r='$',char b='$',char l='$'):t(t),r(r),b(b),l(l){}
 
  void rotate90()
  {
    char tmp = t;
    t = l;
    l = b;
    b = r;
    r = tmp;
  }
 
  bool operator < (const Puzzle &p)const
  {
    if(t != p.t)return t < p.t;
    if(r != p.r)return r < p.r;
    if(b != p.b)return b < p.b;
    return l < p.l;
  }
 
};
 
Puzzle puzzle[9];
Puzzle p2[9];
int cnt;
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};
 
 
 
bool match(char a,char b)
{
  if(a == 'R' && b == 'r')return true;
  if(a == 'G' && b == 'g')return true;
  if(a == 'B' && b == 'b')return true;
  if(a == 'W' && b == 'w')return true;
  if(a == 'w' && b == 'W')return true;
  if(a == 'b' && b == 'B')return true;
  if(a == 'g' && b == 'G')return true;
  if(a == 'r' && b == 'R')return true;
    return false;
}
 
void dfs(int p,int used)
{
 
  if(p >= 9)
    {
      cnt++;
      return;
    }
 
  rep(i,9)
    {
      if((used >> i) & 1)continue;
      puzzle[p] = p2[i];
      rep(j,4)
    {
      if(p == 0)
        {
          dfs(p+1,used|(1<<i));
          puzzle[p].rotate90();
          continue;
        }
 
      if(p%3 == 0)
        {
          if(match(puzzle[p].t,puzzle[p-3].b))
        {
          dfs(p+1,used|(1<<i));
        }
        }
      else
        {
          bool ok = true;
          if(p-3>=0)
        if(!match(puzzle[p].t,puzzle[p-3].b))ok = false;
          if(!match(puzzle[p].l,puzzle[p-1].r))ok = false;
          if(ok)
        {
          dfs(p+1,used|(1<<i));
        }
        }
      puzzle[p].rotate90();
    }
    }
 
}
 
int main()
{
  int T;
  cin >> T;
  while(T--)
    {
      cnt = 0;
      rep(i,3)
    {
      rep(j,3)
        {
          string s;
          cin >> s;
          p2[i*3+j].t = s[0];
          p2[i*3+j].r = s[1];
          p2[i*3+j].b = s[2];         
          p2[i*3+j].l = s[3];         
        }
    }
      dfs(0,0);
 
      cout << cnt << endl;
    }
  return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string> //文字列
#include <iomanip> //doubleの桁数指定 setprecision()
#include <list> //前後に数値を入れれる配列
#include <map> //map
#include <vector> //vecror



#define REP(i,m,n) for(ll i = (ll) (m);i < (ll) (n);i++) //forの短縮
#define rep(i,n) REP(i,0,n) //REPが0の時
#define ll long long int

using namespace std;

double PI = acos(-1); //円周率

//常設関数↓

//最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

//degree → radian
long double chg_DegRad(long double deg) {
	return deg * PI / 180.0;
}

//radian → degree
long double chg_RadDeg(long double rad) {
	return rad * 180.0 / PI;
}
 
//桁数
ll CountDigit(ll n) {
	ll digit = 1;
	while ((n /= 10) != 0) digit++;
	return digit;
}

//距離
double dis(double xa, double ya, double xb, double yb) {
	return pow(pow(xa - xb, 2.0) + pow(ya - yb, 2.0), 0.5);
}

//abs()平均
//pow(,)累乗


//提出コード↓

int n, m, sum;
int a[101];
bool J = true;



int main() {
	cin >> n >> m;
	rep(i, n) {
		cin >> a[i];
		sum += a[i];
	}

	sort(a, a + n);
	reverse(a, a + n);
	rep(i, m) {
		if (a[i] < ( sum/ 4.0 / m)) J = false;
	}
	if (J) cout << "Yes" << endl;
	else cout << "No" << endl;


	return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
static const int MAX=20;
int A[MAX],B[MAX],C[MAX],cost;
int main(void){
	int N;	cin >> N;
	for(int i=0;i<N;i++)cin >> A[i];
	for(int i=0;i<N;i++)cin >> B[i];
	for(int i=0;i<N;i++)
		cost+=(A[i]-B[i]>0?A[i]-B[i]:0);
	cout << cost << endl;
	return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll X, K, D;
    cin >> X >> K >> D;
    X = abs(X);
    if(abs(X) / D / K >= 1) {
        ll temp = abs(X) / D - K;
        ll temp2 = abs(X) % D;
        if(X < 0) cout << temp2 + temp * D << endl;
        else cout << temp2 + temp * D << endl;
    } else {
        ll temp = X % D;
        ll temp2 = K - X / D;
        if(temp2 % 2) cout << D - temp << endl;
        else cout << temp << endl;
    }
    return 0;
}


Measured memory_bytes: 3600