akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int M = scan.nextInt();
        List<Integer>[] list = new List[M];
        for (int i = 0; i < M; i++) {
            list[i] = new ArrayList<>();
        }
        for (int i = 0; i < N; i++) {
            int K = scan.nextInt();
            for (int j = 0; j < K; j++) {
                int L = scan.nextInt()-1;
                list[L].add(i);
            }
        }
        UnionFind uf = new UnionFind(N);
        for (int i = 0; i < M; i++) {
            if (list[i].size() <= 1) {
                continue;
            }
            for (int j = 1; j < list[i].size(); j++) {
                uf.unite(list[i].get(0), list[i].get(j));
            }
        }
        if (uf.size(0) == N) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
    class UnionFind {
        private int[] parent;
        private int[] size;
        UnionFind(int N) {
            int[] parent = new int[N];
            for (int i = 0; i < N; i++) {
                parent[i] = i;
            }
            int[] size = new int[N];
            Arrays.fill(size, 1);
            this.parent = parent;
            this.size = size;
        }
        int find(int x) {
            if (x == this.parent[x]) {
                return x;
            }
            return this.parent[x] = find(this.parent[x]);
        }
        boolean same(int x, int y) {
            return find(x) == find(y);
        }
        void unite(int x, int y) {
            int parent_x = find(x);
            int parent_y = find(y);
            if (parent_x == parent_y) {
                return;
            }
            int size_x = this.size[parent_x];
            int size_y = this.size[parent_y];
            if (size_x < size_y) {
                this.size[parent_y] += this.size[parent_x];
                this.parent[parent_x] = parent_y;
                this.size[parent_x] = -1;
                return;
            }
            this.size[parent_x] += this.size[parent_y];
            this.parent[parent_y] = parent_x;
            this.size[parent_y] = -1;
        }
        int size(int x) {
            int parent_x = find(x);
            return this.size[parent_x];
        }
    }
}


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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl
#define rep(n, i) for (int i = 0; i < n; i++)

using namespace std;
using i64 = long long;

int main()
{
    int x, n;
    cin >> x >> n;
    vector<int> p(n);
    for (auto &&pi : p)
    {
        cin >> pi;
    }

    vector<vector<int>> list(1000);
    for (int y = 0; y <= 110; y++)
    {
        bool ok = true;
        for (auto &&pi : p)
        {
            ok &= pi != y;
        }
        if(ok)
        {
            list[abs(x-y)].push_back(y);
        }
    }

    for (auto &&li : list)
    {
        if(!li.empty())
        {
            cout << li.front() << endl;
            return 0;
        }
    }
    cout << x << endl;
    
    return 0;
}

Measured memory_bytes: 3656
import java.util.*;

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

		int N = sc.nextInt();

		Set<Integer> d = new HashSet<>();

		for(int i=0; i<N; i++)
			d.add(sc.nextInt());

		println(d.size());

	}

	public static void print(Object o) {
		System.out.print(o);
	}

	public static void println(Object o) {
		System.out.println(o);
	}
}

Measured memory_bytes: 21076
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
int main() {
	int n, m, c;
	cin >> n >> m >> c;
	int b[25];
	for (int i = 0; i < m; i++) {
		cin >> b[i];
	}
	int a[25][25];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> a[i][j];
		}
	}
	int count = 0;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			sum += b[j] * a[i][j];
			
		}
		if (sum + c > 0) {
			count++;
		}
		sum = 0;
	}
	cout << count << endl;
	return 0;
	
}

Measured memory_bytes: 256
s=input()
if s=="SUN":
    a=7
if s=="MON":
    a=6
if s=="TUE":
    a=5
if s=="WED":
    a=4
if s=="THU":
    a=3
if s=="FRI":
    a=2
if s=="SAT":
    a=1
print(a)


Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<algorithm>
#include<string.h>
#include<complex>
using namespace std;
typedef long long int llint;
int main(){
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b >= c){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}


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

#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
using i32 = int32_t;
using i64 = int64_t;
using f32 = float;
using f64 = double;
using P = pair<int, int>;

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

template <class T>
void dump_vec(const vector<T>& v) {
    auto len = v.size();
    rep(i, 0, len) {
        cout << v[i] << (i == (int)len - 1 ? "\n" : " ");
    }
}

struct FastIO {
    FastIO() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} FASTIO;

//---------------------------------------------------------------------------------------------------

//---------------------------------------------------------------------------------------------------

signed main() {
    vector<int> v;
    int Q;
    cin >> Q;
    rep(i, 0, Q) {
        int q;
        cin >> q;
        if (q == 0) {
            int a;
            cin >> a;
            v.push_back(a);
        } else if (q == 1) {
            int a;
            cin >> a;
            cout << v[a] << "\n";
        } else {
            v.pop_back();
        }
    }
}



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

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]) {
  int n;
  cin >> n;
  int max_a = 100000;
  ll sum = 0;
  vector<ll> v_cnt(max_a + 1, 0), va(n);
  for (int i = 0; i < n; ++i) {
    cin >> va[i];
    v_cnt[va[i]]++;
    sum += va[i];
  }

  int q;
  cin >> q;
  vector<ll> ans;
  for (int i = 0; i < q; ++i) {
    int b, c;
    cin >> b >> c;
    ll cnt = v_cnt[b];
    v_cnt[b] = 0;
    v_cnt[c] += cnt;
    sum -= b * cnt;
    sum += c * cnt;
    ans.push_back(sum);
  }

  for (int i = 0; i < ans.size(); ++i) {
    cout << ans[i] << '\n';
  }

  return 0;
}

Measured memory_bytes: 5884
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;
int dp[105];// i番目まで観た時にかかる日数
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int K,T;
	cin >> K >> T;
	vector<int> a(T);
	int maxi = 0;
	for(int i=0;i<T;i++){
		cin >> a[i];
		maxi = max(maxi,a[i]);
	}
	cout << max(maxi-1-(K-maxi),0) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

int main() {
    using namespace std;

    int N, K;
    cin >> N >> K;

    int total = 0;
    for (int i=0; i<N; i++) {
        int x;
        cin >> x;

        total += std::min(x, std::abs(K - x));
    }

    cout << total * 2 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <string>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	ll a,b,c; cin>>a>>b>>c;
	ll d = c-b-a;
	// cerr << 4*a*b SP pow(c-a-b,2) << endl;
	if(d<=0) cout<<"No";
	else if(4*a*b<d*d) cout << "Yes";
	else cout << "No";

  return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int main(){
	ll n; cin >> n;
	int ans;
	if(n == 0) ans = 0;
	else ans = 64 - __builtin_clzll(n);
	cout << ans << endl;
	return 0;
}

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

int main(){
  ll x, y;
  cin >> x >>  y;
  ll ans = 0;

  while(x <= y){
    x *= 2;
    ++ans;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n=int(input())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]

count=0

for i in range(n):
    #print("a[i]:",a[i])
    #print("b[i]:",b[i])
    if b[i]==a[i]:
        count+=b[i]
    elif b[i] > a[i]:
        count+=a[i]
        if b[i]-a[i] == a[i+1]:
            count+=(b[i]-a[i])
            a[i+1]=0
        elif b[i]-a[i] > a[i+1]:
            count+=a[i+1]
            a[i+1]=0
        elif b[i]-a[i] < a[i+1]:
            count+=(b[i]-a[i])
            a[i+1]-=(b[i]-a[i])
    elif b[i] < a[i]:
        count+=b[i]

print(count)

Measured memory_bytes: 18624
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define N (1000)
int lcs(string X,string Y){
    int c[N+1][N+1];
    int m=X.size();
    int n=Y.size();
    int maxv=0;
    X=' '+X;
    Y=' '+Y;
    for(int i=0;i<=m;i++)c[i][0]=0;
    for(int i=1;i<=n;i++)c[0][i]=0;
    
    for(int i=1;i<=m;i++){
        for(int j=1;j<=n;j++){
            if(X[i]==Y[j]){
                c[i][j]=c[i-1][j-1]+1;
            }else{
                c[i][j]=max(c[i-1][j],c[i][j-1]);
            }
            maxv=max(maxv,c[i][j]);
        }
    }
    return maxv;
}

int main(void){
    string s1,s2;
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s1>>s2;
        cout<<lcs(s1,s2)<<endl;
    }
    return 0;
}



Measured memory_bytes: 7124
from itertools import permutations


def resolve():
    n, m, x = map(int, input().split())
    inf = float('INF')
    data = [list(map(int, input().split())) for i in range(n)]

    if n > 6:
        d = get(data[:n//2], n//2, m)
        e = get(data[n//2:], n - n//2, m)
        d = merge(d,e,m)
    else:
        d = get(data, n, m)

    ans = inf
    for tt,cost in d.items():
        for t in tt:
            if x > t:
                break
        else:
            if ans > cost:
                ans = cost

    print(ans if ans != inf else -1)

def get(data, n, m):
    d = {}
    for b in range(1 << n):
        tmp = [0 for i in range(m)]
        cost = 0
        for i in range(n):
            if ((1<<i) & b) == 0:
                continue
            cost += data[i][0]
            for j in range(1,m+1):
                tmp[j-1] += data[i][j]
        tt = tuple(tmp)
        if tt not in d:
            d[tt] = cost
        else:
            if cost < d[tt]:
                d[tt] = cost
    return d

def merge(d,e,m):
    f = {}
    for k,v in d.items():
        for s,t in e.items():
            tt = tuple(k[i]+s[i] for i in range(m))
            cost = v + t
            if tt not in f:
                f[tt] = cost
            else:
                if cost < f[tt]:
                    f[tt] = cost
    return f

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 74812
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			int a=sc.nextInt();
			int b=sc.nextInt();
			int n=sc.nextInt();
			System.out.println(sum(a%b*10,b,n,0));
		}
	}
	static int sum(int a,int b,int n,int sum){
		if(n==0){
			return sum;
		}else{
			return sum(a%b*10,b,n-1,sum+a/b);
		}
	}
}

Measured memory_bytes: 20032
#include <bits/stdc++.h>
using namespace std;
#define int long long
int f(int n){
	int ans = 0;
	for(int i = 1 ; i * i <= n ; i++){
		if( n % i == 0 ){
			if( n / i == i ) ans++;
			else ans+=2;
		}
	}
	return ans;
}
signed main(){
	int N;
	cin >> N;
	for(int i = 1 ; ; i++){
		if( f(i) == N ){
			cout << i << endl;
			return 0;
		}
	}

}

Measured memory_bytes: 1156
//Camel and Oases
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long lint;
int const N=2e5+10;
int const S=1<<19;
int n,V;
lint d[N];
int logV,a[25][N];
int U,f1[S],f2[S];
int upFind(int a[],int x)
{
    int L=1,R=a[0];
    while(L<R-1)
    {
        int mid=(L+R)>>1;
        if(a[mid]<=x) L=mid+1;
        if(a[mid]>x) R=mid;
    }
    if(a[L]>x) return a[L];
    else return a[R];
}
int lowFind(int a[],int x)
{
    int L=1,R=a[0];
    while(L<R-1)
    {
        int mid=(L+R)>>1;
        if(a[mid]<x) L=mid;
        if(a[mid]>=x) R=mid-1;
    }
    if(a[R]<x) return a[R]+1;
    else return a[L]+1;
}
int main()
{
    scanf("%d%d",&n,&V);
    logV=0;
    while((1<<logV)<=V) logV++;
    logV++;
    for(int i=1;i<=n;i++) scanf("%lld",&d[i]),d[i-1]=d[i]-d[i-1];
    d[n]=0;
    for(int i=1;i<=logV;i++)
    {
        a[i][0]=1;
        for(int j=1;j<=n;j++)
        {
            a[i][a[i][0]]=j;
            if(d[j]>(V>>(i-1))) a[i][0]++;
        }
    }
    if(a[1][0]>logV)
    {
        for(int i=1;i<=n;i++) printf("Impossible\n");
        return 0;
    }
    U=(1<<logV)-1;
    for(int s=0;s<=U;s++) f1[s]=0,f2[s]=n+1;
    for(int s=0;s<=U;s+=2)
        for(int i=2;i<=logV;i++)
        {
            int s0=1<<(i-1);
            if(s&s0) continue;
            f1[s|s0]=max(f1[s|s0],upFind(a[i],f1[s]));
            f2[s|s0]=min(f2[s|s0],lowFind(a[i],f2[s]-1));
        }
    for(int i=1;i<=a[1][0];i++)
    {
        bool f=false;
        int fr=a[1][i-1]+1,to=a[1][i];
        if(i==1) fr=1;
        for(int s=0;s<=U&&!f;s+=2)
            if(fr<=f1[s]+1 && f2[U-s-1]-1<=to) f=true;
        if(f) for(int j=fr;j<=to;j++) printf("Possible\n");
        else for(int j=fr;j<=to;j++) printf("Impossible\n");
    }
    return 0;
}

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

typedef long long ll;
#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define REPM(i,n) for(ll i=(n-1); 0=<i; i--)
#define VI vector<int>
#define VL vector<ll>
#define VD vector<double>
#define VS vector<string>
#define V_SORT_U(x) sort(x.begin(), x.end());
#define V_SORT_D(x) sort(x.begin(), x.end(),greater<int>());
#define V_SUM(x) accumulate(x.begin(), x.end(), 0)
#define STR_TRANS_UP(x) transform(x.begin(), x.end(), x.begin(), ::toupper);
#define STR_TRANS_LOW(x) transform(x.begin(), x.end(), x.begin(), ::tolower);

ll dp[201][201][201] = {0};

ll gcd(ll a, ll b, ll c){
    ll loop_max = max( max(a,b), max(b,c) );
    ll buff_return = 0;

    REP(i,loop_max)
    {
        if( (a % (i+1) ) == 0 &&
            (b % (i+1) ) == 0 &&
            (c % (i+1) ) == 0)
            {
                buff_return = i+1;
            }
    }

    return buff_return;
}
int main(void){
    int N;
    ll sum=0;
    cin >> N;

    //初期化
    REP(i,N)
    {
        REP(j,N)
        {
            REP(k,N)
            {
                dp[i+1][j+1][k+1] = -1;
            }
        }
    }

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

    REP(i,N)
    {
        REP(j,N)
        {
            REP(k,N)
            {
                if(dp[i+1][j+1][k+1] != -1)
                {
                    sum += dp[i+1][j+1][k+1];
                }
                else
                {
                    dp[i+1][j+1][k+1] = gcd(i+1,j+1,k+1);
                    dp[k+1][i+1][j+1] = dp[i+1][j+1][k+1];
                    dp[j+1][k+1][i+1] = dp[i+1][j+1][k+1];
                    dp[i+1][k+1][j+1] = dp[i+1][j+1][k+1];
                    dp[j+1][i+1][k+1] = dp[i+1][j+1][k+1];
                    dp[k+1][j+1][i+1] = dp[i+1][j+1][k+1];
                    sum += dp[i+1][j+1][k+1];
                }
            }
        }
    }

    cout << sum << endl;
    return 0;
}

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

int main() {
    int ans = 0;
    cin >> ans;
    while(ans > 0)
        ans -= 1000;
    ans = abs(ans);
    cout << ans << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin>>s;
	if(s=="RRR")cout<<3<<endl;
	else{
		if(s=="RRS"||s=="SRR")cout<<2<<endl;
		else if(s!="SSS")cout<<1<<endl;
		else cout<<0<<endl;
	}
	return 0;
 } 

Measured memory_bytes: 3512
#include <iostream>

using namespace std;

int N, M;
int a[50], b[50];

bool graph[50][50];
bool visited[50];

void dfs(int v) {
		visited[v] = true;
		for (int v2 = 0; v2 < N; v2++) {
				if (graph[v][v2] == false) continue;
				if (visited[v2] == true) continue;
				dfs(v2);
		}
}

int main() {
		cin >> N >> M;
		for (int i = 0; i < M; i++) {
				cin >> a[i] >> b[i];
				a[i]--; b[i]--;
				graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;

		}

		int ans = 0;

		for (int i = 0; i < M; i++) {
				graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;

				for (int j = 0; j < N; j++) {
						visited[j] = false;
				}

				dfs(0);

				bool bridge = false;
				for (int j = 0; j < N; j++) {
						if (visited[j] == false) bridge = true;
				}
				if (bridge) ans += 1;

				graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
		}

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


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int S=sc.nextInt();
		
		int h=S/3600;
		int m=(S-3600*h)/60;
		int s=S-3600*h-60*m;
		
		System.out.println(h+":"+m+":"+s);
		

	}
}


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

int main(){
    string s;
    cin >> s;
    int ans = 0;
    rep(i, s.length()) {
        if ( s[i] == '+' ) {
            ++ans;
        }
        else {
            --ans;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int N;
  cin >> N;
  
  string s;
  cin >> s;
  
  vector<int>rightB(N);
  vector<int>rightR(N);
  vector<int>rightG(N);
  int numB = 0;
  for(int i=N-1;i>=0;i--){
    rightB[i] = numB;
    if(s[i] == 'B') numB++;
  }
  
  int numG = 0;
  for(int i=N-1;i>=0;i--){
    rightG[i] = numG;
    if(s[i] == 'G') numG++;
  }
  
  int numR = 0;
  for(int i=N-1;i>=0;i--){
    rightR[i] = numR;
    if(s[i] == 'R') numR++;
  }
  
  long long ans = 0;
  
  for(int i=0;i<N-2;i++){
    for(int j=i+1;j<N-1;j++){
      if((s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R')){
        ans += rightB[j];
        if(j + (j - i) < N && s[j + (j - i)] == 'B') ans--;
      }
    }
  }
  
  for(int i=0;i<N-2;i++){
    for(int j=i+1;j<N-1;j++){
      if((s[i] == 'B' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'B')){
        ans += rightR[j];
        if(j + (j - i) < N && s[j + (j - i)] == 'R') ans--;
      }
    }
  }
  
  for(int i=0;i<N-2;i++){
    for(int j=i+1;j<N-1;j++){
      if((s[i] == 'B' && s[j] == 'R') || (s[i] == 'R' && s[j] == 'B')){
        ans += rightG[j];
        if(j + (j - i) < N && s[j + (j - i)] == 'G') ans--;
      }
    }
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3684
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    int d;
    cin >> d;
    switch (d)
    {
    case 25:
        cout << "Christmas" << endl;
        break;
    case 24:
        cout << "Christmas Eve" << endl;
        break;
    case 23:
        cout << "Christmas Eve Eve" << endl;
        break;
    case 22:
        cout << "Christmas Eve Eve Eve" << endl;
        break;

    default:
        break;
    }
    return 0;
}

Measured memory_bytes: 256
import static java.lang.System.*;
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		
		while(true) {
			int n = sc.nextInt();
			if (n == 0) break;
			boolean F = false;
			
			int saving = 0;
			int[] a = new int[12], b = new int[12];
			for (int i=0; i<12; i++) {
				a[i] = sc.nextInt();
				b[i] = sc.nextInt();
			}
			
			for (int i=0; i<12; i++) {
				saving += a[i] - b[i];
				if (saving >= n) {
					out.println(i+1);
					F = true;
					break;
				}
			}
			
			if (!F) out.println("NA");
		}
	}
}



Measured memory_bytes: 44268
/*#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")*/
//#pragma GCC optimize("fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
//#pragma GCC optimize("unroll-loops")
//#define _CRT_SECURE_NO_WARNINGS
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
//#pragma GCC optimize("Ofast,no-stack-protector")
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <math.h>
#include <random>
using namespace std;
typedef long long  ll;
typedef pair<ll, ll> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
#define all(a) a.begin(), a.end()
#define lb(a, x) lower_bound(a.begin(), a.end(), x)
#define pb(x) push_back(x)
#define fr(i, n) for(int i = 0; i < n; ++i)
//typedef cc_hash_table<int, int, hash<int>> hst2;
//typedef cc_hash_table<int, hst2, hash<int>> hst;
typedef pii ord_set_t;
#ifdef ABCD
typedef set<ord_set_t> ordered_set;
int __builtin_popcount(int x)
{
	int cnt = 0;
	for (; x > 0; x >>= 1) cnt += x & 1;
	return cnt;
}

#else
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
mt19937 rnd(239);
using namespace __gnu_pbds;
typedef tree<
	ord_set_t,
	null_type,
	less<ord_set_t>,
	rb_tree_tag,
	tree_order_statistics_node_update>
	ordered_set;
#endif
const int N = 51;
int get_cnt(int n)
{
	int cnt = 0;
	for (; n; n /= 10)++cnt;
	return cnt % 2;
}
int main()
{

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef ABCD
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else

#endif
	int n; cin >> n;
	int cnt = 0;
	for (int i = 1; i <= n; ++i)
	{
		cnt += get_cnt(i);
	}
	cout << cnt;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# 17:46 -> 

from collections import deque

dx = [0,1,0,-1]
dy = [1,0,-1,0]

H, W = map(int, input().split())

grid = []
num_shiro = 0
for i in range(H):
    grid.append(list(input()))
    num_shiro += sum([dot == '.' for dot in grid[i]])

# 最も近道させ、残りに黒マスを塗るのがよき.
# 幅優先探索
grid_queue = deque()
grid_queue.append((0,0))
grid[0][0] = 1

while len(grid_queue) != 0:
    x, y = grid_queue.popleft()
    depth = grid[x][y]
    for k in range(4):
        new_x = x+dx[k]
        new_y = y+dy[k]
        if 0 <= new_x < H and 0 <= new_y < W and \
            grid[new_x][new_y] == '.':
            if (new_x, new_y) == (H-1, W-1):
                print(num_shiro-depth-1)
                exit(0)
            else:
                grid_queue.append((new_x, new_y))
                grid[new_x][new_y] = depth+1

if grid[H-1][W-1] == '.':
    print(-1)
else:
    print(num_shiro-grid[H-1][W-1])

Measured memory_bytes: 9364
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	int N;
  cin >> N;
  vector<int>a(N);
  cin >> a.at(0);
  int done=0;
  for(int i = 1 ; i < N ; i++){
  	cin >> a.at(i);
    done += (a.at(i) - a.at(0));
  }
  
  if(done == 0){
  	cout << 0 << endl;
    return 0;
  }
  
  int min = 1000000;
  int cal = 0;
  
  for(int i = -100 ; i <= 100 ; i++){
  	int y = i;
      for(int j = 0 ; j < N ; j++){
  	 		cal += (y - a.at(j))*(y - a.at(j));
  	  }
    
    if(min > cal)min = cal;
    cal = 0;
  }
  cout << min << endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int h;
        cin >> h;
        if (h >= k) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1 << 29;
const int N =  1e5 + 10;
 
struct IOsetup{
  IOsetup(){
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   cout.tie(nullptr);
   cout << fixed << setprecision(20);
  }
}IO;

int fact[N], inv[N];

struct COMB{
  
  COMB() {};

  int add(int a, int b, int m = MOD){
    a += b;
    if (a >= m)
      a -= m;
    return a;
  }
   
  int mul(int a, int b, int m = MOD){
    return (a * 1ll * b) % m;
  } 
  int powermod(int a, int b, int m = MOD){
    int res = 1ll;
    while (b){
      if (b & 1) res = res * a % m;
      a = a * a % m, b >>= 1;
    }
    return res;
  }

  int modinv(int a){
    return powermod(a, MOD - 2);
  }

  void init_fact(int n, int m = MOD){
    fact[0] = 1, fact[1] = 1;
    for (int i = 2; i <= n; i++){
      fact[i] = fact[i - 1] * i ;
      fact[i] %= m;
    }
    inv[n - 1] = modinv(fact[n - 1]);
    for (int i = n - 2; i >= 0; --i){
      inv[i] = inv[i + 1] * (i + 1);
      inv[i] %= m;
    }
  }

  int fast_nCr(int n, int r, int m = MOD){
    int res = 1ll;
    if (r > n - r) r = n - r;
    for (int i = 0; i < r; i++){
      res = res * (n - i) % m;
      res *= modinv(i + 1);
      res %= m;
    }
    return res;
  }

  int nCr(int n, int r, int m = MOD){
    if (r > n) return 0;
    int num = fact[n];
    num *= inv[r];
    num %= m;
    num *= inv[n - r];
    num %= m;
    return num;
  }
};



int32_t main(){
 COMB node;
 int n, a, b;
 cin >> n >> a >> b;
 int ret = node.powermod(2, n);
 ret %= MOD, ret -= 1;
 ret = (ret - node.fast_nCr(n, a) + MOD) % MOD;
 ret = (ret - node.fast_nCr(n, b) + MOD) % MOD;
 cout << ret << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline void myassert(bool a,string s){ if(!a)cerr<<s<<endl,exit(0);}
inline int read()
{
	int s=0,f=1;char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int maxn=120;

vector<int>ed[maxn];
int n;

inline void init()
{
	n=read();
	REP(i,1,n-1)
	{
		int u=read(),v=read();
		ed[u].push_back(v);
		ed[v].push_back(u);
	}
}

int cir[maxn],ctp;

inline int bfs(int S)
{
	static int dis[maxn],pre[maxn];
	static queue<int>q;
	q.push(S);
	REP(i,1,n)dis[i]=n+1,pre[i]=0;
	dis[S]=0;
	while(!q.empty())
	{
		int u=q.front();q.pop();
		for(int v:ed[u])
		{
			if(dis[v]>dis[u]+1)
				dis[v]=dis[u]+1,pre[v]=u,q.push(v);
		}
	}
	int mx=0,mxid=0;
	REP(i,1,n)if(dis[i]>mx)mx=dis[i],mxid=i;
	ctp=0; for(int x=mxid;x;x=pre[x])cir[++ctp]=x;
	return mxid;
}

ll num;
int vis[maxn];

inline void doing()
{
	int S=bfs(1);
	bfs(S);
	int ans=ctp+1>>1;
	num=1ll<<60;
	if(~ctp&1)
	{
		int L=cir[ctp>>1],R=cir[ctp+2>>1];
		vis[L]=vis[R]=1;
		static int f[maxn]; memset(f,0,sizeof(int)*(n+1));
		REP(i,0,n)f[i]=1;
		int len=ctp>>1;
		function<void(int u,int fa,int dis)>dfs =[&](int u,int fa,int dis) {
			int son=0;
			for(int v:ed[u])
				if(v!=fa && !vis[v])
				{
					++son;
					dfs(v,u,dis+1);	
				}
			chkmax(f[dis],son);
		};
		dfs(L,0,1); dfs(R,0,1);
		ll res=1;
		REP(i,1,len)res*=f[i];
		res*=2;
		num=res;
	}else
	{
		static int f[maxn]; memset(f,0,sizeof(int)*(n+1));
		REP(i,0,n)f[i]=1;
		int len=ctp+1>>1;
		int RT=cir[ctp+1>>1];
		function<void(int u,int fa,int dis)>dfs =[&](int u,int fa,int dis) {
			int son=0;
			for(int v:ed[u])
				if(v!=fa && !vis[v])
				{
					++son;
					dfs(v,u,dis+1);	
				}
			chkmax(f[dis],son);
		};
		dfs(RT,0,1);
		ll res=1;
		REP(i,1,len)res*=f[i];
		chkmin(num,res);


		int L=RT,R;
		REP(i,0,SZ(ed[L])-1)
		{
			R=ed[L][i];
			REP(i,0,n)f[i]=1;
			len=ctp+1>>1;
			dfs(L,R,1); dfs(R,L,1);
			ll res=1;
			REP(i,1,len)res*=f[i];
			chkmin(num,res*2);
		}
	}
	printf("%d %lld\n",ans,num);
}

int main()
{
	init();
	doing();
	return 0;
}


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

using namespace std;

int n;
int x;
int a[100005];
map<int,int> mp;
int ans;

int main()
{
          cin>>n;
          for(int i=0;i<n;i++)
          {
                    cin>>a[i];
                    mp[a[i]]=i;
          }
          sort(a,a+n);
          for(int i=0;i<n;i++)
                    if(i%2!=mp[a[i]]%2)
                              ans++;
          cout<<(ans+1)/2;
}


Measured memory_bytes: 5376
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
#define answer(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int main() {
    string s;
    cin >> s;
    int n = s.size() / 2, ans = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] != s[s.size() - 1 - i]) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>

#define max(a,b) ((a > b) ? a : b)
#define min(a,b) ((a < b) ? a : b)
#define abs(a) ((a < 0) ? -(a) : a)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

static inline int ri() {
	int a;
	scanf("%d", &a);
	return a;
}

int main() {
	int a = ri();
	int b = ri();
	
	const char* ptr;
	if (a <= 8 && b <= 8) ptr = "Yay!";
	else ptr = ":(";
	
	printf("%s", ptr);
	
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int i,j,n,m,a,b,c,rez;
int main()
{
    std::cin.sync_with_stdio(false);
    std::cin.tie(0);
    cin >> a >> b >> c;
    if (a%2==b%2&&b%2==c%2)
    {

    }
    else
    {
        if (a%2+b%2+c%2==2)
        {
            if (a%2==1)
            {
                a++;
            }
            if (b%2==1)
            {
                b++;
            }
            if (c%2==1)
            {
                c++;
            }
        }
        else
        {
            if (a%2==0)
            {
                a++;
            }
            if (b%2==0)
            {
                b++;
            }
            if (c%2==0)
            {
                c++;
            }
        }
        rez++;
    }
    n=max(max(a,b),c);
    rez+=(n-a)/2+(n-b)/2+(n-c)/2;
    cout << rez;
    return 0;
}


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

using namespace std;

#define int long long

void solve() {
    int x;
    cin >> x;
    cout << 360ll / __gcd(360ll, x);
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 3648
#include<stack>
#include<cstdio>
#include<algorithm>

using namespace std;

int calcMaxAreaOfHistgram(int h[],int n)
{
	stack< pair<int,int> > st;

	h[n]=0;
	int amax=0;
	for(int i=0;i<=n;i++){
		if(st.empty() || st.top().second<h[i])
			st.push(make_pair(i,h[i]));
		else if(st.top().second>h[i]){
			int iback,hback;
			do{
				iback=st.top().first;
				hback=st.top().second;
				amax=max(amax,(i-iback)*hback);
				st.pop();
			}while(!st.empty() && st.top().second>h[i]);
			st.push(make_pair(iback,h[i]));
		}
	}

	return amax;
}

int main()
{
	int w,h;
	static int field[501][502];

	while(scanf("%d%d ",&h,&w),h){
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++)	field[i][j]=getchar();
			getchar();
		}

		for(int j=0;j<w;j++)	field[0][j]=field[0][j]=='.';
		for(int i=1;i<h;i++){
			for(int j=0;j<w;j++){
				if(field[i][j]=='*')	field[i][j]=0;
				else	field[i][j]=field[i-1][j]+1;
			}
		}

		int amax=0;
		for(int i=0;i<h;i++)	amax=max(amax,calcMaxAreaOfHistgram(field[i],w));
		printf("%d\n",amax);
	}

	return 0;
}

Measured memory_bytes: 0
import           Control.Applicative
import           Control.DeepSeq
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.IArray             as IA
import qualified Data.Array.IO                 as AI
import qualified Data.Array.MArray             as MA
import qualified Data.Array.ST                 as STA
import qualified Data.Array.Unboxed            as AU
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import qualified Data.Graph                    as G
import           Data.Int
import qualified Data.IntMap                   as IM
import qualified Data.IntSet                   as IS
import           Data.List
import qualified Data.Map.Strict               as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Sequence                 as SQ
import qualified Data.Set                      as S
import           Data.Time
import qualified Data.Tree                     as T
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readInt :: IO Int
readInt = fst . fromJust . BS.readInt <$> BS.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readIntLists :: Int -> IO [[Int]]
readIntLists n = replicateM n readInts

readInteger :: IO Integer
readInteger = fst . fromJust . BS.readInteger <$> BS.getLine

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegerLists :: Int -> IO [[Integer]]
readIntegerLists n = replicateM n readIntegers

readStrings :: IO [String]
readStrings = map BS.unpack . BS.words <$> BS.getLine

readStringLists :: Int -> IO [[String]]
readStringLists n = replicateM n <$> readStrings

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

put :: Show a => a -> IO ()
put = putStr . show

putList :: Show a => [a] -> IO ()
putList [n     ] = print n
putList (n : ns) = do
  put n
  putStr " "
  putList ns

putStrList :: [String] -> IO ()
putStrList [n     ] = putStrLn n
putStrList (n : ns) = do
  putStr n
  putStr " "
  putStrList ns

yesNoUpper b | b         = putStrLn "YES"
             | otherwise = putStrLn "NO"

yesNo b | b         = putStrLn "Yes"
        | otherwise = putStrLn "No"

divCeiling x n | b == 0    = a
               | otherwise = a + 1
  where (a, b) = x `divMod` n

main = do
  n <- readInt
  s <- sort . concat <$> readIntLists n
  print $ solve s

solve s | all (\x -> x `mod` 10 == 0) s = 0
        | su `mod` 10 == 0              = su'
        | otherwise                     = su
 where
  su  = sum s
  su' = su - head (dropWhile (\x -> x `mod` 10 == 0) s)


Measured memory_bytes: 508
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/


int main() {
	
	int n, m, k;
	scanf("%d%d%d", &n, &m, &k);
	printYN(m - n == k - m);
	
	Please AC;
}


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

int n,m;
int a[50],b[50];
int A[51],B[51];

int dp[51][51][51][51][2][2];


int main(){
  cin>>n>>m;
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(a[i]==-1)a[i]=0;
    A[i+1]=A[i]+a[i];
  }
  for(int i=0;i<m;i++){
    cin>>b[i];
    if(b[i]==-1)b[i]=0;
    B[i+1]=B[i]+b[i];
  }
  memset( dp, -1, sizeof(dp));


  for(int x=n;x>=0;x--){
    for(int y=m;y>=0;y--){
      for(int s=x;s>=0;s--){
        for(int t=y;t>=0;t--){
          for(int f=1;f>=0;f--){
            for(int p=1;p>=0;p--){
              
              int &res=dp[x][y][s][t][f][p];

              if(p==0){
                res=-1e9;

                if(f==1 && x==s && y==t){
                  res=max(res,0);
                }else{
                  int nf=(x==s&&y==t);
                  res=max(res,dp[x][y][x][y][nf][1]+A[x]-A[s]-B[y]+B[t]);
                }


                if(x<n && a[x]==0){
                  res=max(res,dp[x+1][y][s][y][0][1]);
                }
                if(x<n && a[x]>0){
                  res=max(res,dp[x+1][y][s][t][0][1]);
                }
    
              }else{
                res=1e9;

                if(f==1 && x==s && y==t){
                  res=min(res,0);
                }else{
                  int nf=(x==s&&y==t);
                  res=min(res,dp[x][y][x][y][nf][0]+A[x]-A[s]-B[y]+B[t]);
                }


                if(y<m && b[y]==0){
                  res=min(res,dp[x][y+1][x][t][0][0]);
                }
                if(y<m && b[y]>0){
                  res=min(res,dp[x][y+1][s][t][0][0]);
                }

              }
            }
          }
        }
      }
    }
  }
  cout<<dp[0][0][0][0][0][0]<<endl;
  return 0;
}

Measured memory_bytes: 108820
N, M = gets.split.map &:to_i
correct = 0
penalty = 0
failed = Array.new(N + 1, 0)
solved = Array.new(N + 1, false)
M.times do
    prob, result = gets.split
    if !solved[prob.to_i]
        if result == "AC"
            correct += 1
            solved[prob.to_i] = true
            penalty += failed[prob.to_i]
        else
            failed[prob.to_i] += 1
        end
    end
end
puts [correct, penalty].join " "

Measured memory_bytes: 3324
#include <iostream>
#include <vector>

using namespace std;

int main(){
  int n, l;
  cin >> n >> l;
  int a[n];
  int sum_a = 0;
  for (int i = 1; i < n+1; i++) {
    a[i] = l + i - 1;
    sum_a += a[i];
  }

  int max_abs = 1000000000;
  int index = 0;
  for (int i = 1; i < n+1; i++) {
    if (max_abs > abs(sum_a - sum_a - a[i])) {
      max_abs = abs(sum_a - sum_a - a[i]);
      index = i;
    }
  }

  cout << sum_a - a[index] << "\n";
}


Measured memory_bytes: 256
using System.Collections.Generic;
using System.Linq;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int F() => int.Parse(ReadLine());
	int[] G() => ReadLine().Split().Select(int.Parse).ToArray();
	public K()
	{
		WriteLine(S());
	}
	long S()
	{
		var N = F();
		var A = G();
		var d = new Dictionary<int, int>();
		foreach (var a in A) if (!d.ContainsKey(-a)) d[-a] = 1; else d[-a]++;
		var e = new SortedDictionary<int, int>();
		foreach (var x in d) if (x.Value >= 4) e[x.Key] = 2; else if (x.Value >= 2) e[x.Key] = 1;
		if (e.Count == 0) return 0;
		var m = e.Keys.First();
		if (e.Count == 1 && e[m] < 2) return 0;
		if (e[m] >= 2) return (long)m * m;
		e.Remove(m);
		return (long)m * e.Keys.First();
	}
}


Measured memory_bytes: 27740
#include<iostream>
#include<string.h>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack> 
#define  ll long long
#define M 1046527
#define L 14
using namespace std;
char H[M][L];

int getChar (char ch)
{
	if(ch=='A')
	return 1;
	else if(ch=='C')
	return 2;
	else if(ch=='G')
	return 3;
	else if(ch=='T')
	return 4;
	else return 0;
}
ll getKey(char str[])
{
	ll sum=0,p=1,i;
	for(i=0;i<strlen(str);i++)
	{
		sum+=p*(getChar(str[i]));
		p=p*5;
	}
	return sum;
}
ll h1(ll key)
{
	return (key%M);
}
ll h2(ll key)
{
	return 1+(key%(M-1));
}
int find(char str[])
{
	ll h,key;
	int i;
	key=getKey(str);
	for(i=0;;i++)
	{
		h=(h1(key)+i*h2(key))%M;
		if(strcmp(H[h],str)==0)
		return 1;
		else if(strlen(H[h])==0)
		return 0;
	}
	return 0;
}
int insert(char str[])
{
	ll h,key;
	int i;
	key=getKey(str);
	for(int i=0;;i++)
	{
		h=((h1(key)+i*h2(key))%M);
		if(strcmp(H[h],str)==0)
		{
		return 1;
	}
		else if(strlen(H[h])==0)
		{
			strcpy(H[h],str);
			return 0;
		 } 
	}
}



int main()
{
int i,n,h;
char str[L],com[9];
for(int i=0;i<M;i++)
H[i][0]='\0';
cin>>n;
for(int i=0;i<n;i++)
{
	memset(str,0,sizeof(str));
	memset(com,0,sizeof(com));
	scanf("%s",com);
	scanf("%s",str);
	if(com[0]=='i')
	{
		insert(str);
	}
	else{
	
	 if(find(str))
	{
		printf("yes\n");
	}
	else
	{
		printf("no\n");
	}
	//cout<<i<<endl;
}
}
return 0;
}



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

public class Problem_C
{
  public static void Main()
  {
    var N = int.Parse(Console.ReadLine());
    var deck = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    long total = 0;
    foreach (var n in deck) total += n;
    long snuke = 0;
    long minDiff = long.MaxValue;
    for (var i = 0; i < N - 1; i++)
    {
      snuke += deck[i];
      minDiff = Math.Min(minDiff, Math.Abs(snuke - (total - snuke)));
    }
    Console.WriteLine($"{minDiff}");
  }
}


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

int main()
{
    int a=0;
    char s[11];
	int l;
  
    // 文字列の入力
    scanf("%s",s);

    // 文字サイズの入力
    l=strlen(s);


for(a = 0 ;l>a;a=a+2){
  if((s[a]=='h')&&(s[a+1]=='i')){

    // 出力
  }else{
    printf("No");
    return 0;
    
}
}
    printf("Yes");
    return 0;

}


Measured memory_bytes: 128
#include<stdio.h>
 
int main(void){
    int a,b,c,i,n=0;
    scanf("%d%d%d",&a,&b,&c);
    for(i=a;i<=b;i++)
        if(c%i==0) n++;
    printf("%d\n",n);
    return 0;
}


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

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define repR(i,s,n) for(ll i = (n-1); i >= (s); i--)
#define repR0(i,n) repR(i,0,n)
#define repR1(i,n) repR(i,1,n+1)

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;
#define fcout cout << fixed << setprecision(18)

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

int a[100];
int cells[100][100]; // r * c

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

  vector<ll> A(N), B(N), C(N);

  rep0(i, N) cin >> A[i];
  rep0(i, N) cin >> B[i];
  rep0(i, N - 1) cin >> C[i];

  ll ans = 0;
  rep0(i, N) {
    ans += B[A[i] - 1];
    if (A[i] + 1 == A[i+1]) ans += C[A[i] - 1];
  }

  cout << ans << BR;
  return 0;
}

Measured memory_bytes: 256
k,n = map(int, input().split())
lst = list(map(int, input().split()))

maxDis = (k-lst[-1]) + lst[0]
for i in range(n-1):
  if lst[i+1] - lst[i] > maxDis:
    maxDis = lst[i+1] - lst[i]
print(k-maxDis)

Measured memory_bytes: 26548