akhauriyash/Code-Regression huggingface dataset:
from itertools import product
import numpy as np
H, W, K = map(int, input().split())

grid = [[] for _ in range(H) ]
for i in range(H):
  grid[i] = list(map(int, input()))

#print(grid)

def init_cnt():
  _grid = [[0] * W for _ in range(H) ]
  _grid[0][0] = grid[0][0]
  for w in range(1, W):
    _grid[0][w] = _grid[0][w-1] + grid[0][w]
  for h in range(1, H):
    cnt_w = 0
    for w in range(W):
      cnt_w += grid[h][w]
      _grid[h][w] = _grid[h-1][w] + cnt_w
  
  return _grid

_grid = init_cnt()
#print(_grid)

# (x1, y1) ~ (x2, y2)の合計
def cnt(x1, x2, y1, y2):
  if x1 == 0 and y1 == 0:
    return _grid[x2][y2]
  if x1 == 0:
    return _grid[x2][y2] - _grid[x2][y1 -1]
  if y1 == 0:
    return _grid[x2][y2]- _grid[x1 - 1][y2]
  return _grid[x2][y2] - _grid[x2][y1 - 1] - _grid[x1 - 1][y2] + _grid[x1 - 1][y1 - 1]


ans = 1010
for i in range(2 ** (H - 1)):
  res = 0
  lst = list(k for k, j in enumerate(range(H), 1) if i >> j & 1)
  res += len(lst)
  lst.append(H)
 
  #print(lst)
  y =  0
  for w in range(1, W+1):
    x = 0
    flag = False
    
    for lst_i in lst:
      if cnt(x, lst_i - 1 ,y ,w - 1) > K:
        if y + 1 < w:
          res += 1
          y = w - 1
        else:
          flag = True
        break
        
      x = lst_i 
    else:
      pass
    if flag:
      break
  else:
    ans = min(ans, res)
    
print(ans)

Measured memory_bytes: 12620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+10;
const double pi = acos(-1);
int n,c[N],a;
int main(){
    scanf("%d",&n);
    for(int i=1;i<n;++i){
        scanf("%d",&a);
        c[a]++;
    }
    for(int i=1;i<=n;++i) printf("%d\n",c[i]);
}

Measured memory_bytes: 4608
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)                                 //g++ template.cpp -o template.exe
#define zeroes(x) memset(x,0,sizeof(x))                                        //all elements to 0  |  \
#define all(x) (x).begin(), (x).end()
typedef long long int ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn=100000;







bool sortbysec(const pair<int,int> &a,                         //sorting of elements wrt second
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 




int main()
{
    int a;
    cin>>a;
    cout<<a+a*a+a*a*a;

    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int k, n, a[200005],ans;
int main(){
	cin>>k>>n;
	for(int i=1;i<=n;i++){ 
		cin>>a[i];	 
	}
	sort(a+1, a+1+n);
	for(int i=2;i<=n;i++)
		ans=max(ans, a[i]-a[i-1]);
	ans=max(ans, k-a[n]+a[1]);
	cout<<k-ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int cnt[300];
int main(void){
    string s; cin >> s;
    for (int i = 0; i < 4; i++) {
        cnt[s[i]]++;
    }
    for (int i = 0; i < 300; i++) {
        if (cnt[i] != 0 && cnt[i] != 2) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long int ll;

ll n,m,a,b,c,x,y,aa[100010],ba[100010];
bool r,br,ar;
string s;
char ca,cb;


int main(){
    cin>>a>>b>>c;
    r=(a*100+b*10+c)%4==0;
    cout<<(r ? "YES":"NO")<<endl;
    
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
using namespace std;
#include<algorithm>
#include<set>
#include<vector>
#define rep(i,n) for(int i=0;i<(n);i++)

const int mod=1000000007;


int main(){
int a,b;
cin>>a>>b;
rep(pr,10000){
int za=pr*8/100;
int zb=pr*1/10;
if(za==a&&zb==b){
  cout<<pr<<endl;
  return 0;
}
}
cout<<-1<<endl;
return 0;
}

Measured memory_bytes: 3184
A,B,K = map(int,input().split())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
a = make_divisors(A)
b = make_divisors(B)
c = sorted(set(a)&set(b))
print(list(c)[-K])

Measured memory_bytes: 3060
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define fo(i,a,b) for(int i=a,__=b;i<=__;++i)
#define rep(i,a,b) for(int i=a,__=b;i<__;++i)
#define fd(i,a,b) for(int i=a,__=b;i>=__;--i)
#define ll long long
#define mo 1000000007

using namespace std;

int f[200100],n,ls[200100],t;
struct ran{int l,r;}r[200100];
bool cmp(ran a,ran b){return a.l<b.l;}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		int x;scanf("%d",&x);
		if(ls[x]&&ls[x]+1<i)r[++t]=(ran){ls[x],i-1};
		ls[x]=i;
	}f[0]=1;sort(r+1,r+t+1,cmp);
	for(int i=1,a=1;i<=n;++i){
		f[i]=(f[i-1]+f[i])%mo;
		for(;a<=t&&r[a].l==i;++a)f[r[a].r+1]=(f[r[a].r+1]+f[i])%mo;
	}printf("%d",f[n]);
}

Measured memory_bytes: 2560
from sys import stdin
N = int(stdin.readline().rstrip())
H = [int(x) for x in stdin.readline().rstrip().split()]
dp = [0]*N
dp[1] = abs(H[0]-H[1])
for i in range(2,N):
    dp[i] = min(dp[i-1]+abs(H[i]-H[i-1]),dp[i-2]+abs(H[i]-H[i-2]))
print(dp[-1])

Measured memory_bytes: 13928
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 200005;
int N, a[maxn];
long long s[maxn];
int main() {
	scanf("%d", &N);
	for(int i = 1; i <= N; ++i) {
		scanf("%d", a + i);
		s[i] = s[i - 1] + a[i];
	}
	long long ans = ~0ULL>>1;
	for(int i = 1; i < N; ++i) {
		if(s[i] < s[N] - s[i]) 
			ans = min(ans, s[N] - s[i] - s[i]);
		else 
			ans = min(ans, s[i] + s[i] - s[N]);
	}
	printf("%lld\n", ans);
	return 0;
}
 


Measured memory_bytes: 2560
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int D = sc.nextInt();
        int xtt = sc.nextInt();
        for(int i=1; i<11;i++) {
          if(i!=1){System.out.print("\n");}
            xtt = (r*xtt)-D;
            // 出力
            System.out.print(xtt);
        }
    }
}

Measured memory_bytes: 23380
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
key = True
if n%2:
  key = False
ans = True
for i in range(n):
  if key:
    if a[i] != (i//2)*2+1:
      ans = False
      break
  else:
    if a[i] != ((i+1)//2)*2:
      ans = False
      break

if ans:
  print(pow(2, n//2, pow(10, 9)+7))
else:
  print(0)


Measured memory_bytes: 13880
#include "bits/stdc++.h"
#define double long double
#define int long long
#define mii map<int,int>
#define low lower_bound
#define upp upper_bound
#define inf 1000000007 //10^9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define sort(vec) sort(all(vec));
#define rever(vec) reverse(all(vec));
#define bisea binary_search
#define cend cout<<endl;
#define F first
#define S second
using namespace std;
signed main() {
  int n,k;
  cin>>n>>k;
  int d[k];
  bool can=true;
  rep(i,k) cin>>d[i];
  while(1) {
    string a=to_string(n);
    int e=a.size();
    rep(i,e) {
      rep(j,k) {
        if(a[i]-'0'==d[j]) {
          can=false;
        }
      }
    }
    if(can) {
      cout<<a<<endl;
      break;
    }
    can=true;
    n++;
  }
}

Measured memory_bytes: 256
import java.util.*;

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

    int[] c = new int[n];
    int[][] a = new int[n][m];
    int ans = Integer.MAX_VALUE;

    for(int i=0; i<n; i++){
      c[i] = sc.nextInt();
      for(int j=0; j<m; j++){
        a[i][j] = sc.nextInt();
      }
    }

    for(int i=0; i<(1<<n); i++){
      int[] total = new int[m];
      int cost = 0;
      int flag = 0;

      for(int j=0; j<n; j++){
        if((i>>j&1)==1){
          for(int k=0; k<m; k++){
            total[k] += a[j][k];
          }
          cost += c[j];
        }
      }
      for(int j=0; j<m; j++){
        if(total[j]>=x)
          flag += 1;
      }

      if(flag==m){

        if(cost<ans){
          ans = cost;
        }
      }

    }

    if(ans==Integer.MAX_VALUE)
      ans = -1;

    System.out.println(ans);
  }
}

Measured memory_bytes: 37292
data_list = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
bingo_list = [int(input()) for _ in range(N)]
mark = [[False, False, False] for _ in range(3)]
for i in range(3):
    for j in range(3):
        if data_list[i][j] in bingo_list:
            mark[i][j] = True
ans = "No"
for i in range(3):
    if all(mark[i]):
        ans = "Yes"
        break
for j in range(3):
    if mark[0][j] and mark[1][j] and mark[2][j]:
        ans = "Yes"
        break
if (mark[0][0] and mark[1][1] and mark[2][2]) or (mark[2][0] and mark[1][1] and mark[0][2]) :
    ans = "Yes"
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/
void solve(vl&ans, ll v){
    ans.push_back(v);
    ll p=v%10;
    range(d,-1,2){
        if(p==0 and d==-1)continue;
        if(p==9 and d==1)continue;
        if(v*10+p+d>3234566667)continue;
        solve(ans, v*10+p+d);
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vl ans;
    range(i,1,10)solve(ans,i);
    sort(all(ans));
    puta(ans[n-1]);
    return 0;
}

Measured memory_bytes: 1400
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharpSample01
{
	class Program
	{

		static void Main(string[] args)
		{
			var N = long.Parse(Console.ReadLine());

			var valueList = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			// 最大値
			var max = valueList.Max();
			var countArray = new int[max + 1];
			var count = 0;
			var flag = false;

			for(int i = 0;i < N; i++)
			{
				var value = valueList[i];
				flag = false;
				var kakeruValue = 1;
				while (!flag)
				{
					countArray[value * kakeruValue]++;
					kakeruValue++;
					if(value * kakeruValue > max)
					{
						flag = true;
					}
				}
			}

			for(int x = 0;x < N; x++)
			{
				var value = valueList[x];

				if(countArray[value] == 1)
				{
					count++;
				}
			}

			Console.WriteLine(count);
		}
	}
}

Measured memory_bytes: 47328
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin>>N>>M;
  vector<set<int>> A(N);
  for(int i=0;i<M;i++){
    int a,b;
    cin>>a>>b;
    A[a-1].insert(b-1);
    A[b-1].insert(a-1);
  }
  queue<pair<int,int>> B;
  vector<int> C(N,0);
  B.push(make_pair(0,0));
  int a=N;
  while(true){
    pair<int,int> D=B.front();
    B.pop();
    if(C.at(D.first)==0){
      C.at(D.first)=D.second+1;
      a--;
      if(a==0)
        break;
      for(int i:A.at(D.first))
        B.push(make_pair(i,D.first));
    }
  }
  cout<<"Yes"<<endl;
  for(int i=1;i<N;i++)
    cout<<C.at(i)<<endl;
}

Measured memory_bytes: 29596
#include<bits/stdc++.h>
using namespace std;
const double EPS=1e-10;
double x[4],y[4];
int main(){
    int n;
    cin>>n;
    while(n--){
        for(int i=0;i<4;i++)cin>>x[i]>>y[i];
        for(int i=0;i<4;i+=2){
            x[i]-=x[i+1];y[i]-=y[i+1];
        }
        if(fabs(x[0]*y[2]-x[2]*y[0])<EPS)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

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


int main(){
    int n;
    cin>>n;
    int h[n];

    for(int i=0; i<n; i++){
        cin>>h[i];
    }

    int point = h[0]-1;

    for(int i=1; i<n; i++){
        if(point < h[i]){
            point = h[i] - 1;
        }
        else if(point == h[i]){
        }
        else{
            cout<<"No"<<endl;
            return 0;
        }
    }

    cout<<"Yes"<<endl;
}

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

int frogBU(int h[],int n,int dp[]){
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);

    for(int i=2;i<n;i++){
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }

    return dp[n-1];
}

int main() {
  int n;
  cin >> n;
  
  int *dp = new int[n+1]{0};
  int *arr = new int[n];
  for(int i=0;i<n;i++){
  	cin >> arr[i];
  }
  
  cout << frogBU(arr, n, dp) << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <deque>
#include <thread>

using namespace std;

int main()
{
    int n;
    long long int a[100010];
    long long int min_sub = 1000000010;
    int ind;

    cin >> n;

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

    sort(a, a+n);

    for (int i = 0; i < n-1; i++) {
        long long int sub = a[n-1] - a[i];
        if (abs(sub-(a[n-1]/2)) < min_sub) {
            min_sub = abs(sub-(a[n-1]/2));
            ind = i;
        }
    }

    cout << a[n-1] << " " << a[ind] << endl;
}


Measured memory_bytes: 1024
#define DEBUG 0

/**
 * File    : D.cpp
 * Author  : Kazune Takahashi
 * Created : 2019-5-26 21:13:56
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(10101010));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;
int N, K;
int X[100];

int _solve(vector<int> V, int k)
{
  int ans = 0;
  for (auto i = 0; i <= min((int)V.size(), k); i++)
  {
    vector<int> W;
    for (auto j = 0; j < i; j++)
    {
      W.push_back(V[j]);
    }
    sort(W.begin(), W.end());
    int n = k - i;
    int ind = 0;
    for (auto j = 0; j < min(n, (int)W.size()); j++)
    {
      if (W[j] < 0)
      {
        ind++;
      }
    }
    int t = 0;
    for (auto j = ind; j < (int)W.size(); j++)
    {
      t += W[j];
    }
    ans = max(ans, t);
  }
  return ans;
}

int solve(vector<int> V, vector<int> W)
{
  int ans = 0;
  for (auto i = 0; i <= K; i++)
  {
    ans = max(ans, _solve(V, i) + _solve(W, K - i));
  }
  return ans;
}

int main()
{
  cin >> N >> K;
  for (auto i = 0; i < N; i++)
  {
    cin >> X[i];
  }
  int ans = 0;
  for (auto i = 0; i <= N; i++)
  {
    vector<int> V, W;
    for (auto j = 0; j < i; j++)
    {
      V.push_back(X[j]);
    }
    for (auto j = N - 1; j >= i; j--)
    {
      W.push_back(X[j]);
    }
#if DEBUG == 1
    cerr << "V :";
    for (auto x : V)
    {
      cerr << x << " ";
    }
    cerr << endl;
    cerr << "W :";
    for (auto x : W)
    {
      cerr << x << " ";
    }
    cerr << endl;
#endif
    ans = max(ans, solve(V, W));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
string a;
string b;
cin>>a;
cin>>b;
if((a[0]==b[2])&&(a[1]==b[1])&&(a[2]==b[0])){
cout<<"YES"<<endl;
}
else{
cout<<"NO"<<endl;
}


}

Measured memory_bytes: 256
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_1_D&lang=jp

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

map<ll, int> PrimeFactor(ll a){
    map<ll, int> mp;

    while(true){
        bool found = false;
        for(ll i = 2; i * i <= a; i++){
            if(a % i == 0){
                mp[i]++;
                a /= i;
                found = true;
                break;
            }
        }

        if(!found){
            mp[a]++;
            break;
        }
    }

    return mp;
}

//====================================================

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

    map<ll, int> mp = PrimeFactor(N);
    vector<ll> primes;
    for(auto it = mp.begin(); it != mp.end(); it++){
        primes.push_back(it -> first);
    }

    int sz = primes.size();

    ll ans = 0;
    for(int msk = 1; msk < (1 << sz); msk++){
        int cnt = 0;
        ll div = 1; //わるかず
        for(int i = 0; i < sz; i++){
            if(msk & (1 << i)){
                cnt++;
                div *= primes[i];
            }
        }

        if(cnt % 2 == 0){
            ans -= N / div;
        }
        else {
            ans += N / div;
        }
    }

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


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

int main(void){
    //input
    long long int N,M;
    cin >>N>>M;
     
    //count cards of odd-doses flip
    //but N<10^9 so can just O(N) or lesser computation time

    cout<<abs((N-2)*(M-2))<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 5000

int getsign(int d){
    return d >= 0 ? 1 : -1;
}

int seqsum(int n){
    int a[N];
    int b[N];
    int c = 0;
    int s = 0;

    scanf("%d", a);
    b[0] = a[0];
    s = getsign(a[0]);

    for(int i=1; i<n; ++i){
        scanf("%d", a+i);
        if(s == getsign(a[i])){
            b[c] += a[i];
        }else{
            b[++c] = a[i];
            s = getsign(a[i]);
        }
    }

    int m = b[0];
    if(c == 0){
        if(m >= 0){ return m; }
        m = a[0];
        for(int i=1; i<n; ++i){
            if(m < a[i]){
                m = a[i];
            }
        }
        return m;
    }

    m = a[0] = b[0];
    for(int i=1; i<=c; ++i){
        a[i] = a[i-1] < 0 ? b[i] : a[i-1] + b[i];
        if(m < a[i]){
            m = a[i];
        }
    }

    return m;
}

int main(void){
    int n = 0;
    while(true){
        scanf("%d", &n);
        if(n == 0){ break;}
        printf("%d\n", seqsum(n));
    }
    return 0;
}

Measured memory_bytes: 1056
N, x = map(int, input().split())
A = sorted(list(map(int, input().split())))
S = [0]
for i in range(N):
    S.append(S[i] + A[i])
# print(S)
l = -1
r = N+1
while r - l > 1:
    m = l + (r-l)//2
    if S[m] > x:
        r = m
    else:
        l = m
print(l - (l == N and S[l] < x))


Measured memory_bytes: 38256
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007


int N;
int A[100005];
//最長部分広義減少列を求めます
//はめんどくさいので、Aの中身の符号を逆にして最長部分広義増加列を求めます
int LIS(int *A,const int A_len){
    int dp[A_len+5];
    rep(i,A_len+3)dp[i]=LLINF;
    dp[0]=-A[0];
    //dpは広義単調増加、出来るだけ小さく更新したい
    for(int i=1;i<A_len;i++){
        //二分探索で更新箇所を求める 
        //追加した文字がdp[i]以上ならばもっと伸ばせる
        //(更新場所は、追加した文字より大きいところで一番小さいの)
        int p=upper_bound(dp,dp+A_len,-A[i])-dp;
        //大きいところがあればそこを更新する
        if(p>0)dp[p]=-A[i];
        else if(dp[p]>-A[i])dp[p]=-A[i];
    }
    //一番最後の更新されたところを探す
    //rep(i,A_len)printf("%lld/",dp[i]);
    int p=lower_bound(dp,dp+A_len,LLINF)-dp;
    return p;
}
signed main(){
    scanf("%lld",&N);
    rep(i,N)scanf("%lld\n",&A[i]);
    int ans=LIS(A,N);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

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

	int a, b, c;
	cin >> a >> b >> c;
	if (a + b >= c) {
		cout << "Yes" << "\n";
	}
	else {
		cout << "No" << "\n";
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string op;
  int A, B, ans;
  
  // ここにプログラムを追記
  cin >> A >> op >> B;
  
  if (op == "+") {
    ans = A + B;
  }
  else {
    ans = A - B;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    ll N, A, B;
    cin >> N >> A >> B;

    ll div = N/(A+B);
    ll ans = A*div + min(N%(A+B),A);
    cout << ans;
    return 0;
}


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

#define max 3

int main()
{
    int A, B;
    char str[max][11];
    
    scanf("%s %s", str[0], str[1]);
    scanf("%d %d", &A, &B);
    scanf("%s", str[2]);
    
    if(strcmp(str[0], str[2])==0){
        A--;
    }else if(strcmp(str[1], str[2])==0){
        B--;
    }
    
    printf("%d %d", A, B);
    
    return 0;
}


Measured memory_bytes: 128
n,k = map(int,input().split())
li = list(map(int,input().split()))
ans = [0]*(n+1)
tmp = [0]*(n+1)
tmp_sum = []
#print(ans)
#[0, 0, 0, 0, 0]
k = min(k,100)

for kkk in range(k):
    #print(li,'li')
    for i,l in enumerate(li):
        if l != 0:
            start = max(0,i-l)
            end = min(n,i+l+1)
            #print(start,'start',end,'end')
            tmp[start] += 1
            #print(end,len(tmp),'aaa')
            tmp[end] -= 1
    #print(tmp,'tmp')
    last = 0
    for t in tmp:
        last = t+last
        tmp_sum.append(last)
    for i,l in enumerate(li):
        if l == 0:
            tmp_sum[i] += 1
    ans = tmp_sum[:n]
    li = tmp_sum[:n]
    tmp = [0]*(n+1)
    tmp_sum = []
    #if len(set(ans)) == 1:
    #    break
print(*ans)

Measured memory_bytes: 242064
# coding: utf-8


import sys
sys.setrecursionlimit(int(1e6))


class Graph(object):
    def __init__(self, N):
        self.N = N
        self.paths = [None] * (N + 1)
        for i in range(1, N + 1):
            self.paths[i] = set()

    def path(self, n1, n2):
        self.paths[n1].add(n2)
        self.paths[n2].add(n1)

    def dfs(self, n, f):
        # fからNへの最短経路を探す
        if n == self.N:
            return [n]
        for nn in self.paths[n]:
            if nn != f:
                path = self.dfs(nn, n)
                if path is not None:
                    path.append(n)
                    return path
        return None

    def region(self, start, block, f):
        # startからblockを経由せず行ける範囲のnode数
        s = 1
        for nn in self.paths[start]:
            if nn != f and nn != block:
                s += self.region(nn, block, start)
        return s


def main():
    N = int(input())
    graph = Graph(N)
    for i in range(N-1):
        n1, n2 = map(int, input().split())
        graph.path(n1, n2)
    path = graph.dfs(1, None)
    l = len(path)
    fb = path[l // 2]
    sb = path[l // 2 - 1]
    fr = graph.region(1, sb, None)
    sr = graph.region(N, fb, None)
    # print(fr)
    # print(sr)
    if fr > sr:
        print("Fennec")
    else:
        print("Snuke")


main()


Measured memory_bytes: 122228
S = input()

res = 0
for i in range(len(S)):
    h = 'gp'[i % 2]
    if S[i] == 'g' and h == 'p':
        res += 1
    elif S[i] == 'p' and h == 'g':
        res -= 1
    else:
        pass

print(res)

Measured memory_bytes: 3316
N, X, M = map(int, input().split())

appearance = [0] * (M + 1)
cum_sum = [0]
A = X
appearance[A] = 1
cum_sum.append(A)
a = 1
for a in range(2, N + 1):
    A = (A**2)%M
    if appearance[A] != 0:
        n = a - 1
        break
    appearance[A] = a
    cum_sum.append(cum_sum[a - 1] + A)
else: n = a

k = appearance[A]
l = (N - n) // (n - k + 1)
m = (N - n) - (n - k + 1)*l + k - 1

ans = cum_sum[n] + (cum_sum[n] - cum_sum[k - 1])*l + cum_sum[m] - cum_sum[k - 1]
print(ans)

Measured memory_bytes: 68536
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,N) for(int i = 0;i < (int)(N);i++)
int main(){
  int a,b;
  cin>>a>>b;
  int x=1;
  rep(i,1001){
    if(x*8/100==a&&x*10/100==b) break;
    x++;
  }
if(x<=1000) {
  cout<<x<<endl;
}
else if(x=1001){
  x=-1;
  cout<<x<<endl;
}
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <climits>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;
// scanf
#pragma warning(disable: 4996)
// v:vector  type:型  order:greater or less
#define _sort(v,type,order) do { sort(v.begin(),v.end(),order<type>()); } while(0)
// v:vector  default_value:初期値
#define _sum(v,default_value) accumulate(v.begin(),v.end(),default_value )
// 丸め
#define _round(v) round(v)
// 2乗 / 3乗
#define _square(v) pow(v,2)
#define _cube(v)   pow(v,3)
// 大小判定
#define _max(x,y) max(x,y)
#define _min(x,y) min(x,y)

int main()
{
	uint32_t n;
	cin >> n;

	vector<uint32_t> v(101,0);
	uint32_t temp;
	for (uint32_t i = 0; i < n; i++) {
		cin >> temp;
		v[temp]++;
	}
	uint32_t sub = 0;
	for (uint32_t i = 1; i < 101; i++) {
		if (!v[i]) { continue; }
		sub += v[i] - 1;
	}
	printf("%d\n", n - sub);
	return 0;
	//	std::cout << "Hello World!\n"; 
}


Measured memory_bytes: 256
public class Main {

  private static void solve() {
    int n = ni();
    int[] x = na(n);

    int ret = Integer.MAX_VALUE;
    for (int j = 0; j <= 100; j++) {
      int now = 0;
      for (int i = 0; i < n; i++) {
        now += (j - x[i]) * (j - x[i]);
      }
      ret = Math.min(ret, now);
    }
    System.out.println(ret);

  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}



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

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

    vector<int> A(N);

    A.at(0) = -1;
    for (int i = 1; i < A.size(); ++i)
        cin >> A.at(i);

    vector<vector<int>> sub(N);
    for (int i = 1; i < N; i++)
    {
        int leader = A.at(i) - 1;    // i番の上司の番号
        sub.at(leader).push_back(i); // 上司の部下一覧にi番を追加
    }
    for (int i = 0; i < N; ++i)
        cout << sub.at(i).size() << endl;
}

Measured memory_bytes: 14720
#include <iostream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <limits>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <unordered_map>
#include <random>
#include <cmath>
#include <complex>
// #include "utiltime.hpp"

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef complex<double> cdouble;

const int INFL = (int)1e9;
const ll INFLL = (ll)1e18;
const double INFD = numeric_limits<double>::infinity();
const double PI = 3.14159265358979323846;
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loopll(i, n) for(ll i = 0; i < (ll)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopll1(i, n) for(ll i = 1; i <= (ll)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Looprll(i, n) for(ll i = (ll)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define Looprll1(i, n) for(ll i = (ll)n; i >= 1; i--)
#define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++)
#define printv(vector) Loop(i, vector.size()) { cout << vector[i] << " "; } cout << endl;
#define printmx(matrix) Loop(i, matrix.size()) { Loop(j, matrix[i].size()) { cout << matrix[i][j] << " "; } cout << endl; }
#define quickio() ios::sync_with_stdio(false); cin.tie(0);
#define readfile(filename) ifstream in(filename); cin.rdbuf(in.rdbuf());
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
bool nearlyeq(double x, double y) { return abs(x - y) < 1e6; }
ll rndf(double x) { return (ll)(x + (x >= 0 ? 0.5 : -0.5)); }
ll floorsqrt(double x) { ll m = (ll)sqrt(x); return m + (m * m <= (ll)(x) ? 0 : -1); }
ll ceilsqrt(double x) { ll m = (ll)sqrt(x); return m + ((ll)x <= m * m ? 0 : 1); }
ll rnddiv(ll a, ll b) { return (a / b + (a % b * 2 >= b ? 1 : 0)); }
ll ceildiv(ll a, ll b) { return (a / b + (a % b == 0 ? 0 : 1)); }
ll gcd(ll m, ll n) { if (n == 0) return m; else return gcd(n, m % n); }

/*******************************************************/

void failed() {
	cout << -1 << endl;
	exit(0);
}

int main() {
	string s; cin >> s;
	int n = s.length();
	if (s[0] == '0' || s[n - 1] == '1') failed();
	s.pop_back();
	string t = s;
	reverse(t.begin(), t.end());
	if (s != t) failed();
	vector<P> ans;
	if (n == 2) ans = { {1,2} };
	else if (n == 3) ans = { {1,2},{2,3} };
	else {
		vi v = { 1 };
		Loop1(i, n / 2 - 1) {
			if (s[i] == '0') {
				v.push_back(i + 1);
			}
			else {
				Loop(j, v.size()) {
					ans.push_back({ v[j], i + 1 });
				}
				v = { i + 1 };
			}
		}
		Loop(j, v.size()) {
			ans.push_back({ v[j], n / 2 + 1 });
		}
		for (int i = n / 2 + 1; i < n; ++i) {
			ans.push_back({ i + 1, n / 2 + 1 });
		}
	}
	Loop(i, ans.size()) {
		cout << ans[i].first << " " << ans[i].second << endl;
	}
}

Measured memory_bytes: 2548
from fractions import gcd
mod = 10**9+7
n = int(input())
A = list(map(int, input().split()))
m = A[0]
for i in range(1, n):
  m = A[i] // gcd(m, A[i]) * m
ans = 0
for i in A:
  ans += m//i
print(ans%mod)

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

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L

#define long long long int

using namespace std;

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int m1 = -1;
    int m2 = -1;
    for (int i = 0; i < n; i++) {
        if (m1 == -1 || a[i] > a[m1]) {
            m1 = i;
        } else if (m2 == -1 || a[i] > a[m2]) {
            m2 = i;
        }
    }
    for (int i = 0; i < n; i++) {
        if (i == m1) {
            cout << a[m2];
        } else {
            cout << a[m1];
        }
        cout << "\n";
    }
    return 0;
}

Measured memory_bytes: 2432
using System;
using System.Collections.Generic;
using System.Linq;

namespace MyProgram{
    class AtCoder{
        static void Main(){
            var N = long.Parse(Console.ReadLine());
            var A = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
            var dict = new Dictionary<long,long>();
            for(var i=0;i<N;i++){
                if(!dict.ContainsKey(A[i]))dict[A[i]] = 0;
                else{
                    Console.WriteLine("NO");
                    return;
                }
            }
            Console.WriteLine("YES");
        }
    }
}


Measured memory_bytes: 41296
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);


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

  // a~z が j 番目以降に何個含まれるか
  vector<vector<int>> n(26, vector<int>(s.size() + 1, 0));

  for (int i = s.size() - 1; i >= 0; i--) {
    for (int j = 0; j < 26; j++) {
      if ('a' + j == s[i]) {
        n[j][i] = n[j][i+1] + 1;
      } else {
        n[j][i] = n[j][i+1];
      }
    }
  }

  ll ans = 1;  // 何もしない
  for (int i = 0; i < s.size() - 1; i++) {
    // i+1 から最後までの文字数から s[i] の数を引く
    ans += s.size() - (i+1) - n[s[i] - 'a'][i+1];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 21764
#include "bits/stdc++.h"
using namespace std;
void BFS(vector<vector<char>>& Maze, int H, int W, pair<int, int>Start, vector<vector<int>>& Count, vector<vector<bool>>& reach) {
	queue<pair<int, int>>Q;
	reach.at(Start.second).at(Start.first) = true;
	Count.at(Start.second).at(Start.first) = 1;
	Q.push(Start);
	while (!Q.empty()) {
		pair<int, int>P = Q.front(); Q.pop();
		if (P.first > 0) {
			if (Maze.at(P.second).at(P.first - 1) == '.' && !reach.at(P.second).at(P.first - 1)) {
				reach.at(P.second).at(P.first - 1) = true;
				Count.at(P.second).at(P.first - 1) = Count.at(P.second).at(P.first) + 1;
				Q.push(make_pair(P.first - 1, P.second));
			}
		}
		if (P.first < W - 1) {
			if (Maze.at(P.second).at(P.first + 1) == '.' && !reach.at(P.second).at(P.first + 1)) {
				reach.at(P.second).at(P.first + 1) = true;
				Count.at(P.second).at(P.first + 1) = Count.at(P.second).at(P.first) + 1;
				Q.push(make_pair(P.first + 1, P.second));
			}
		}
		if (P.second > 0) {
			if (Maze.at(P.second - 1).at(P.first) == '.' && !reach.at(P.second - 1).at(P.first)) {
				reach.at(P.second - 1).at(P.first) = true;
				Count.at(P.second - 1).at(P.first) = Count.at(P.second).at(P.first) + 1;
				Q.push(make_pair(P.first, P.second - 1));
			}
		}
		if (P.second < H - 1) {
			if (Maze.at(P.second + 1).at(P.first) == '.' && !reach.at(P.second + 1).at(P.first)) {
				reach.at(P.second + 1).at(P.first) = true;
				Count.at(P.second + 1).at(P.first) = Count.at(P.second).at(P.first) + 1;
				Q.push(make_pair(P.first, P.second + 1));
			}
		}
	}
}
int main() {
	int H, W;
	cin >> H >> W;
	vector<vector<char>>Maze(H, vector<char>(W));
	int black = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> Maze.at(i).at(j);
			if (Maze.at(i).at(j) != '#') black++;
		}
	}
	vector<vector<int>>Count(H, vector<int>(W, 1000000007));
	vector<vector<bool>>reach(H, vector<bool>(W, false));
	BFS(Maze, H, W, make_pair(0, 0), Count, reach);
	if (Count.at(H - 1).at(W - 1) != 1000000007) {
		cout << black - Count.at(H - 1).at(W - 1) << endl;
	}
	else cout << -1 << endl;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.HashMap;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            Long[] a = new Long[n];
            HashMap<Long, Long> hm = new HashMap<>();
            for (int i = 0; i < n; i++) {
                a[i] = in.nextLong();
                if (hm.containsKey(a[i]))
                    hm.put(a[i], hm.get(a[i]) + 1);
                else
                    hm.put(a[i], 1L);
            }
            Arrays.sort(a, (x1, x2) -> Long.compare(x2, x1));
            long s = 0;
            for (int i = 0; i < n; i++) {
                long t = a[i];
                if (!hm.containsKey(t))
                    continue;
                if (hm.get(t) >= 4) {
                    if (s > 0)
                        out.println(s * t);
                    else
                        out.println(t * t);
                    return;
                } else if (hm.get(t) >= 2) {
                    if (s == 0) {
                        s = t;
                        hm.remove(t);
                    } else {
                        out.println(s * t);
                        return;
                    }
                }
            }

            out.println(0);
        }

    }

    static class InputReader {
        StringTokenizer st;
        BufferedReader br;

        public InputReader(InputStream is) {
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            this.br = br;
        }

        public String next() {
            if (st == null || !st.hasMoreTokens()) {
                String nextLine = null;
                try {
                    nextLine = br.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                if (nextLine == null)
                    return null;
                st = new StringTokenizer(nextLine);
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}
 

Measured memory_bytes: 46500
#include<stdio.h>
int main()
{
  int i, x;
  char s[2];
  char t[2];
  scanf("%s",s);
  scanf("%s",t);
  
  x = 0;
  for(i=0;i<3;i++)
  {
    if(s[i] == t[i])
      x = x + 1;
  }
  printf("%d",x);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

struct union_find {
    vector<ll> par;
    vector<ll> rank;
    vector<ll> count;

    union_find(ll n) : par(n, 0), rank(n, 0), count(n, 1) {
        for(ll i = 0; i < n; ++i){ par.at(i) = i; }
    }

    ll find(ll x){
        if(par.at(x) == x){
            return x;
        }else{
            return par.at(x) = find(par.at(x));
        }
    }

    void unite(ll x, ll y){
        x = find(x);
        y = find(y);
        if(x == y){ return; }
        if(rank.at(x) < rank.at(y)){
            par.at(x) = y;
        }else{
            par.at(y) = x;
            if(rank.at(x) == rank.at(y)){
                rank.at(x)++;
            }
        }

        ll new_count = count.at(x) + count.at(y);
        count.at(find(x)) = new_count;
    }

    bool same(ll x, ll y){
        return find(x) == find(y);
    }

    ll size(ll x){
        return count.at(find(x));
    }
};


int main(){
    ll n, k, l;
    cin >> n >> k >> l;
    union_find road(n);
    REP(i, k){
        ll p, q;
        cin >> p >> q;
        p--; q--;
        road.unite(p, q);
    }
    union_find rail(n);
    REP(i, l){
        ll r, s;
        cin >> r >> s;
        r--; s--;
        rail.unite(r, s);
    }

    map<pair<ll, ll>, ll> count;
    REP(i, n){
        count[make_pair(road.find(i), rail.find(i))]++;
    }
    REP(i, n){
        cout << count.at(make_pair(road.find(i), rail.find(i)));
        if(i < n - 1){
            cout << ' ';
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 21120
N, M, K = map(int, input().split())
mod = 998244353

facs = [1] * N
invs = [1] * N
nfac = 1
for i in range(1, N):
    nfac = nfac * i % mod
    facs[i] = nfac
    invs[i] = pow(facs[i], mod-2, mod)

s = 0
for i in range(K+1):
    d = facs[N-1] * invs[i] * invs[N-1-i] \
        * M * pow(M-1, N-1-i, mod) % mod
    s = (s + d) % mod

print(s)

Measured memory_bytes: 24656
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

#include <vector>
using namespace std;
using i64 = long long;


struct QuickFind{
  vector<int> gi;
  vector<vector<int>> vg;
  int n;

  QuickFind(int size) : n(size){
    gi.resize(n);
    vg.resize(n);
    for(int i = 0;i < n;i++){
      gi[i] = i;
      vg[i].push_back(i);
    }
  }
  bool same_group(int a,int b){
    return gi[a] == gi[b];
  }
  void merge(int a,int b){
    int ga = gi[a];
    int gb = gi[b];
    if(ga == gb) return;
    if(vg[ga].size() < vg[gb].size()) swap(ga,gb);
    for(int j : vg[gb]) gi[j] = ga;
    vg[ga].insert(vg[ga].end(),vg[gb].begin(),vg[gb].end());
    vg[gb].clear();
  }
};


int main(){
  int N,Q;
  cin >> N >> Q;
  QuickFind qf(N);
  rep(i,0,Q - 1){
    int c,x,y;
    cin >> c >> x >> y;
    if(c == 0){
      qf.merge(x,y);
    }
    else{
      if(qf.same_group(x,y)){
        cout << "1\n";
      }
      else{
        cout << "0\n";
      }
    }
  }
}



Measured memory_bytes: 3728
#include <iostream>

using namespace std;

int main(void){
  char c[3][3];
  int i, j;
  for(i=0; i<3; i++)
    for(j=0; j<3; j++)
      cin >> c[i][j];

  for(i=0; i<3; i++)
    for(j=0; j<3; j++)
      if(i == j)
	cout << c[i][j];
  
  cout << endl;
    
  return 0;
}


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

using namespace std;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

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

template<class T>
ostream &operator<<(ostream &os, const vector <T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair <T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

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

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;

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

    // ifstream in("in.txt");
    // cin.rdbuf(in.rdbuf());

    for (;;) {
        int N, M; cin >> N >> M;
        if (N == 0) break;
        vvi G(N);
        REP(i, M) {
            int u, v; cin >> u >> v; --u, --v;
            G[u].push_back(v);
            G[v].push_back(u);
        }

        vi color(N);

        function<int(int,int)> dfs = [&](int v,int c) {
            if (color[v] == c) return 1;
            if (color[v] == -c) return 0;
            color[v] = c;
            int ret = 1;
            for (int u : G[v]) {
                ret &= dfs(u, -c);
            }
            return ret;
        };

        if (!dfs(0, 1)) {
            cout << 0 << endl;
            continue;
        }

        map<int,int> cnt;
        for (int c : color) ++cnt[c];

        map<int,int> ans;
        if (cnt[-1] % 2 == 0) ans[cnt[-1] / 2] = 1;
        if (cnt[1] % 2 == 0) ans[cnt[1] / 2] = 1;

        cout << ans.size() << endl;
        for (auto &tp : ans) cout << tp.first << endl;
    }

    return 0;
}




Measured memory_bytes: 3252
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a[n];
    int b[n];
    int c[n];
    for (int i = 0; i < n; ++i)
    {
     cin >> a[i];
    }
    for (int i = 0; i < n; ++i)
    {
     cin >> b[i];
    }
    for (int i = 0; i < n-1; ++i)
    {
     cin >> c[i];
    }
    int ans = 0;
    for (int i = 0; i < n; ++i)
    {
        ans+= b[i];
    }
    int k = a[0];
    for (int i = 1; i < n; ++i)
    {
        if (a[i] == k+1)
        {
            ans+= c[a[i]-2];
        }
        k = a[i];
    }
    cout << ans;
}


Measured memory_bytes: 256