akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
int main() {
  string s;
  cin>>s;
  if(s[2]==s[3] && s[4]==s[5]) cout<<"Yes";
  else cout<<"No";
}


Measured memory_bytes: 3636
n = gets.to_i
as = gets.chomp.split(" ")
nums = []
abss = []
for i in as
  nums.push(i.to_i)
  abss.push(i.to_i.abs)
end


#print abss
flag =  nums.count{|i| i<0}
if flag%2 == 0
  puts abss.inject(:+)
else
  puts abss.inject(:+)-(abss.min*2)
end

Measured memory_bytes: 10740
#include<bits/stdc++.h>
#define MAX 1024
#define inf 1<<29
#define linf 1e16
#define eps (1e-8)
#define mod 1000000007
#define pi acos(-1)
#define phi (1.0+sqrt(5))/2.0
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a)-1;(b)<=i;i--)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,double> pid;
typedef pair<double,int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpi;
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

int n;
int a[MAX];

int main()
{
  while(cin>>n && n){
    FOR(i,0,n)cin>>a[i];
    sort(a,a+n);
    int ans=inf;
    FOR(i,1,n)ans=min(ans,a[i]-a[i-1]);
    cout<<ans<<endl;
  }
  return 0;
}

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

int main() {
  int n;
  while(cin >> n){
    if(n==0) return 0;

    vector<pair<int, int>> v(n);
    v[0].first = 0, v[0].second = 0;

    int xmax=0, xmin=0, ymax=0, ymin=0;
    REP(i, 1, n){
      int m, d;
      cin >> m >> d;
      if(d==0){
        v[i].first = v[m].first-1;
        v[i].second = v[m].second;
      }
      else if(d==1){
        v[i].first = v[m].first;
        v[i].second = v[m].second-1;
      }
      else if(d==2){
        v[i].first = v[m].first+1;
        v[i].second = v[m].second;
      }
      else if(d==3){
        v[i].first = v[m].first;
        v[i].second = v[m].second+1;
      }
      xmax = max(xmax, v[i].first);
      xmin = min(xmin, v[i].first);
      ymax = max(ymax, v[i].second);
      ymin = min(ymin, v[i].second);
    }
    cout<<xmax-xmin+1<<" "<<ymax-ymin+1<<endl;
  }
  return 0;
}


Measured memory_bytes: 3112
#include<stdio.h>
int main(){
	int a,b,c;
	while(scanf("%d%d%d",&a,&b,&c)!=EOF){
		if(a<1||b<1||c<1||a>100||b>100||c>100) continue;
		if(a-b==b-c)
				printf("YES");
		else	printf("NO");
	}
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>
using namespace std;
 
int main() {
   string a;
   int n;
   cin >> n;
   cin >> a;
   for(int i = 0;i< a.length();i++){
     int baka = a[i]+n;
     if(baka >90) baka= baka-26;
     char aho = baka;
     cout<<aho;
   
   }
    return 0;
}

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

typedef pair<int,int> P;
const int INF = 1e+8;
const int MAX_V = 101;
const int MAX_C = 21;
const int MAX_P = 55;

// 辺
struct edge{
	int to, d, c;
	edge(int to_, int d_, int c_){
		to = to_; d = d_; c = c_;
	}
};
// グラフ
vector<edge> G[MAX_V];

// 入力
int p[MAX_C];
int q[MAX_C][MAX_P];
int r[MAX_C][MAX_P];

// cost[j][z] := 鉄道会社 j の距離 z の運賃を返す.
int cost[MAX_C][20001];
// memo[i] := ノード i が探索済みかどうか
bool memo[MAX_V];
// ゴールに辿りつけるかどうか
bool is_ans;
// wf[c][i][j] := 鉄道会社 c のみの (i,j)間の最小距離 
int wf[MAX_C][MAX_V][MAX_V];
// fare[i][j] := (i,j)間の最小の運賃
int fare[MAX_V][MAX_V];

// 初期化
void ini(){
	is_ans = false;
	for(int i=0 ; i < MAX_V ; i++ ){
		G[i].clear();
		memo[i] = false;
	}
	for(int i=0 ; i < MAX_C ; i++ ){
		for(int j=0 ; j < 20001 ; j++ ){
			cost[i][j] = 0;
		}
		for(int a=0 ; a < MAX_V ; a++ ){
			for(int b=0 ; b < MAX_V ; b++ ){
				wf[i][a][b] = (a == b)? 0 : INF;
			}
		}
	}
	for(int a=0 ; a < MAX_V ; a++ ){
		for(int b=0 ; b < MAX_V ; b++ ){
			fare[a][b] = (a == b)? 0 : INF;
		}
	}
}

// 辺の追加
void add_edge(int u, int v, int d, int c){
	wf[c][u][v] = wf[c][v][u] = min( d , wf[c][u][v] );
	edge e(v,d,c);
	G[u].push_back( e );
	e.to = u;
	G[v].push_back( e );
}

// スタートからゴールに辿りつけるかDFSで調べる.
void is_impossible(int u, int g){
	if( u == g ) is_ans = true;
	
	memo[u] = true;
	for(int i=0 ; i < G[u].size() ; i++ ){
		int v = G[u][i].to;
		if( !memo[v] ){
			is_impossible(v,g);
		}
	}
}

int solve(int n, int c, int s, int g){
	// ワーシャルフロイドで同じ鉄道会社について最短距離を求めておく.
	for(int c_ = 0 ; c_ < c ; c_++ ){
		for(int k=0 ; k < n ; k++ ){
			for(int i=0 ; i < n ; i++ ){
				for(int j=0 ; j < n ; j++ ){
					wf[c_][i][j] = min( wf[c_][i][j] , wf[c_][i][k] + wf[c_][k][j] );
				}
			}
		}
	}
	// 求めた距離から任意の(i,j)について運賃を計算しておく.
	for(int c_ = 0 ; c_ < c ; c_++ ){
		for(int i=0 ; i < n ; i++ ){
			for(int j=0 ; j < n ; j++ ){
				if( wf[c_][i][j] == INF ) continue;
				fare[i][j] = min( fare[i][j] , cost[c_][wf[c_][i][j]] );
			}
		}
	}
	// ワーシャルフロイドで任意の(i,j)間の最小の運賃を計算する.
	for(int k=0 ; k < n ; k++ ){
		for(int i=0 ; i < n ; i++ ){
			for(int j=0 ; j < n ; j++ ){
				fare[i][j] = min( fare[i][j] , fare[i][k] + fare[k][j] );
			}
		}
	}
	return fare[s][g];
}

int main(){
	int n, m, c, s, g;
	while( cin >> n >> m >> c >> s >> g , n ){
		ini();
		s--; g--;
		
		for(int i=0 ; i < m ; i++ ){
			int x, y, d, c_;
			cin >> x >> y >> d >> c_;
			x--; y--; c_--;
			add_edge( x , y , d , c_ );
		}
		for(int i=0 ; i < c ; i++ ){
			cin >> p[i];
		}
		for(int j=0 ; j < c ; j++ ){
			q[j][0] = 0;
			for(int k=1 ; k < p[j] ; k++ ){
				cin >> q[j][k];
			}
			q[j][p[j]] = INF;
			for(int k=1 ; k <= p[j] ; k++ ){
				cin >> r[j][k];
			}
			int k=1;
			cost[j][0] = 0;
			for(int z=1 ; z < 20001 ; z++ ){
				if( q[j][k-1]+1 <= z && z <= q[j][k] ){
					cost[j][z] += cost[j][z-1] + r[j][k];
				}else{
					k++;
					cost[j][z] += cost[j][z-1] + r[j][k];
				}		
			}
		}
		
		// ゴールに辿りつけるかチェック
		is_impossible(s,g);
		if( is_ans ){
			int ans = solve(n, c, s, g);
			cout << ans << endl;
		}else{
			cout << -1 << endl;
		}
	}
}

Measured memory_bytes: 4336
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace P_AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            //1st judge
            if (input[0] != 'A')
            {
                Console.WriteLine("WA");
                return;
            }
            //2nd judge
            var checkC = input.Skip(2).Take(input.Length - 3);
            if (!checkC.Any(x => x == 'C'))
            {
                Console.WriteLine("WA");
                return;
            }

            //3rd judge
            var useA = false;
            var useC = false;
            for (int index = 0; index < input.Length; index++)
            {
                if (char.IsUpper(input[index]))
                {
                    if (input[index] == 'A')
                    {
                        if (useA)
                        {
                            Console.WriteLine("WA");
                            return;
                        }
                        useA = true;
                    }
                    else if (input[index] == 'C')
                    {
                        if (useC)
                        {
                            Console.WriteLine("WA");
                            return;
                        }
                        useC = true;
                    }
                    else
                    {
                        Console.WriteLine("WA");
                        return;
                    }
                }
            }

            Console.WriteLine(useA && useC ? "AC" : "WA");
        }
    }
}

Measured memory_bytes: 13268
#include<stdio.h>
int main(void)
{
	int N,K,X,Y;
	scanf("%d %d %d %d",&N,&K,&X,&Y);
	if(N<=K){
		printf("%d\n",N*X);
	}
	else{
		printf("%d\n",K*X+(N-K)*Y);
	}
	return 0;
}

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

using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const ll LINF = 1e18;
const ll MOD = 86400;
const int INF = 1e9;
double EPS = 1e-8;

struct Edge
{
	int to;
	ll cost;
};

ll d[100010];
vector<Edge> es[100010];

int E, V;

int main(){
	int start;
	cin>>V>>E>>start;
	rep(i, E){
		int s, t, d;
		cin>>s>>t>>d;
		es[s].pb({t, d});
	}
	
	auto dijkstra = [&]{
		typedef pair<ll, int> P;
		priority_queue<P, vector<P>, greater<P> > q;
		P p;
		rep(i, V) d[i] = 1e18;
		q.push({0, start});
		d[start] = 0;
		while(!q.empty()){
			p = q.top();
			int from = p.se;
			ll cost = p.fi;
			q.pop();
			if(d[from] < cost) continue;
			for(auto&e :es[from]){
				int to = e.to;
				ll newCost = cost + e.cost;
				if(d[to] > newCost){
					d[to] = newCost;
					q.push({newCost, to});
				}
			}
		}
	};
	dijkstra();
	for(int i = 0; i < V; i++){
		if(d[i] == 1e18) cout<<"INF"<<endl;
		else cout<<d[i]<<endl;
	}
}

Measured memory_bytes: 19508
def is_consistent(bit, t_tuple):
    mask, tf = t_tuple
    if (bit & mask) == (tf & mask):
        return True
    else:
        return False

n = int(input())
testimony = [0] * n
for i in range(n):
    mask, tf = 0, 0
    for j in range(int(input())):
        x, y = map(int, input().split())
        mask += 1 << (x - 1)
        tf += y << (x - 1)
    testimony[i] = (mask, tf)

max_honest = 0
for bit in range(1 << n):
    honest = 0
    all_consistence = True
    for shift in range(n):
        if ((bit >> shift) & 1):
            if is_consistent(bit, testimony[shift]):
                honest += 1
            else:
                all_consistence = False    
    if all_consistence and (max_honest < honest):
        max_honest = honest
print(max_honest)

Measured memory_bytes: 3064
import math

# 入力
a, b, h, m = map(int, input().split())

# 処理
rad = math.pi / 180
hour = 30 * h + m / 2
minute = 6 * m
arg = min(abs(hour - minute), 360 - abs(hour - minute))
ans = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(rad * arg))

# 出力
print(ans)

Measured memory_bytes: 62456
#include <stdio.h>

int main(){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

    if(y-r < 0 || y+r > H || x-r < 0 || x+r > W) printf("No\n");
    else printf("Yes\n");
}



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

int main() {
	
	string s; cin >> s;
	if (s[s.size() - 1] != 's') {
		s += "s";
	}
	else {
		s += "es";
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

#define MOD 1000000007

int main()
{
  int n, k;
  cin >> n >> k;
  vector<double> dp = {};
  dp.resize(n, 0);

  for (auto i = 0; i < n; i++)
  {
    double p;
    cin >> p;

    if (i == 0)
    {
      dp[i] = (1 + p) / 2;
    }
    else
    {
      dp[i] = dp[i - 1] + ((1.0 + p) / 2);
    }
  }

  double cur_max = -1;
  for (auto i = -1; i + k < n; i++)
  {
    double ans;
    if (i == -1)
      ans = dp[i + k];
    else
      ans = dp[i + k] - dp[i];

    if (cur_max < ans)
    {
      cur_max = ans;
    }
  }
  std::cout << std::fixed;
  cout << std::setprecision(9) << cur_max << endl;
  return 0;
}


Measured memory_bytes: 1920
#include <fstream>
#include <string>
#include <iostream>
#include <math.h>
#include <algorithm>
#include<bits/stdc++.h>
#include <vector>
using namespace std;
string s;
int main(){
    cin >> s;
    int n = s.size();
    int pot = 1;
    int prevsuf = 0;
    int suf[n];
    map<int, int> sfx;
    long long answer = 0;
    for (int x = n - 1; x >= 0; x--){
        int digit = s[x] - '0';
        suf[x] = (digit * pot + prevsuf) % 2019;
        pot = (10 * pot) % 2019;
        auto it = sfx.find(suf[x]);
        if (it != sfx.end()){
            answer += it -> second;
            sfx[suf[x]] += 1;
        }
        else{
            sfx.insert(make_pair(suf[x], 1));
        }
        if (suf[x] == 0){
            answer += 1;
        }
        prevsuf = suf[x];
    }
    cout << answer << "\n";
}


Measured memory_bytes: 4516
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define ll long long
#define P pair<int, int>

using namespace std;

int N, M, R;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N >> M >> R;
  vector<int> r(R);
  rep(i, R) {
    cin >> r.at(i);
  }

  ll graph[205][205];
  rep(i, 205) {
    rep(j, 205) {
      graph[i][j] = LONG_MAX/2;
    }
  }

  rep(i, M) {
    int a, b, c;
    cin >> a >> b >> c;
    graph[a][b] = c;
    graph[b][a] = c;
  }

  for(int k=1; k<=N; k++) {
    for(int i=1; i<=N; i++) {
      for(int j=1; j<=N; j++) {
        graph[i][j] = min(graph[i][k] + graph[k][j], graph[i][j]);
      }
    }
  }

  sort(r.begin(), r.end());
  ll ans = LONG_MAX;

  do {
    ll sum = 0;
    for(int i=0; i<R-1; i++) {
      sum += graph[r.at(i)][r.at(i+1)];
    }
    ans = min(ans, sum);
  } while (next_permutation(r.begin(), r.end()));

  cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#define REP(i,n) for(int i = 0; n > i; i++)
#define MOD 1000000007
#define accm(i) ( (i)%2 ? od[((i)-1)/2] : ev[(i)/2])
#define acc(i) ( i%2 ? cpod[(i-1)/2] : cpev[i/2])
using namespace std;
typedef vector<int> Ivec;
typedef pair<int, int> pii;
typedef long long int ll;
int main() {
	ll a, b, c;
	scanf("%lld %lld %lld", &a, &b, &c);
	if (!(a % 2) || !(b % 2) || !(c % 2)) printf("0\n");
	else {
		priority_queue<ll,vector<ll>,greater<ll>> ls;
		ls.push(a*b);
		ls.push(a*c);
		ls.push(b*c);

		printf("%lld\n", ls.top());
	}
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;


vector<string>cs{
	" ",
	"',.!?",
	"abcABC",
	"defDEF",
	"ghiGHI",
	"jklJKL",
	"mnoMNO",
	"pqrsPQRS",
	"tuvTUV",
	"wxyzWXYZ",

};

int main() {
	string st;
	while (cin >> st) {
		vector<pair<int, int>>vs;
		int from = -1;
		int num = 0;
		st.push_back('z');
		for (int i = 0; i < st.size(); ++i) {
			int n = st[i] - '0';
			if (from == n) {
				num++;
			}
			else {
				if (num) {
					vs.push_back(make_pair(from, num));
				}
				num = 1;
			}
			from = n;
		}
		for (int i = 0; i < vs.size(); ++i) {
			if (vs[i].first) {
				int k = (vs[i].second-1)%cs[vs[i].first].size();

				cout << cs[vs[i].first][k];
			}
			else {
				for (int j = 0; j < vs[i].second - 1; ++j) {
					cout << ' ';
				}
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 2976
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n=sc.nextInt();
			if(n==0) break;
			int[][] input = new int[n-1][2];
			int[] data = {-1,-1,1,1};
			int[][] map = new int[n][2];
			int xmin=0,xmax=0,ymin=0,ymax=0;
			for(int i=0;i<n-1;++i){
				input[i][0]=sc.nextInt();
				input[i][1]=sc.nextInt();
				if(input[i][1]==0){
					map[i+1][0]=map[input[i][0]][0]+data[input[i][1]];
					map[i+1][1]=map[input[i][0]][1];
				}
				else if(input[i][1]==1){
					map[i+1][0]=map[input[i][0]][0];
					map[i+1][1]=map[input[i][0]][1]+data[input[i][1]];
				}
				else if(input[i][1]==2){
					map[i+1][0]=map[input[i][0]][0]+data[input[i][1]];
					map[i+1][1]=map[input[i][0]][1];
				}
				else{
					map[i+1][0]=map[input[i][0]][0];
					map[i+1][1]=map[input[i][0]][1]+data[input[i][1]];
				}
				if(xmin>map[i+1][0]) xmin=map[i+1][0];
				if(xmax<map[i+1][0]) xmax=map[i+1][0];
				if(ymin>map[i+1][1]) ymin=map[i+1][1];
				if(ymax<map[i+1][1]) ymax=map[i+1][1];
			}
			System.out.println((xmax-xmin+1)+" "+(ymax-ymin+1));
		}
	}
}



Measured memory_bytes: 42368
#include<iostream>
#include<cstdio>
#define int long long
using namespace std;
const int N=2e5+10;
int n,a[N],t[N],ans;
int C(int x)
{
	return x*(x-1)/2;
}
signed main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]),t[a[i]]++;
	for(int i=1;i<N;i++)
		if(t[i]>=2) ans+=C(t[i]);
	for(int i=1;i<=n;i++)
	{
		if(t[a[i]]<2) printf("%lld\n",ans);
		else printf("%lld\n",ans-(C(t[a[i]])-C(t[a[i]]-1)));
	}
	return 0;
}

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

int main() {
	int n; cin >> n;
	vector<int>v(n), c(n);
	for (int i = 0; i < n; i++)cin >> v[i];
	for (int i = 0; i < n; i++) cin >> c[i];

	vector<int>val(n);
	for (int i = 0; i < n; i++) val[i] = v[i] - c[i];
	int ans = 0;
	for (auto x : val) if (x > 0)ans += x;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i,n) for (ll i=0;i<(ll)(n);i++)
using namespace std;
int main(){
  int n;
  cin>>n;
  pair<int,int> a[100020],b[100020];
  rep(i,100020){
    a[i].first=0;
    a[i].second=i;

    b[i].first=0;
    b[i].second=i;
  }
  rep(i,n){
    int t;
    cin>>t;
    if(i%2==0){
      a[t].first++;
    }else{
      b[t].first++;
    }
  }
  sort(a,a+100020,greater<pair<int,int> >());
  sort(b,b+100020,greater<pair<int,int> >());
  //cout<<a[0].second<<","<<b[0].second<<endl;
  if (a[0].second==b[0].second){
    cout<<min((n-a[0].first-b[1].first),(n-a[1].first-b[0].first))<<endl;;
  }else{
      cout<<(n-a[0].first-b[0].first)<<endl;
  }
  return 0;
}


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

#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define MAX 1e9
#define MIN -1e9
#define mod 1000000007
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define mxn 100005
using namespace std;

int main()
{
    FLASH
    ll n,q;
    cin >> n;
    ll a[n];
    map<ll,ll> mp;
    ll sum = 0;
    for(int i = 0; i < n; i++)
        cin >> a[i],mp[a[i]]++,sum += a[i];
    cin >> q;
    while(q--)
    {
        ll b,c;
        cin >> b >> c;
        ll k = mp[b];
        sum -= (k * b);
        sum += (k * c);
        mp[c] += mp[b];
        mp[b] = 0;
        cout << sum << '\n' ;
    }
    return 0;
}



Measured memory_bytes: 10256
#include<stdio.h>
int main(void)
{
	int n,i,a[10001],b,j,c;

	scanf("%d",&n);
	while(n!=0){
		b=0;
		j=0;
		for(i=1;i<=n;i++){
			scanf("%d",&a[i]);
				if(a[i]>=2){
					b=1;
				}
				else if(a[i]==0){
					j++;
				}
			}
		if(b==0){
			printf("NA\n");
		}
		else {
			c=n-j+1;
			printf("%d\n",c);
		}
		scanf("%d",&n);
	}
	return 0;
}

Measured memory_bytes: 1076
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
ll n,D[100005][3],mod=1e9+7;
vector < int > v[100005];
void Dfs(int x,int p) {
	D[x][0]=D[x][1]=1;
	for (int i=0; i<v[x].size(); i++) {
		int to=v[x][i];
		if (to==p) continue;
		Dfs(to,x);
		D[x][0]=(D[x][0]*D[to][1])%mod;
		D[x][1]=(D[x][1]*((D[to][0]+D[to][1])%mod))%mod;
	}
}
main () {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	for (int i=1; i<n; i++) {
		int a,b;
		cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
	}
	Dfs(1,1);	
	cout<<(D[1][0]+D[1][1])%mod<<endl;
}

Measured memory_bytes: 14976
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = 0
s = sum(b)
for i in range(n-1):
  if a[i] + 1== a[i+1]:
    d += c[a[i]-1]

print(d+s)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
 
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> flag(256, 0);
  for(int i = 0; i < N; i++) {
    char a; cin >> a; flag[a] = 1;
  }
  int cnt = 0;
  for(int i = 0; i < 256; i++) cnt += flag[i];
  if (cnt == 3) cout << "Three" << endl;
  else cout << "Four" << endl; 
  return 0;
}

Measured memory_bytes: 384
h, w, a, b = map(int, input().split())

l1 = '0' * a + '1' * (w - a)
l2 = '1' * a + '0' * (w - a)
for i in range(b):
	print('{}'.format(l1))
for i in range(h-b):
	print('{}'.format(l2))

Measured memory_bytes: 3956
#include <stdio.h>

int count(int a, int b){
  int t;
  scanf("%d", &t);
  return((t < a || b <= t) ? 1 : 0);
}

int attendable(){
  int n, a, b;
  int i;
  int ans;

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

  ans = 0;
  for (i = 0; i < n; i++)ans += count(a, b);

  return(ans);
}

int main(void){
  printf("%d\n", attendable());
  return(0);
}

Measured memory_bytes: 128
a,b,c,k = map(int, input().split())
cheak = 10**18
key = a-b
def calc(a,b,c,k):
    if a == b:
        return 0
    elif key < 0:
        if k % 2 == 1:
            return -key
        else:
            return key
    else:
        if k % 2 == 1:
            return -key
        else:
            return key
ans = calc(a,b,c,k)
if ans > cheak:
    print("Unfair")
else:
    print(ans)


Measured memory_bytes: 3060
s = input()

n = len(s)

first = s[0:int((n-1)/2)]
first_n = len(first)
second = s[int((n+3)/2 - 1):]
second_n = len(second)
flag = True

for sn in range(int(n/2)):
    if not s[sn] == s[-sn-1]:
        flag = False

for sn in range(int(first_n/2)):
    if not first[sn] == first[-sn-1]:
        flag = False

for sn in range(int(second_n/2)):
    if not second[sn] == second[-sn-1]:
        flag = False

if flag:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
n = int(input())
#0,n-1が空席かどうかを確認する
print(0)
start = input()
if start == 'Vacant':
    print(0)
    exit()
print(n-1)
last = input()
if last == 'Vacant':
    print(n-1)
    exit()
left_seat = start
right_seat = last
def binary_search(left, right):
    global left_seat
    global right_seat
    mid = (left+right) // 2
    print(mid)
    query = input()
    num = mid - left
    #numの偶奇により判定
    if query == 'Vacant':
        exit()
    if num % 2 == 0:
        if query == left_seat:
            left_seat = query
            binary_search(mid,right)
        else:
            binary_search(left,mid)
    else:
        if query == left_seat:
            binary_search(left,mid)
        else:
            left_seat = query
            binary_search(mid,right)
binary_search(0,n-1)

Measured memory_bytes: 3660
function gets(str){
  this._s = str.split("\n");
  this._y = 0;
};
gets.prototype = {
  a: function(f){
    var s = this._s, y = this._y, r;
    if(typeof s[y] === "string")s[y] = s[y].split(" ").reverse();
    r = s[y].pop();
    if(!s[y].length)this._y++;
    return f?r:+r;
  },
  l: function(f){
    var s = this._s, y = this._y;
    s[y] = typeof s[y] === "string" ? s[y].split(" ") : s[y].reverse();
    this._y++;
    return f?s[y]:s[y].map(a=>+a);
  },
  m: function(n,f){
    var s = this._s, y = this._y, r = [], i = 0;
    if(f)for(;i < n; i++)r[i] = s[y+i].split(" ");
    else for(;i < n; i++)r[i] = s[y+i].split(" ").map(a=>+a);
    this._y += n;
    return r;
  },
};

var mod = 1e9 + 7;
function abmod(){var a=arguments,r=a[0],i=1;for(;i<a.length;)r=((r>>16)*a[i]%mod*65536+(r&65535)*a[i++])%mod;return r;}
function powmod(a,n){var r=1;while(n){if(n&1)r=abmod(a,r);a=abmod(a,a);n>>=1;}return r;}

var o = new gets(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var n = o.a(), a = o.l();
  a.sort((a,b)=>a-b);
  var l = n % 2 ? 0 : 1;
  var r = (1 - l) * 2;
  for(var i = 0; i < n; i++){
    if(a[i] !== l)return 0;
    l += r;
    r = 2 - r;
  }
  return powmod(2, n >> 1);
}

Measured memory_bytes: 17364
import sys

# sys.stdin = open('a1.in')

N = 10 ** 5
M = 10 ** 9 + 7


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


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve(n, m):
    if abs(n - m) > 1:
        return 0
    res = f[m] * f[n]
    res %= M
    if m == n:
        res *= 2
        res %= M
    return res


f = [1] * (N + 1)
for i in range(1, N + 1):
    f[i] = i * f[i - 1]
    f[i] %= M

n, m = read_int_list()
res = solve(n, m)
print(res)


Measured memory_bytes: 6900
#include<iostream>
using namespace std;
#define lli long long int
#include<math.h>
#include<iomanip>
int main(){
  int n,l,flag=0,i;
  cin>>n>>l;
  int v[n+1];
  v[0]=0;
  for(i=1;i<=n;i++){
    int a;cin>>a;
    v[i]=v[i-1]+a;
    if(v[i]>l){
      flag=1;
      break;
    }
  }
  
  cout<<i;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int l,s,ans=0;
	cin>>l>>s;
	for(int i=0;i<=l;i++)
	{
		for(int j=0;j<=l;j++)
		{
			int k=s-i-j;
			if(k<=l && k>=0)
				ans++;
		}
	}
	cout<<ans;
	return 0;
}

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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

signed main(){
    int N, C; cin>>N>>C;
    vector<vector<int>> D(C, vector<int>(C));
    vector<vector<int>> c(N, vector<int>(N));
    rep(i,C){
        rep(j,C){
            cin>>D.at(i).at(j);
        }
    }
    rep(i,N){
        rep(j,N){
            cin>>c.at(i).at(j);
        }
    }

    vec_int iwakan0(C,0); // (X+Y)%3=0のマスを色iにしたときの違和感の合計
    vec_int iwakan1(C,0);
    vec_int iwakan2(C,0);

    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            for(int k=0;k<C;k++){
                int color = c.at(i).at(j)-1;
                if((i+j)%3==0){
                    iwakan0.at(k) += D.at(color).at(k);
                }else if((i+j)%3==1){
                    iwakan1.at(k) += D.at(color).at(k);
                }else{
                    iwakan2.at(k) += D.at(color).at(k);
                }
            }
        }
    }
    /*
    int min0 = INT_MAX;
    int min1 = INT_MAX;
    int min2 = INT_MAX;
    rep(i,C){
        if(min0>iwakan0.at(i)){
            min0=iwakan0.at(i);
        }
        if(min1>iwakan1.at(i)){
            min1=iwakan1.at(i);
        }
        if(min2>iwakan2.at(i)){
            min2=iwakan2.at(i);
        }
    }
    cout<<min0+min1+min2<<endl;
    */
   int min = INT_MAX;
   for(int i=0;i<C;i++){
   for(int j=0;j<C;j++){
       if(i==j)continue;
   for(int k=0;k<C;k++){
       if(i==k || j==k)continue;
       int temp = iwakan0.at(i)+iwakan1.at(j)+iwakan2.at(k);
       if(min>temp)min=temp;

   }
   }
   }
   cout<<min<<endl;

    return 0;
}

Measured memory_bytes: 5592
week = str(input())

if week == "SUN":
    print(7)
elif week == "MON":
    print(6)
elif  week == "TUE":
    print(5)
elif  week == "WED":
    print(4)
elif  week == "THU":
    print(3)
elif  week == "FRI":
    print(2)
else:
    print(1)

Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<tuple>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

const ll mod = 1e9+7;
const ll INF = ll(1e18)+1;
const ll MAXN = 1e6;

const int MAX=510000;

int main()
{
    int n,a,b;
    cin>>n>>a>>b;
    cout<<min(b,n*a);
}

Measured memory_bytes: 256
object Main extends App {
	val Array(n, m) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
	val mod = 1000000007L
	val swich = math.abs(n - m)
	if(swich >= 2) println(0)
	else if(swich == 1){
		println((f(n)*f(m))%mod)
	}else{
		println((2L*f(n)*f(m))%mod)
	}

	def f(x: Int): Long = Range(1, x+1).map(_ * 1L).reduce((a,b) => (a*b)%mod)
} 


Measured memory_bytes: 38880
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 3000000
int a[N],b[N],c[N],d[N],n,m,e[4];

int main() {
  cin>>n>>m>>e[0]>>e[1]>>e[2]>>e[3];
  a[0]=e[0];
  for(ll i=1;i<n;i++)a[i]=(a[i-1]*58+e[1])%(m+1);
  b[0]=e[2];
  for(ll i=1;i<m;i++)b[i]=(b[i-1]*58+e[3])%(n+1);
  for(ll i=0;i<m;i++)c[b[i]]++;
  for(ll i=n-1;i>=0;i--)c[i]+=c[i+1];
  for(ll i=0;i<n;i++)d[a[i]]++;
  ll x=0,ans=0,i=1;
  for(ll j=m;j>=0;j--) {
    while(d[j]--) {
      ll k=min(j,x+c[i]);
      ans+=k;
      x+=c[i]-k;
      i++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 42168
#include <stdio.h>

int main(void)
{
  int n, m, p, cor = 0, pen = 0;
  char s[3];
  int cnt[100005] = {};
  scanf("%d%d", &n, &m);
  
  for(int i = 0; i < m; i++) {
    scanf("%d%s", &p, &s);
    if (cnt[p] == -1)
      continue;
    if (s[0] == 'A') {
      cor++;
      pen += cnt[p];
      cnt[p] = -1;
    } else
      cnt[p]++;
  }
  
  printf("%d %d\n", cor, pen);
  
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,c;cin>>n>>k>>c;
	string s;cin>>s;

	int a[k]={},b[k]={};

	for(int i=0,j=0;i<n&&j<k;i++)
		if(s[i]=='o')
			a[j++]=i,i+=c;
		
	for(int i=n-1,j=k-1;i>=0&&j>=0;i--)
		if(s[i]=='o')
			b[j--]=i,i-=c;

	for(int i=0;i<k;i++)
		if(a[i]==b[i])
			cout<<a[i]+1<<"\n";

	return 0;
}

Measured memory_bytes: 3332
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main() {
  ll N = 0;
  cin >> N;
  vector<ll>A(N);
  rep(i,N){
    cin >> A[i];
  }
  if(N % 2 != 0){
    cout << "0";
    return 0;
  }
  sort(A.begin(), A.end()); //小さい順
  if(A[N/2-1] == A[N/2]){
    cout << "0";
  }
  else{
    cout << A[N/2] - A[N/2 - 1];
  }
}
  

Measured memory_bytes: 1024
while True:
    h, w = map(int, input().split())
    if h == 0 and w == 0:
        break
    for j in range(h):
        for i in range(w):
            if j == 0 or i == 0 or j == h-1 or i == w-1:
                print("#", end="")
            else:
                print(".", end="")
        print()
    print()    


Measured memory_bytes: 7008
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G;
		int A = I[0], B = I[1], K = I[2];
		var c = new int[] { A, B };
		for (var i = 0; i < K; i++)
		{
			var j = i & 1;
			c[j] >>= 1;
			c[1 - j] += c[j];
		}
		WriteLine($"{c[0]} {c[1]}");
	}
}


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

#define IOS                               \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);
#define int long long int
#define endl "\n"
#define sz(a) (int)((a).size())
#define all(a) a.begin(), a.end()

const int N = 500009;
const int mod = 1000000007;

int a,b;

void pre()
{
}

int32_t main()
{
	IOS;
	pre();
	cin>>a>>b;
	if(1<=a&&a<=9 && 1<=b&&b<=9)
		cout<<(a*b);
	else
		cout<<-1;
}	

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.GregorianCalendar;
import java.util.Calendar;

class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		
		while (true)
		{
			int m = sc.nextInt();
			int d = sc.nextInt();
			
			if (m == 0) break;
			
			GregorianCalendar cal = new GregorianCalendar();
			cal.set(2004, m-1, d);
			switch (cal.get(Calendar.DAY_OF_WEEK))
			{
				case Calendar.SUNDAY:
					System.out.println("Sunday");
					break;
				case Calendar.MONDAY:
					System.out.println("Monday");
					break;
				case Calendar.TUESDAY:
					System.out.println("Tuesday");
					break;
				case Calendar.WEDNESDAY:
					System.out.println("Wednesday");
					break;
				case Calendar.THURSDAY:
					System.out.println("Thursday");
					break;
				case Calendar.FRIDAY:
					System.out.println("Friday");
					break;
				case Calendar.SATURDAY:
					System.out.println("Saturday");
					break;
			}
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>

using namespace std;
typedef long long ll;

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

Measured memory_bytes: 256
#!/usr/bin/env python3
import math

movable = 0
h, w = map(int, input().split())

# 二列ごと見ると全体の半数に移動可能
if h ==1 or w == 1:
    movable = 1
else:
    movable = math.ceil((h * w)/2)

print(movable)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int A,B;
    cin >> A >> B;
    if(A >= 13)cout << B << endl;
    else if(A >= 6)cout << B/2 << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 256
import sys


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, K = map(int, input().split())
    P = list(map(int, input().split()))
    C = list(map(int, input().split()))


    maxscore = -10 ** 9 - 10
    for i in range(N):
        vis_val = [-10 ** 10] * N
        vis_time = [0] * N
        score = 0
        current = i
        k = 1
        flag=0
        while k <= K:
            current = P[current] - 1
            score += C[current]
            if vis_time[current]:
                if score - vis_val[current] <= 0:
                    roopmax = max(vis_val)
                    flag=1
                    break
                else:

                    one_cicle = k - vis_time[current]
                    one_val = score - vis_val[current]
                    rem = (K - k) // one_cicle
                    score += rem * one_val
                    k += one_cicle *rem
                    roopmax = score
                    k+=1
                    while k <= K:
                        current = P[current] - 1
                        score += C[current]
                        roopmax = max(roopmax, score)
                        k+=1
                        flag=1

            vis_val[current] = score
            vis_time[current] = k
            k += 1
        if flag==0:
            roopmax=max(vis_val)

        maxscore = max(roopmax, maxscore)

    print(maxscore)

if __name__ == "__main__":
    main()


Measured memory_bytes: 76296
#include <iostream>

using namespace std;


int main() {

  int n;
  int p_a,p_b;


  while(cin >> n,n) {

    p_a=p_b=0;

    for(int i=0;i<n;i++) {

      int a,b;

      cin >> a >> b;

      if(a>b) p_a+=a+b;

      else if(a==b) {

	p_a+=a;
	p_b+=b;

      }

      else p_b+=a+b;

    }

    cout << p_a << " " << p_b << endl;

  }

  return 0;

}

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

using namespace std;

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

  int n, m;
  cin >> n >> m;

  // vector<bool> ok(m, true);

  // for (int i = 0; i < n; ++i) {
  //   int k;
  //   cin >> k;
  //   vector<bool> a(m, false);
  //   for (int j = 0; j < k; ++j) {
  //     int idx;
  //     cin >> idx;
  //     a[idx - 1] = true;
  //   }
  //   for (int j = 0; j < m; ++j) {
  //     ok[j] = ok[j] && a[j];
  //     // cerr << ok[j] << " ";
  //   }
  //   // cerr << '\n';
  // }

  // int cnt = 0;
  // for (int i = 0; i < m; ++i) {
  //   if (ok[i]) {
  //     ++cnt;
  //   }
  // }

  vector<int> cnt(m, 0);
  for (int i = 0; i < n; ++i) {
    int k;
    cin >> k;
    for (int j = 0; j < k; ++j) {
      int a;
      cin >> a;
      ++cnt[a - 1];
    }
  }

  int ans = 0;
  for (int i = 0; i < m; ++i) {
    if (cnt[i] == n) {
      ++ans;
    }
  }

  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 3600
n = gets.to_i
s = gets.chomp.chars
hs = Hash.new
s.each_with_index do |c, i|
  hs[c] ||= []
  hs[c] << i
end

# imos method
res =  Array.new(n, 0)
hs.to_a.each do |k, v|
  next if v.size < 2
  l = v[0]
  r = v[-1]
  res[l] += 1
  res[r] -= 1
end
(1...n).each do |i|
  res[i] += res[i - 1]
end
puts res.max

Measured memory_bytes: 1788
n = int(input())
a = input()
r = [None] * (n + 1)
for i in range(n, 0, -1):
    r[i] = (ord(a[2 * i - 2]) + sum(r[i * 2::i])) % 2
print(r.count(1))
print(*(i for i, x in enumerate(r) if x))

Measured memory_bytes: 12036
#include <stdio.h>
#include <utility>

using namespace std;

int main()
{
	int x, y = 0;

	scanf("%d", &x);
	scanf("%d", &y);

	if (y > x) {
		swap(x, y);
	}

	while (y > 0) {
		int tmp = x % y;
		x = y;
		y = tmp;
	}

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

	return 0;
}


Measured memory_bytes: 2740
#include <iostream>
#include <cfenv>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <limits>

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

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

    string ans = "";

    rep(i, s.size()){
        ans += "x";
    }

    cout << ans << endl;
}

Measured memory_bytes: 760
using System;

class ALDS1_3_D {
    void run() {

        int i, j, narea, ssum;
        string s = Console.ReadLine().Trim();
        int d, dmin, dmax, total, slen = s.Length;
        d = dmin = dmax = 0;
        for (i=0;i<slen;i++) {
            if (s[i]=='\\') d--;
            else if (s[i]=='/')  d++;
            if (dmin>d) dmin=d;
            else if (dmax<d) dmax=d;
        }
        int[] start = new int[dmax-dmin+1];
        for (i=0; i<dmax-dmin+1; i++)  start[i] = -1;
        int[] h = new int[slen];

        total = 0;
        d = -dmin;
        for (i=0; i<slen; i++) {
            if (s[i]=='\\') start[d--]=i;
            else if (s[i]=='/') {
                d++;
                if (start[d]>=0) {
                    for (j=start[d]; j<i; j++)  h[j]++;
                    total += i-start[d];
                }
            }
        }

        Console.WriteLine("{0}", total);
        narea=ssum=0;
        foreach (int k in h) {
            ssum += k;
            if (k==0) {
                if (ssum>0) narea++;
                ssum=0;
            }
        }
        Console.Write("{0}", narea);
        if (narea>0) {
            foreach (int k in h) {
                ssum += k;
                if (k==0) {
                    if (ssum>0) Console.Write(" {0}", ssum);
                    ssum=0;
                }
            }
        }
        Console.WriteLine();
    }

    public static void Main()
    {
        ALDS1_3_D a = new ALDS1_3_D();
        a.run();
    }
}



Measured memory_bytes: 17936
A, B = map(int, input().split())
K = 50
G = [['.' for j in range(2 * K)] for i in range(K)] + [['#' for j in range(2 * K)] for i in range(K)]
x = 0
while B > 1:
  for y in range(min(K, B - 1)):
    G[x][x % 2 + 2 * y] = '#'
    B -= 1
  x += 2
x = 2 * K - 1
while A > 1:
  for y in range(min(K, A - 1)):
    G[x][x % 2 + 2 * y] = '.'
    A -= 1
  x -= 2
print(2 * K, 2 * K)
for i in range(2 * K):
  print(''.join(G[i]))

Measured memory_bytes: 3188
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

x,y,a,b,c=nii()
p=lnii()
q=lnii()
r=lnii()

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

l=p[:x]+q[:y]
l.sort()

ans=0
for i in range(x+y):
  if i<c:
    ans+=max(l[i],r[i])
  else:
    ans+=l[i]

print(ans)

Measured memory_bytes: 29712
N, K = map(int, input().split())
A = list(map(int, input().split()))

cnt = {}
for a in A:
    if a not in cnt:
        cnt[a] = 1
    else:
        cnt[a] += 1

d = len(cnt) - K
ans = sum(list(sorted(cnt.values()))[:d])
print(ans)


Measured memory_bytes: 96976
N=int(input())
S=[]
for _ in range(N):
    L=sorted(input())
    S.append(''.join(L))
S.sort()
#print(S)

def comb(x):
    return x*(x-1)//2

count=1
ans=0
for i in range(N-1):
    if i<N-2:
        if S[i]==S[i+1]:
            count+=1
        else:
            if count>=2:
                ans+=comb(count)
                count=1
    else:
        if S[i]==S[i+1]:
            count+=1
            if count>=2:
                ans+=comb(count)
        else:
            if count>=2:
                ans+=comb(count)

print(ans)

Measured memory_bytes: 10640
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int i = 0;
        int b = s.length();
        for(int j=0;j<b;j++){
            if(s.charAt(j) != s.charAt(b-1-j)){
                i++;
            }
        }
        System.out.println(i / 2);
    } 
}

Measured memory_bytes: 23760
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
const int N=5000,D=998244353;

ll qpow(ll x,ll k) {
	ll ret=1;
	while(k) {
		if(k&1) ret=ret*x%D;
		x=x*x%D;
		k>>=1;
	}
	return ret;
}
ll fac[N+233],inv[N+233],tot,mul2[N+233];
void first() {
	fac[0]=inv[0]=1;
	for(int i=1;i<=N;i++) fac[i]=fac[i-1]*i%D;
	inv[N]=qpow(fac[N],D-2);
	for(int i=N-1;i;i--) inv[i]=inv[i+1]*(i+1)%D;
	mul2[0]=1;
	for(int i=1;i<=N;i++) mul2[i]=mul2[i-1]*2%D;
}
ll C(ll x,ll y) {
	if(y<0) return 0;
	return fac[x]*inv[y]%D*inv[x-y]%D;
}
ll calc(ll x,ll y,ll z) {//x position,y pair limit,z others
	ll ret=0;
	for(int i=0;i<=min(y,x);i++)
		ret=(ret+C(y,i)*mul2[i]%D*C(x+z-1,i+z-1))%D;
	return ret;
}
int n,K;
int main() {
	first();
	scanf("%d%d",&K,&n);
	for(int i=2;i<=(K<<1);i++) {
		int p=0,o;
		for(int j=1,k=i-1;j<k;j++,k--) if(j<=K&&k<=K) ++p;
		o=K-2*p;
		ll ans=0;
		if(i&1) ans=calc(n,p,o);
		else --o,ans=(calc(n,p,o)+calc(n-1,p,o))%D;
		printf("%lld\n",(ans+D)%D);
	}
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
using namespace std;
const ll N=500010;

vector<ll> ar;
int dp[5001][5001];

ll func(ll idx,ll k)
{
    if(idx<0){
        if(k<=0){return 1;}
        else{return 0;}
    }
    if(k<=0){return (1<<(idx+1));}
    if(dp[idx][k]==-1)
    {
        dp[idx][k]=func(idx-1,k-ar[idx])+func(idx-1,k);
    }
    return dp[idx][k];
}

vector<bool> ans;
int dp2[5001][5001];

void func2(ll idx,ll k)
{
    if(idx<0){return;}
    if(k<0){return;}
    if(dp2[idx][k]==-1){
        dp2[idx][k]=1;
        ll wayswith=func(idx-1,k-ar[idx]);
        ll wayswithout=func(idx-1,k);
        if(wayswith!=wayswithout){ans[idx]=0;}
        func2(idx-1,k);
        func2(idx-1,k-ar[idx]);
    }
    return;
}

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

    ll n,k;
    cin>>n>>k;
    ar.resize(n);
    for(ll i=0;i<n;++i){
        cin>>ar[i];
    }

    memset(dp,-1,sizeof(dp));
    ll lol=func(n-1,k);
    ans.resize(n,1);

    memset(dp2,-1,sizeof(dp2));
    func2(n-1,k);

    ll sum=0;
    for(ll i=0;i<n;++i){
        sum+=ans[i];
    }
    cout<<sum<<endl;

    return (0);
}


Measured memory_bytes: 195968
#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
using namespace std;

int main(){
    int N;
    string S;
    scanf("%d\n", &N);
    cin >> S;
    long long ans = 0;

    ans += count(S.begin(), S.end(), 'R') * count(S.begin(), S.end(), 'G') * count(S.begin(), S.end(), 'B');
    
    for(int i=1; i<N; i++){
        for(int j=0; j+2*i<N; j++){
            if(S[j] != S[j+i] && S[j+i] != S[j+2*i] && S[j+2*i] != S[j]){
                ans--;
            }
        }
    }
    cout << ans << endl;
    return 0;

}

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

using namespace std;

int main() {
  int N;
  cin >> N;
  int ans = 0, m = 0;
  for (int i = 0; i < N; ++i) {
    int p;
    cin >> p;
    ans += p;
    m = max(m, p);
  }
  ans -= m / 2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
const int N=200005;
const int INF=1e9;
int n,m;
struct node{
    int u,v,w;
}p[N];
int fa[N];
int dist[N];
int np[N];
int find_father(int x){
	if(x==fa[x]){
		//dist[x]=0;
		return x;
	}
	int f=fa[x];
    fa[x]=find_father(fa[x]);
    dist[x]=dist[f]+np[x];
    np[x]=dist[x];
    return fa[x];
}
void merge(int x,int y,int w){
    int f1=find_father(x);
	int f2=find_father(y);
    w-=dist[x]-dist[y];
    fa[f1]=f2;
	np[f1]=w;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		fa[i]=i;
    for(int i=1;i<=m;i++){
        scanf("%d%d%d",&p[i].u,&p[i].v,&p[i].w);
    }
    for(int i=1;i<=m;i++){
        int u=p[i].u,v=p[i].v,w=p[i].w;
        find_father(u);
        find_father(v);
        if(fa[u]!=fa[v]){
			merge(u,v,w);
        }
        else{
            if(dist[u]-dist[v]!=w){
                printf("No\n");
                return 0;
            }
        }
    }
    printf("Yes\n");
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a.at(i);
    }
    for(int i = 0; i < n; i++){
        int v = a.at(i);
        int j = i - 1;
        while(j >= 0 && a.at(j) > v){
            a.at(j + 1) = a.at(j);
            j--;
        }
        a.at(j+1) = v;
        for(int j = 0; j < n; j++){
            if (j > 0){
                cout << " ";
            }
            cout << a.at(j);
        }
        cout << endl;
    }
}


Measured memory_bytes: 3104
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int t = sc.nextInt();
        long ans = t;
        int start = sc.nextInt();
        for (int i = 1; i < n; i++) {
            int ti = sc.nextInt();
            if (start + t > ti)
                ans += ti - start;
            else
                ans += t;
            start = ti;
        }
        System.out.println(ans);
    }
}


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


class Main{
	void solve(){
		Scanner sc = new Scanner(System.in);
		
		int count = 0;
		while(sc.hasNext()){
			char[] str = sc.next().toCharArray();
			
			boolean f = true;
			for(int i=0; i<(str.length+1)/2; ++i){
				int j = str.length-1-i;
				f &= str[i] == str[j];
			}
			if(f) ++count;
		}
		
		System.out.println(count);
	}
	
	public static void main(String[] args){
		new Main().solve();
	}
	
	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}
}

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

using namespace std;

int dirs[4][2]={{-1, 0}, {0, 1}, {1, 0}, {0, -1}};

int main()
{
    //freopen("inp.in", "r", stdin);
    //freopen("outp.out", "w", stdout);
    //ios::sync_with_stdio(false);
    int n;
    scanf("%d", &n);
    vector<long long> v(n);
    for(int i=0; i<n; i++)
    {
        scanf("%lld", &v[i]);
    }
    vector<int> eerste(n, -1);
    for(int i=1; i<n; i++)
    {
        if(v[i-1] != 0) eerste[i]=i-1;
        else eerste[i]=eerste[i-1];
    }

    vector< vector<int> > bits(n);
    for(int i=0; i<n; i++)
    {
        vector<int> tmp;
        for(int j=0; j<25; j++)
        {
            if((1LL<<j)&v[i])
            {
                tmp.push_back(j);
            }
        }
        bits[i]=tmp;
    }
    long long ans=0;
    for(int i=0; i<n; i++)
    {
        set<int> s;
        int j=i;
        while(j>=0)
        {
            bool ok=true;
            for(int b : bits[j])
            {
                if(s.count(b)>0)
                {
                    ok=false;
                    break;
                }
                s.insert(b);
            }
            if(ok){
                ans++;
                //cerr << i << " " << j << endl;
            }
            else
            {
                break;
            }
            ans += j-eerste[j]-1;
            j=eerste[j];
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 17792