akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include <cmath>
#include <limits>
#include <iomanip>
using namespace std;
const long long INF=20000000000;

int main(){
	string s;
	cin>>s;
	if(s=="Sunny")cout<<"Cloudy"<<endl;
	if(s=="Cloudy")cout<<"Rainy"<<endl;
	if(s=="Rainy")cout<<"Sunny"<<endl;

	
}
	


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

const int N = 310;
const int INF = 1e9;

int n, m;
char a[N][N];
int res;
int dp[N][N], c[N][N];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) cin >> a[i][j];
	}

	for (int col = 1; col < m; ++col) {
		// prepare
		for (int i = 0; i <= n; ++i) {
			for (int j = 0; j <= n; ++j) {
				c[i][j] = 0;
				if (i == 0 || j == 0) {
					for (int k = 1; k <= n - i; ++k) {
						if (k + i - j >= 1 && k + i - j <= n - j) {
							c[i][j] += (a[k][col] == a[k + i - j][col + 1]);
						}
					}
				} else {
					c[i][j] = c[i - 1][j - 1] - (a[n - i + 1][col] == a[n - j + 1][col + 1]);
				}
			}
		}

		// solve
		for (int i = 0; i <= n; ++i) {
			for (int j = 0; j <= n; ++j) dp[i][j] = INF;
		}
		dp[0][0] = 0;
		for (int i = 0; i <= n; ++i) {
			for (int j = 0; j <= n; ++j) {
				if (i < n) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + c[i][j]);
				if (j < n) dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + c[i][j]); 
			}
		}

		res += dp[n][n];
	}

	cout << res << endl;
}

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

using namespace std;

#define ll long long int
#define fo(i,b,n) for(int i=(b); i<(n) ; i++)
#define xx first
#define yy second
#define pb push_back
#define sz(n) int(n.size())
#define pii pair
#define MP make_pair

#define read(x) scanf("%d",&x)
#define read2(x,y) scanf("%d%d",&x,&y)
#define readl(x) scanf("%lld",&x)
#define readl2(x,y) scanf("%lld%lld",&x,&y)
#define readd(x) scanf("%lf",&x)
#define readd2(x,y) scanf("%lf%lf",&x,&y)

#define pr(n) printf("%d",n)
#define prn(n) printf("%d\n",n)
#define prl(n) printf("%lld",n)
#define prln(n) printf("%lld\n",n)
#define prd(x) printf("%lf",x)
#define prdn(x) printf("%lf\n",x)

#define TC(n) printf("Case %d: ",n)


int main()
{

    int a,b,c;
    cin>>a>>b>>c;
    vector<int>v;
    v.pb(a),v.pb(b),v.pb(c);
    sort(v.begin(),v.end());

    puts( v[0]+v[1]==v[2] ? "Yes" : "No" );


    return 0;
}

















Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <complex>

using namespace std;

typedef complex<double> P;

struct L {
    P p, q;
    L(P p, P q) : p(p), q(q) {}
};

const double EPS = 1e-8;
const double INF = 1e12;

double dot(P a, P b) { return real(conj(a)*b); }
double cross(P a, P b) { return imag(conj(a)*b); }
double angle(P a, P b) { return arg(conj(a)*b); }

P footPerp(L l, P p) {
    return l.p+(l.q-l.p)*(dot(l.q-l.p,p-l.p) / (abs(l.q-l.p)*abs(l.q-l.p)));
}

P lineShadow(L l, P p){
    return 2.0*footPerp(l, p)-p;
}

bool ssIntersect(L a, L b){
    if(abs(imag((a.q-a.p)/(b.q-b.p)))<EPS) return false;
    return cross(a.q-a.p, b.p-a.p)*cross(a.q-a.p, b.q-a.p) < 0 &&
           cross(b.q-b.p, a.p-b.p)*cross(b.q-b.p, a.q-b.p) < 0;
}

bool lpIntersect(L a, P p){
    return abs(imag((p-a.p)/(a.q-a.p)))<EPS;
}

P ssCrosspoint(L a, L b){
    double A = cross(a.q-a.p, b.q-b.p);
    double B = cross(a.q-a.p, a.q-b.p);
    return b.p + B/A * (b.q-b.p);
}

void check(vector<double> &agl, const vector<L> &vl, const vector<int> &idx, P s, P g){
    for(int i=0;i<idx.size();i++){
        if(lpIntersect(vl[idx[i]], g)) return ;
        g = lineShadow(vl[idx[i]], g);
    }
    agl.push_back(angle(P(1,0), g-s));
}

void dfs(vector<double> &agl, const vector<L> &vl, vector<int> &idx, P s, P g){
    check(agl, vl, idx, s, g);
    if(idx.size()==5) return ;
    for(int i=0;i<vl.size();i++){
        if(!idx.empty()&&idx.back()==i) continue;
        idx.push_back(i);
        dfs(agl, vl, idx, s, g);
        idx.pop_back();
    }
}

double calc(const vector<double> &agl, const vector<L> &vl, P s, P g){
    double res = INF;
    for(int i=0;i<agl.size();i++){
        P cur = s;
        P dir = P(cos(agl[i]), sin(agl[i]));
        double len = 0.0;
        for(int cnt=0; ;cnt++){
            P nxt = cur + 1000.0*dir;
            if(lpIntersect(L(cur, cur+dir), g)&&dot(dir, g-cur)>EPS) nxt = g;
            int idx = -1;
            for(int j=0;j<vl.size();j++){
                if(!lpIntersect(vl[j], cur)&&ssIntersect(L(cur, nxt), vl[j])){
                    idx = j;
                    nxt = ssCrosspoint(L(cur, nxt), vl[j]);
                }
            }
            len += abs(cur-nxt);
            if(abs(nxt-g)<EPS) break;
            if(idx == -1 || cnt == 6){
                len = INF;
                break;
            }
            dir = lineShadow(L(nxt, nxt+(vl[idx].q-vl[idx].p)*P(0,1)), cur) - nxt;
            dir /= abs(dir);
            cur = nxt;
        }
        res = min(res, len);
    }
    return res;
}

int main(){
    int n;
    while(cin >> n, n){
        P s, g;
        vector<L> vl;
        for(int i=0;i<n;i++){
            int px, py, qx, qy; cin >> px >> py >> qx >> qy;
            vl.push_back(L(P(px,py), P(qx,qy)));
        }
        int tx, ty, lx, ly; cin >> tx >> ty >> lx >> ly;
        s = P(tx, ty);
        g = P(lx, ly);
        vector<int> idx;
        vector<double> vd;
        dfs(vd, vl, idx, s, g);
        printf("%.4lf\n", calc(vd, vl, s,g));
    }
}

Measured memory_bytes: 1004
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){
  string S;
  cin >> S;
  int ans=0;
  for(int i=0;i<S.size();i++){
    if(S.at(i)=='+')  ans++;
    else if(S.at(i)=='-') ans--;
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りに作成したソースコード
 */
public class Main {

	/** 数字を作るのに必要なマッチ数 */
	private static final int[] NUMBERS = { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), m = scanner.nextInt();
			int[] a = IntStream.range(0, m).map(i -> scanner.nextInt()).sorted().toArray();
			int[] num = IntStream.range(0, m).map(i -> num(a[i])).sorted().toArray();
			int digit = dp(n, num), remain = n;
			StringBuilder sb = new StringBuilder();
			for (int i = 0; i < digit; i++) {
				for (int j = m - 1; j >= 0; j--) {
					if (dp(remain - num(a[j]), num) == dp(remain, num) - 1) {
						sb.append(a[j]);
						remain -= num(a[j]);
						break;
					}
				}
			}
			System.out.println(sb.toString());
		}
	}

	/**
	 * @param k 数字
	 * @return 数字を並べるのに必要なマッチ棒の数
	 */
	private static int num(int k) {
		return NUMBERS[k];
	}

	/**
	 * @param n   マッチ棒の総数
	 * @param num 数字を並べるのに必要なマッチ棒の数一覧
	 * @return 並べられる最大桁数
	 */
	private static int dp(int n, int[] num) {
		if (0 == n) {
			return 0;
		}
		int min = num[0];
		if (n % min == 0) {
			return n / min;
		} else {
			for (int number : num) {
				if (n >= number) {
					int next = dp(n - number, num);
					if (next >= 0) {
						return next + 1;
					}
				}
			}
		}
		return -1;
	}
}


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

using namespace std;

int a[101];

int main(){
  int i,N,S=0,mini=100;
  cin >> N;
  for (i=0;i<N;++i) {
    cin >> a[i];
    S+=a[i];
    a[i]*=N;
  }
  a[100]=10000;
  for (i=0;i<N;++i) {
    a[i]=abs(S-a[i]);
    if (a[i]< a[mini]) {
      mini=i;
    }
  }
  cout << mini << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 int main() {
int a,b,c;
   cin >> a>>b>>c;
   int sum =1000000;
   sum = min(sum,a+b);
   sum = min(sum,a+c);
   sum = min(sum,c+b);
   
cout << sum <<endl;
     
   }
   


Measured memory_bytes: 256
N, K = list(map(int, input().split()))
Pd = 1 / N
Pc = 0.5
ans = []
def f(i):
  P = Pd
  while(i<K):
    P = P * Pc
    i = 2 * i
  return P

for j in range(1,N+1):
  ans.append(f(j))
  
print(sum(ans))

Measured memory_bytes: 9720
N = gets.to_i

a = 0
b = 0
ab = 0
res = 0

N.times do
  s = gets.chomp
  if s[0] == 'B' && s[-1] == 'A'
    ab += 1
  elsif s[0] == 'B'
    b += 1
  elsif s[-1] == 'A'
    a += 1
  end
  (0...(s.length)).each do |i|
    if s.slice(i, 2) == 'AB'
      res += 1
    end
  end
end


if a > 0
  while a > 0 do
    a -= 1
    res += ab
    ab = 0

    if b > 0
      b -= 1
      res += 1
    end
  end
else
  if ab >= 2
    res += ab-1
    if b > 0
      res += 1
    end
  elsif ab >= 1
    if b > 0
      res += 1
    end
  end
end

puts res


Measured memory_bytes: 1916
import sys
sys.setrecursionlimit(100002)

input = lambda : sys.stdin.readline().rstrip()


def main(a_s, b_s, n, m):
    graph = {}
    for node in range(1, n+1):
        graph[node] = []

    for i in range(m):
        a, b = a_s[i], b_s[i]
        graph[a].append(b)
        graph[b].append(a)

    uses = [False] * (n+1)

    def check(node):
        uses[node] = True
        kids = graph[node]
        for kid in kids:
            if not uses[kid]:
                check(kid)

    next_graph_i = 1
    for node in range(1, n+1):
        if uses[node]:
            continue
        graph_i = next_graph_i
        check(node)
        next_graph_i = graph_i + 1

    out = graph_i - 1
    print(out)

if True:
    n, m = map(int, input().split(" "))
    a_s = []
    b_s = []
    for i in range(m):
        a, b = map(int, input().split(" "))
        a_s.append(a)
        b_s.append(b)
else:
    import random
    n = random.randint(2, 100000)
    m = random.randint(1, 100000)
    
    a_s = []
    b_s = []
    for i in range(m):    
        a = random.randint(1, n-1)
        b = random.randint(a+1, n)
        a_s.append(a)
        b_s.append(b)

main(a_s, b_s, n, m)

Measured memory_bytes: 65372
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

bool solve(vector<int> v){
  int maxp = 0;
  for(int i=0;i<v.size();i++){
    if(i*10<=maxp){
      maxp = max(maxp, v[i] + i*10); 
    }
  }
  return 10*(v.size()-1) <= maxp;
}

int main(){
  int n;
  cin>>n;
  vector<int> v, u;
  for(int i=0;i<n;i++){
    int x;
    cin>>x;
    v.push_back(x);
  }
  u = v;
  reverse(u.begin(),u.end());
  cout << (solve(v) && solve(u)?"yes":"no") << endl;
}


Measured memory_bytes: 7556
#include<bits/stdc++.h>
#define ll long long
#define db double
#define lowbit(p) (p&(-p))
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define A first
#define B second
using namespace std;
void read(int &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
void read(ll &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
void Min(int &x,int y){
	if (x>y)x=y;
}
void Max(int &x,int y){
	if (x<y)x=y;
}
void Min(ll &x,ll y){
	if (x>y)x=y;
}
void Max(ll &x,ll y){
	if (x<y)x=y;
}
/*
题意:
有两个序列A和B,然后两个人轮流操作
Satori希望操作次数尽可能多,每次操作都会选择序列的一个正数项,然后--
Koishi希望操作次数尽可能少,每次操作都会选择序列的一个正数项,然后--

求最后的操作次数?
分析:
感觉很玄妙啊...又是分类讨论吗?
如果A<B那么可以一直-- 然后就必须要怎么怎么.
如果A=B的话那么同理...?
否则A>B那么可以先把剩下的东西都给搞掉,然后乱来...?
*/
#define M 200005
int n,a[M],b[M],mx;
ll sum;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
//	freopen("1.in","r",stdin);
	read(n);
	mx=1e9;
	int i,flag=1;
	for (i=1;i<=n;i++){
		read(a[i]); read(b[i]);
		sum+=a[i];
		if (a[i]>b[i]){
			Min(mx,b[i]);
		}
		if (a[i]!=b[i]){
			flag=0;
		}
	}
	if (flag){
		printf("0\n");
		return 0;
	}
	printf("%lld\n",sum-mx);
	return 0;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Random;
import java.util.StringTokenizer;
public class Main{
       public static void main(String[] args){
            FastScanner scanner = new FastScanner(System.in);
            int a = scanner.nextInt();
            int b=scanner.nextInt();
            if(a==b)System.out.println("Yes");
         	else System.out.println("No");
       }
       static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
 
        FastScanner(InputStream stream) {
            try {
                br = new BufferedReader(new InputStreamReader(stream));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
 
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt() {
            return Integer.parseInt(next());
        }
    }
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    int n,x;cin >> n>>x;
    vector<int> a(n);
    REP(i, n) { cin >> a[i];}
    int ans=0;
    sort(ALL(a));
    REP(i,n){
        if(i==n-1){
            if(x==a[i]){
                ans += 1;
            }
            break;
        }
        if(x>0){
            if(x>=a[i]){
                x -= a[i];
                ans += 1;
            }
        }else{
            break;
        }
    }

    cout << ans <<"\n";

    return 0;
}

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

Measured memory_bytes: 35652
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

//https://beta.atcoder.jp/contests/abc060/tasks/abc060_b

int main() {
    int A, B, C; cin >> A >> B >> C;

    for (int i = 1; i <= A*B; i++) if (A*i%B==C){
            cout << "YES" << "\n";
            return 0;
    }

    cout << "NO" << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <fstream>
#include <utility>
#include <iomanip>
#include <cstring>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#define IO ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
typedef long double ld;

using namespace std;
const ll INF = 1e18;
const int mod = 1e4, N = 1e5 + 5, inf = 1e9;

int main()
{
    IO
    int n, a[N], b[N], c[N];
    ll ans[N][2] = {}; // :)
    ll A = 0; // :)
    cin >> n;
    for(int i = 0 ; i < n; cin >> a[i++]);
    for(int i = 0 ; i < n; cin >> b[i++]);
    for(int i = 0 ; i < n; cin >> c[i++]);
    sort(a, a + n);
    sort(b, b + n);
    sort(c, c + n);
    for(int i = 0; i < n; i++)
    {
        int s = 0, e = n - 1, m, loc = -1;
        while(s <= e)
        {
            m = (s + e) / 2;
            if(a[m] < b[i])
            {
                loc = m;
                s = m + 1;
            }
            else e = m - 1;
        }
        ans[i][0] = loc + 1;
    }
    for(int i = 1; i < n; i++)
        ans[i][0] += ans[i - 1][0];
    for(int i = 0; i < n; i++)
    {
        int s = 0, e = n - 1, m, loc = -1;
        while(s <= e)
        {
            m = (s + e) / 2;
            if(b[m] < c[i])
            {
                loc = m;
                s = m + 1;
            }
            else e = m - 1;
        }
        if(loc != -1)
            ans[i][1] = ans[loc][0];
    }
    for(int i = 0; i < n; i++)
        A += ans[i][1];
    cout << A << '\n';
    return 0;
}

Measured memory_bytes: 6356
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.next()
    val b = sc.next()
    val c = sc.next()
    println(if (a[a.length-1] == b[0] && b[b.length-1] == c[0]) "YES" else "NO")
}




Measured memory_bytes: 29476
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  while(N != 0){
    vector<int> X(N),Y(N);
    vector<bool> get(N,false); 
    for(int i=0; i<N; i++){
      cin >> X[i] >> Y[i];
    }
    int M;
    cin >> M;
    int x=10,y=10;
    string str = "ENWS";
    for(int i=0; i<M; i++){
      char c;
      int cnt;
      cin >> c >> cnt;
      for(int dir=0; dir<4; dir++){
        if(str[dir] == c){
          for(int k=0; k<cnt; k++){
            x += dx[dir];
            y += dy[dir];
            for(int j=0; j<N; j++){
              if(X[j] == x and Y[j] == y){
                get[j] = true;
              }
            }
          }
        }
      }
    }
    bool all = true;
    for(int i=0; i<N; i++){
      if(!get[i]) all = false;
    }
    if(all){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
    cin >> N;
  }
  return 0;
}


Measured memory_bytes: 3076
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>

using namespace std;

int main()
{
	unsigned int n;
	while (cin >> n)
	{
		int count = 0;
		for (int i = 0; i < 10; i++)
			for (int j = 0; j < 10; j++)
				for (int k = 0; k < 10; k++)
					for (int l = 0; l < 10; l++)
						if (n == (i + j + k + l))
							count++;
		
		
		cout << count << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1156
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    dd = [(-1,0),(1,0),(0,-1),(0,1),(-1,-1),(-1,1),(1,-1),(1,1)]

    while True:
        w,h = LI()
        if w == 0:
            break
        a = [LI() for _ in range(h)]
        f = collections.defaultdict(bool)
        r = 0
        for i in range(h):
            for j in range(w):
                if f[(i,j)] or a[i][j] == 0:
                    continue
                r += 1
                q = [(i,j)]
                f[(i,j)] = True
                qi = 0
                while len(q) > qi:
                    ci,cj = q[qi]
                    qi += 1
                    for di,dj in dd:
                        ni = ci + di
                        nj = cj + dj
                        if 0 <= ni < h and 0 <= nj < w and a[ni][nj] == 1 and not f[(ni,nj)]:
                            f[(ni,nj)] = True
                            q.append((ni,nj))
        rr.append(r)

    return '\n'.join(map(str, rr))


print(main())




Measured memory_bytes: 9452
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<P,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define print(v) cout<<v<<endl;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;

ll digit(long long int n){
    string s;
    s = std::to_string(n);
    return s.size();
}

int main(){
    ll N;
    cin >> N;
    ll M;
    cin >> M;
    vector<ll> Pa(M,0);
    vector<ll> Y(M,0);
    for(ll i=0;i<M;i++){cin>>Pa[i]>>Y[i];Pa[i]--;}
    vector<vector<P>> vec(N, vector<P>(0));
    for(ll i=0;i<M;i++){
        vec[Pa[i]].emplace_back(P(Y[i],i));
    }
    
    for(ll i=0;i<N;i++)sort(vec[i].begin(), vec[i].end());
    vector<P> ans(M);
    for(ll i=0;i<N;i++)
        for(ll j=0;j<vec[i].size();j++){
            ans[vec[i][j].second]=P(i,j);
        }
    for(ll i=0;i<M;i++){
        ll s=ans[i].first+1;
        ll t=ans[i].second+1;
        for(ll j=0;j<6-digit(s);j++)cout<<0;
        cout<<s;
        for(ll j=0;j<6-digit(t);j++)cout<<0;
        cout<<t<<endl;
    }



    return 0;
}

Measured memory_bytes: 10112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll MAX_N = ll(1e5 + 5);
#define REP(i, n) for (int i = 0; i < n; i++)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()


int main() {
    int n, t, ans = IINF;
    cin >> n >> t;
    REP(i,n){
        int c, tt;
        cin >> c >> tt;
        if(tt <= t)ans = min(ans, c);
    }
    if(ans < IINF) cout << ans << endl;
    else cout << "TLE" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main()
{
  int a,b; cin >> a >> b;
  vector<bool> flg(3,false);
  flg[--a] = true;
  flg[--b] = true;
  rep(i,3){
    if(!flg[i]) cout << ++i << endl;
  }
}

Measured memory_bytes: 256
mod = 10 ** 9 + 7

n, k = map(int, input().split())
a = sorted(map(int, input().split()))

fact = [1] * n
inv = [1] * n
inv_fact = [1] * n

for i in range(2, n):
  fact[i] = fact[i-1] * i % mod
  inv[i] = -inv[mod % i] * (mod // i) % mod
  inv_fact[i] = inv_fact[i-1] * inv[i] % mod

max_sum = 0
for i in range(k-1, n):
  max_sum = (max_sum + a[i] * fact[i] * inv_fact[i-k+1]) % mod
max_sum = (max_sum * inv_fact[k-1]) % mod

min_sum = 0
for i in range(n-k+1):
  min_sum = (min_sum + a[i] * fact[n-i-1] * inv_fact[n-k-i]) % mod
min_sum = (min_sum * inv_fact[k-1]) % mod

print((max_sum - min_sum) % mod)

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

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

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

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int N, K, Q;
  cin >> N >> K >> Q;
  set< pair< int, int > > mp;
  vector< int > uku(N, K);
  for(int i = 0; i < N; i++) mp.emplace(K, i);

  for(int i = 1; i <= Q; i++) {
    int a;
    cin >> a;
    --a;
    mp.erase({uku[a], a});
    uku[a] += 1;
    mp.emplace(uku[a], a);
  }


  while(mp.size() && (*mp.begin()).first <= Q) {
    mp.erase(mp.begin());
  }

  for(int i = 0; i < N; i++) {
    if(mp.count({uku[i], i})) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}




Measured memory_bytes: 5760
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>

using namespace std;

int X, Y, n;

struct Memo
{
	int b;
	int k;
};

struct Point
{
	int x;
	int y;
};

struct Node
{
	int idx;
	int a[10][10];
};

class memo_greater
{
public:
	bool operator() (const Memo m1, const Memo m2)
	{
		return m1.k > m2.k;
	}
};

Point P[15];
Memo M[15];
int A[10][10];

bool is_able(int a[10][10], int x, int y, int w, int h, int idx)
{
	for(int j=y; j<y+h; j++)
	{
		for(int i=x; i<x+w; i++)
		{
			if(i<0 || j<0 || i>=X || j>=Y) return false;
			if(a[j][i]!=0 && a[j][i]!=idx) return false;
		}
	}

	return true;
}

void set(int a[10][10], int x, int y, int w, int h, int idx)
{
	for(int j=y; j<y+h; j++)
	{
		for(int i=x; i<x+w; i++)
		{
			a[j][i] = idx;
		}
	}
}

bool is_ans()
{
	for(int y=0; y<Y; y++)
	{
		for(int x=0; x<X; x++)
		{
			if(A[y][x]==0)
			{
				return false;	
			}
		}
	}

	return true;
}

bool solve()
{
	queue<Node> que;
	int b, k, i, j, mem_size;
	Point p;

	bool is_ok;
	mem_size = sizeof(int) * 100;
	sort(&M[0], &M[n-1], memo_greater());
	Node nn;
	nn.idx = 0;
	memcpy(nn.a, A, mem_size);

	que.push(nn);

	is_ok = false;
	while(!que.empty())
	{
		nn = que.front();
		que.pop();

		if(nn.idx==n)
		{
			if(!is_ok)
			{
				memcpy(A, nn.a, mem_size);
				is_ok = true;
			}
			else{
				return false;
			}
		}

		b = M[nn.idx].b;
		k = M[nn.idx].k;
		p = P[b-1];

		for(i=1; i<=k; i++)
		{
			if(k%i!=0) continue;

			j = k / i;
			for(int dy=0; dy<j; dy++)
			{
				for(int dx=0; dx<i; dx++)
				{
					if(is_able(nn.a, p.x-dx, p.y-dy, i, j, b))
					{
						Node node;
						memcpy(node.a, nn.a, mem_size);
						set(node.a, p.x-dx, p.y-dy, i, j, b);
						node.idx = nn.idx+1;
						que.push(node);
					}
				}
			}
		}
	}

	if(is_ok) return true;
	else return false;
}

int main(int argc, char** argv)
{
	while( 1 )
	{
		cin >> X >> Y >> n;
		if(!(X || Y || n)) break;

		for(int i=0; i<n; i++)
		{
			cin >> M[i].b >> M[i].k;
		}

		for(int y=0; y<Y; y++)
		{
			for(int x=0; x<X; x++)
			{
				cin >> A[y][x];
				if(A[y][x] != 0)
				{
					P[A[y][x]-1].x = x;
					P[A[y][x]-1].y = y;
				}
			}
		}

		if(solve())
		{	
			for(int y=0; y<Y; y++)
			{
				for(int x=0; x<X; x++)
				{
					cout << A[y][x];
					if(x!=X-1) cout << " ";
				}
				cout << endl;
			}
		}
		else
		{
			cout << "NA" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
using ll = long long;
using namespace std;

int main() {
    set<string> s;
    map<string,int> m;
    int n,max=0;
    string st;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>st;
        s.insert(st);
        m[st]++;
        if(max<m[st])max=m[st];
    }
    for(auto x : s){
        if(m[x]==max)cout<<x<<endl;
    }
}

Measured memory_bytes: 34560
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] >= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}
	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

int main() {
	string s;
	cin >> s;
	if (s == "RSR") {
		cout << "1";
	}
	else {
		int a = 0;
		for (int i = 0; i < 3; i++) {
			if (s[i] == 'R') {
				a++;
			}
		}
		cout << a;
	}
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
signed main(){
  string a; 
  cin>>a;
  if(a[0]=='Y'){
    if(a[1]=='A'){
      if(a[2]=='K'){
        if(a[3]=='I') cout<<"Yes";
        else cout<<"No";
      }
      else cout<<"No";
    }
    else cout<<"No";
  }
  else cout<<"No";
  cout<<"\n";
}

Measured memory_bytes: 256
S=input()
k=0
z=0
cnt=0
if S[0]=='A':
    for i in range(2,len(S)-1):
        if S[i]=='C':
            k=i
            cnt += 1
            z=100
            if z==100 and cnt==1:
                for j in range(1,k):
                    if 'a'<=S[j]<='z':
                        z=200
                    else:
                        print('WA')
                        exit()
                if z==200 :        
                    for l in range(k+1,len(S)):
                        if 'a'<=S[l]<='z':
                            z=102
                        else:
                            print('WA')
                            exit()
if z == 0 or z==100:
    print('WA')
else:
    print('AC')

Measured memory_bytes: 9036
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;





int main() {
//    cout << setprecision(100);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    string s;
    cin >> s;
    map<char, int> d;
    for (char c : s) {
        d[c]++;
    }
    
    
    if (d.size() == 2) {
        auto it = d.begin();
        auto itt = it;
        itt++;
        if (it->second == 2 && itt->second == 2) {
            cout << "Yes";
            return 0;
        }
    }
    
    cout << "No";




}




Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int k = sc.nextInt();
    int kMinus = k - 1;
    
    if (k % 2 == 0) {
      System.out.println((k / 2) * (k / 2));
    } else {
      System.out.println((kMinus / 2) * (kMinus / 2 + 1));
    }
  }
}

Measured memory_bytes: 21972
//@winlere
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>

using namespace std;  typedef long long ll;
inline int qr(){
	int ret=0,f=0,c=getchar();
	while(!isdigit(c))f|=c==45,c=getchar();
	while(isdigit(c)) ret=ret*10+c-48,c=getchar();
	return f?-ret:ret;
}
ll a,b,n;
int main(){
	cin>>a>>b>>n;
	if(b-1<=n) cout<<(a*(b-1))/b-(b-1)/b*a<<endl;
	else cout<<(n*a)/b-n/b*a<<endl;
	return 0;
}


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

using namespace std;

#define MOD 1000000007
#define ll long long int
#define ld long double
#define pb push_back
#define mkp make_pair
#define pii pair<int, int> 
#define pll pair<long long int, long long int>
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define fi first
#define sc second
#define eps 1e-9

int A[100005];

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

	ll n, m, i, j, k, x, y, z;
	cin >> n >> k;
	for (i = 0; i < n; ++i) cin >> A[i];
	sort(A, A+n);
	multiset<ll> se;
	for (i = 0; i < k-1; ++i) se.insert(A[i]);
	ll ans = 1e18;
	for (i = k-1; i < n; ++i) {
		se.insert(A[i]);
		x = *se.begin();
		y = *(--se.end());
		ans = min(ans, min(abs(x), abs(y)) + abs(x-y));
		se.erase(se.find(A[i-k+1]));
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 5376
import java.util.Scanner;
//終了処理の雛形
class Main{
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] str;
		int[][] kami;		// yoko tate
		kami=new int[14][14];
		int x=0,y=0,scale=0;
		int zerokosu=0;
		int maxkosa=0;

		while(sc.hasNext()) {
			str=sc.next().split(",");
			x=Integer.parseInt(str[0]);
			y=Integer.parseInt(str[1]);
			scale=Integer.parseInt(str[2]);

			if(scale==1) {
				kami[x+2][y+2]++;
				kami[x+3][y+2]++;
				kami[x+1][y+2]++;
				kami[x+2][y+1]++;
				kami[x+2][y+3]++;
			}

			else if(scale==2) {
				kami[x+2][y+2]++;
				kami[x+3][y+2]++;
				kami[x+1][y+2]++;
				kami[x+2][y+3]++;
				kami[x+3][y+3]++;
				kami[x+1][y+3]++;
				kami[x+2][y+1]++;
				kami[x+3][y+1]++;
				kami[x+1][y+1]++;
			}

			else if(scale==3) {
				kami[x+2][y+2]++;
				kami[x+3][y+2]++;
				kami[x+1][y+2]++;
				kami[x+2][y+3]++;
				kami[x+3][y+3]++;
				kami[x+1][y+3]++;
				kami[x+2][y+1]++;
				kami[x+3][y+1]++;
				kami[x+1][y+1]++;
				kami[x][y+2]++;
				kami[x+2][y]++;
				kami[x+4][y+2]++;
				kami[x+2][y+4]++;
			}
		}

		for(int i=2; i<12; i++) {
			for(int j=2; j<12; j++) {
				if(kami[i][j]==0) {
					zerokosu++;
				}
				else {
					if(kami[i][j]>maxkosa) {
						maxkosa=kami[i][j];
					}
				}
			}
		}
		System.out.println(zerokosu);
		System.out.println(maxkosa);
	}
}


Measured memory_bytes: 26224
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>

using namespace std;
using ll = long long;

const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<ll> A(n + 1), B(n + 1, 0);
    for(int i = 0; i <= n; i++) cin >> A[i];
    for(int i = 0; i < n; i++) cin >> B[i];
    ll ans = 0;
    for(int i = 0; i < n; i++)
    {
        if(B[i] < A[i])
        {
            ans += B[i];
            A[i] -= B[i];
            B[i] = 0;
        }
        else
        {
            ans += A[i];
            B[i] -= A[i];
            if(B[i] < A[i + 1])
            {
                ans += B[i];
                A[i + 1] -= B[i];
                B[i] = 0;
            }
            else
            {
                ans += A[i + 1];
                A[i + 1] = 0;
            }
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1920
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな　オーバーフローする
//開区間と閉区間どうにかしろ
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグりがち
//切り上げ：(a + (b - 1)) / b
const ll MOD = 1000000007;
int main(){
    int n; cin >> n;
    ll x[n];
    int cnt1[n][70];
    rep(i,n){
        cin >> x[i];
        rep(j,60){
            if(i==0) cnt1[i][j]=0;
            else cnt1[i][j]=cnt1[i-1][j];
            if(x[i]&(ll)(1ull<<j)){
                cnt1[i][j]++;
            }
        }
    }
    ll sum[n];
    sum[0]=0;
    for(int i=1;i<n;i++){
        ll res=0;
        rep(j,60){
            ll k=((1ull<<j)%MOD);
            if(x[i]&(ll)(1ull<<j)) res+=(k*(ll)(i-cnt1[i-1][j])) % MOD; //立ってる
            else res += (k*(ll)(cnt1[i-1][j])) % MOD;
            res %= MOD;
        }
        sum[i] = (sum[i-1]+res) % MOD;
        sum[i] %= MOD;
    }
    cout << sum[n-1] << endl;
}


Measured memory_bytes: 86912
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

int main() {
  string S; cin >>S;
  vector<char> vec(S.size());
  rep(i,0,S.size()) vec[i]=S[i];
  while(true) {
    vec.pop_back();
    if (vec.size()%2) continue;
    else {
      int count=0;
      rep(i,0,vec.size()/2) {
        if (vec[i]==vec[vec.size()/2+i]) count++;
      }
      if (count==(int)(vec.size())/2) {
        cout <<vec.size() <<endl;
        break;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
N=int(input())
T=[int(i) for i in input().split()]
M=int(input())
P=[0 for  i in range(M)]
X=[0 for i in range(M)]
for i in range(M):
    P[i],X[i]=map(int, input().split())
S=sum(T)
for i in range(M):
    print(S-T[P[i]-1]+X[i])


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

using namespace std;
typedef long long ll;
ll k,ans = 1,c[100010] = {},mod = 1000000007;
vector<int> G[100010];
void dfs(int s, int p){
	for(int x:G[s]){
		if(x==p) continue;
		//cout << s << " " << x << " " << c[s] << endl;
		(ans *= (k - c[s])) %= mod;
		c[s]++; c[x]++;
		dfs(x,s);
	}
}

int main(){
	int i,n;
	cin >> n >> k;
	for(i=0;i<n-1;i++){
		int a,b; cin >> a >> b; a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	for(i=0;i<n;i++){
		c[i]++;
	}
	ans *= k;
	dfs(0,-1);
	cout << ans << endl;
}

Measured memory_bytes: 9984
s = gets.chomp.split("")
n = s.count
t1 =  s[0..((n-1)/2)-1]
t2 =  s[(n+3)/2-1..n-1]

(n/2).times do |i|
  unless s[i] == s[-(i+1)]
    puts "No"
    exit
  else
    next
  end
end

(t1.count/2).times do |i|
 unless t1[i] == t1[-(i+1)]
   puts "No"
   exit
 else
   next
 end
end

(t2.count/2).times do |i|
 unless  t2[i] == t2[-(i+1)]
   puts "No"
   exit
 else
   next
 end
end

puts "Yes"

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

int main() {

    int N;    
    cin >> N;
    vector<int> a(N);
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }



    double ave = accumulate(begin(a), end(a), 0.0) / a.size();
    double min_diff = 1e9;
    vector<double> diff;
    for(int i = 0; i < N; i++){
        // double tmp_diff = abs(N*a[i] - N*ave);
        double tmp_diff = abs(a[i] - ave);
        diff.push_back(tmp_diff);
    }

    auto minitr = min_element(begin(diff), end(diff));
    size_t idx = distance(begin(diff), minitr);
    cout << idx << endl;

    return 0;
}

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

int main()
{
    int n,k;
    cin>>n>>k;
    vector<int>h(n+1,0);
    vector<int>d(n+1,INT_MAX);
    for(int i=1;i<=n;i++)
    {
        cin>>h[i];
    }
    d[1]=0;
    for(int i=2;i<=n;i++)
    {
        for(int j=i-1;j>=max(1,i-k);j--)
        {
            d[i]=min(d[i],d[j]+abs(h[i]-h[j]));
        }
    }
    cout<<d[n];
}



Measured memory_bytes: 1024
// Problem : E - Red Scarf
// Contest : AtCoder - AtCoder Beginner Contest 171
// URL : https://atcoder.jp/contests/abc171/tasks/abc171_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl '\n'
#define pb push_back
#define mod 1000000007
ll power(ll x, ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % mod; 
    p = (p * p) % mod; 
  
    return (y%2 == 0)? p : (x * p) % mod; 
} 
ll factorial[1000007];
ll fact(ll n)
{
    memset(factorial,0,sizeof(factorial));
    factorial[0]=1;
factorial[1]=1;

    for(int i=1;i<n;i++)
    {
        factorial[i]=(factorial[i-1]*i)%mod;
    }
    
}
ll ncr(ll n,ll r)
{
    ll ans=1;
    ll i;
    ans=factorial[n];
    ll ans1=power(factorial[n-r],mod-2);
    ll ans2=power(factorial[r],mod-2);
    ans=((ans*ans1)%mod*ans2)%mod;
    return ans;
}
ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 

bool prime[100000006];
void sieve(ll n){
    memset(prime,true,sizeof(prime));
	prime[1]=false; 
    for (ll p=2;p*p<=n;p++){
        if (prime[p]){  
            for (ll i=p*p;i<=n;i+=p)
                prime[i]=false;
        }
    }
}
void bfs(vector<int> v[],int o,int n,int dp[]){
	queue<int> q;
	q.push(o);
	dp[o]=0;
	bool visited[n+1]={0};
	visited[o]=true;
	while(q.empty()==false){
		int a=q.front();
		q.pop();
		for(int i=0;i<v[a].size();i++){
			if(visited[v[a][i]]==false){
				visited[v[a][i]]=true;
				q.push(v[a][i]);
				dp[v[a][i]]=dp[a]+1;
			}
		}
	}
}
int nov[1000001];
bool visited[1000001];
int dp[1000001];
int dfs(vector<int> v[],int o)
{
    if(visited[o]==0)
    {
        visited[o]=1;
        for(int i=0;i<v[o].size();i++)
        {
            if(visited[v[o][i]]==0)
            {
            dp[v[o][i]]=dp[o]+1;
            nov[o]+=dfs(v,v[o][i]);
            }
        }
        return nov[o]+1;
    }
    else
    return 0;
}
// string s=bitset<64>(n).to_string();
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	ll n;
	cin>>n;
	ll a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	ll temp=0;
	for(int i=0;i<n;i++)
	{
		temp=temp^a[i];
	}
	vector<ll> ans;
	for(int i=0;i<n;i++)
	{
		ans.pb(temp^a[i]);
	}
	for(int i=0;i<n;i++)
	{
		cout<<ans[i]<<" ";
	}
	return 0;
}


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

int main(){
    string s;
    int s_len, flag;
    cin >> s ;
    s_len = s.length();
    flag=0;
    for(int i(0);i < (s_len-1)/2; i++){
        if( s[i] != s[(s_len-i-1)]){
            flag = 1;
        }
        if( s[i] != s[(s_len-2*i-3)/2]){
            flag = 1;
        }
    }
    if(flag==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
def perm_cul(N):
    return N * (N + 1) // 2
S = input()
N = len(S)
cnt_list = []
cnt = 1
ans = 0
if N == 1:
    print(1)
    exit()
for i in range(N-1):
    if S[i] == S[i+1]:
        cnt += 1
    elif S[i] != S[i+1]:
        cnt_list.append(cnt)
        cnt = 1
    if i == N-2:
        cnt_list.append(cnt)
##print(cnt_list)
if S[0] == '<' and S[N-1] == '<':
    for i in range(len(cnt_list) - 1):
        ans += perm_cul(cnt_list[i]-1)
        if i % 2 == 1:
            ans += max(cnt_list[i-1], cnt_list[i])
    ans += perm_cul(cnt_list[len(cnt_list) - 1])

elif S[0] == '<' and S[N-1] == '>':
    for i in range(len(cnt_list)):
        ans += perm_cul(cnt_list[i]-1)
        if i % 2 == 1:
            ans += max(cnt_list[i-1], cnt_list[i])

elif S[0] == '>' and S[N-1] == '>':
    ans += perm_cul(cnt_list[0])
    for i in range(1, len(cnt_list)):
        ans += perm_cul(cnt_list[i] - 1)
        if i % 2 == 0:
            ans += max(cnt_list[i-1], cnt_list[i])

else:
    ans += perm_cul(cnt_list[0])
    for i in range(1, len(cnt_list) - 1):
        ans += perm_cul(cnt_list[i]-1)
        if i % 2 == 0:
            ans += max(cnt_list[i-1], cnt_list[i])
    ans += perm_cul(cnt_list[len(cnt_list) - 1])

print(ans)

Measured memory_bytes: 6428
#include<stdio.h>
int main(void){
    int a[5],i,j,tmp;
    for(i=0;i<5;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<4;i++){
        for(j=i+1;j<5;j++){
            if(a[i]<a[j]){
                tmp=a[i];
                a[i]=a[j];
                a[j]=tmp;
            }
        }
    }
    for(i=0;i<5;i++){
        printf("%d",a[i]);
        if(i<4){
            printf(" ");
        }else{
            printf("\n");
        }
    }

    return 0;
}

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

#define endl '\n'

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define BUFF ios::sync_with_stdio(0);

typedef long long int ll;
typedef long double ld;
typedef vector < int > vi;
typedef vector < vi > vvi;
typedef pair < int, int > ii;
typedef vector < ii > vii;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const int MOD = 998244353;
const ld pi = acos(-1);

ll pow(ll x, ll y, ll m) {
  ll ret = 1;
  while (y) {
    if (y & 1) ret = (ret * x) % m;
    y >>= 1;
    x = (x * x) % m;
  }
  return ret;
}
int main() { BUFF
  ll n, m, k; cin >> n >> m >> k;
  ll acc = 0;
  vector<ll>  fact(n+10, 1), inv(n+10, 1);
  for(ll i=1; i<=n; i++) {
    fact[i] = (fact[i-1] * i) % MOD;
    inv[i] = pow(fact[i], MOD-2, MOD);
  }
  for(ll i=0; i<=k; i++) {
    ll val = ((pow(m-1, n-1-i, MOD) * m) % MOD);
    val = (val * ((((fact[n-1] * inv[i]) % MOD) * inv[n-1-i]) % MOD) % MOD);
    acc = (acc + val) % MOD;
  }
  cout << acc << endl;
  return 0;
}


Measured memory_bytes: 6432