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

using namespace std;

int main()
{
    int k,n,temp=0;
    cin>>n>>k;
    int a[n],i,ans[k+1],j;
    for(i=0;i<n;i++)
        cin>>a[i];
    for(i=0;i<=k;i++)
        ans[i]=0;
    for(i=a[0];i<=k;i++)
    {
        for(j=0;j<n;j++)
        {
            if(i-a[j]>=0)
            {
                if(ans[i-a[j]]==0)
                {
                    ans[i]=1;
                    break;
                }
                if(j==n-1)
                    ans[i]=0;
            }
        }
    }
    if(ans[k]==0)
        cout<<"Second"<<endl;
    else
        cout<<"First"<<endl;
    return 0;
}


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

public class Main {
	public static void main(String[] args) {
		var sc = new Scanner(System.in);
		var n = sc.nextInt();
		var m = sc.nextInt();
		var x = sc.nextInt();
		var c = new int[n];
		var a = new int[n][m];
		for (var i = 0; i < n; i++) {
			c[i] = sc.nextInt();
			for (var j = 0; j < m; j++) {
				a[i][j] = sc.nextInt();
			}
		}
		sc.close();

		var min = Integer.MAX_VALUE;
		for (int i = 0; i < (int) Math.pow(2, n); i++) {
			var sum = 0;
			var asum = new int[m];
			for (int j = 0; j < n; j++) {
				if( ((i % (int) Math.pow(2, j + 1)) / ((int) Math.pow(2, j))) != 0) {
					sum += c[j];
					for (int k = 0; k < m; k++) {
						asum[k] += a[j][k];
					}
				}
			}
			if (Arrays.stream(asum).allMatch(aa -> aa >= x)) {
				min = Math.min(min, sum);
			}
		}
		System.out.println(min == Integer.MAX_VALUE ? -1 : min);
	}
}

Measured memory_bytes: 39808
import sys
import math
n = int(input())
ls = []
for i in range(n-1):
    c, s, f = [int(i) for i in sys.stdin.readline().split()]
    ls.append((c, s, f))
for start in range(n):
    _sum = 0
    for c, s, f in ls[start:]:
        _sum = max(math.ceil(_sum / f) * f, s)
        _sum += c
    print(_sum)

Measured memory_bytes: 42604
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define int long long
priority_queue<pair<int,int> >q;
int n,m,b[200100],a[200100],pre[200100],nxt[200100];
signed main(){
    int i,j,k,ans=0;
    scanf("%lld",&n);
    for(i=1;i<=n;i++)scanf("%lld",&a[i]);
    for(i=1;i<=n;i++){
      scanf("%lld",&b[i]);
      q.push(mp(b[i],i));
    }
    for(i=1;i<=n;i++){
      nxt[i]=i+1;
      pre[i]=i-1;
    }
    pre[1]=n;
    nxt[n]=1;
    while(!q.empty()){
      int x=q.top().se;
      q.pop();
      if(b[x]==a[x])continue;
      int y=pre[x],z=nxt[x];
      if(b[x]-b[y]-b[z]<a[x]){
          puts("-1");
          return 0;
      }
      k=b[x]-a[x];
      ans+=k/(b[y]+b[z]);
      b[x]=(k%(b[y]+b[z]))+a[x];
      if(a[x]!=b[x])q.push(mp(b[x],x));
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 10732
from collections import deque
h,w=map(int,input().split())
a=[list(input()) for _ in range(h)]
field=[[False for i in range(w)] for j in range(h)]
 
q=deque()
 
for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            q.append((i,j))
            field[i][j]=True
 
dx=[1,0,-1,0]            
dy=[0,1,0,-1]
ans=0
 
while q:
    nq=deque()
    while True:
        y,x=q.popleft()    
        for i in range(4):
            ny=y+dy[i]
            nx=x+dx[i]
            if 0<=ny<h and 0<=nx<w and field[ny][nx]==False:
                field[ny][nx]=True
                nq.append((ny,nx))

        if not q:
            ans+=1
            q=nq
            break
print(ans-1)

Measured memory_bytes: 122716
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		string s;
		cin >> s;
		sort(s.begin(), s.end());
		int m = stoi(s);
		reverse(s.begin(), s.end());
		int M = stoi(s);
		cout << M - m << endl;
	}
	return 0;
}


Measured memory_bytes: 3072
#include <stdio.h>
#include <math.h>
#include <queue>
#include <vector>
using namespace std;

int main()
{
	double a,b,c;
	int n,i;
	priority_queue< double, vector<double>, greater<double> > que;

	scanf("%d",&n);

	for(i = 0; i < n; i++){
		scanf("%lf %lf %lf",&a,&b,&c);
		que.push(a);
		que.push(b);
		que.push(c);
		a = que.top();
		que.pop();
		b = que.top();
		que.pop();
		if(pow( que.top(),2.0 ) == pow( a,2.0 ) + pow( b,2.0 )){
			printf("YES\n");
		}
		else{
			//printf("%lf %lf\n",pow( que.top(),2.0 ),pow( a,2.0 ) + pow( b,2.0 ));
			printf("NO\n");
		}
		que.pop();
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <map>
#include <algorithm>

constexpr int MAX_N=(int)1e5;

int n;

int a[MAX_N];

std::map<int,int> map;

int main() {

    std::cin>>n;

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

    for(int i=0;i<n;++i){
        for(int j=-1;j<=1;++j)
            ++map[a[i]+j];
    }

    int ans=0;

    for(auto p : map)
        ans=std::max(ans,p.second);

    std::cout<<ans<<std::endl;

    return 0;
}

Measured memory_bytes: 5120
#include<iostream>
using namespace std;
int main(){
string x ;
cin>>x;
if(x=="Sunny"){
    cout<<"Cloudy"<<endl;
}
else if(x=="Cloudy"){
    cout<<"Rainy"<<endl;
}
else if(x=="Rainy"){
    cout<<"Sunny"<<endl;
}

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    int bt=0,bx=0,by=0;
    int t,x,y;
    cin>>N;
    bool f=true;
    while(N--){
        cin>>t>>x>>y;
        int tt=t-bt;
        int r=abs(x-bx)+abs(y-by);
        if(r>tt||((r-tt)&1))f=false;
        bt=t;bx=x;by=y;
    }
    if(f)puts("Yes");
    else puts("No");
    return 0;
}




Measured memory_bytes: 256
"""
int(input())
map(int,input().split())
list(map(int,input().split()))

"""

n=int(input())
A=list(map(int,input().split()))
x=[]
for i in range(n-1):
    if(A[i]>=A[i+1]):
        x.append(1)
    else:
        x.append(0)
i=0
m=0
while(i<n-1):
    while(i<n-1 and x[i]==0):
        i+=1
    cur=0
    while(i<n-1 and x[i]==1):
        cur+=1
        i+=1
    if(cur>m):
        m=cur
print(m)
        

Measured memory_bytes: 14132
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	k := nextInt()

	// ball := make([]int, n)
	// for i := 0; i < n; i++ {
	// 	ball[i] = nextInt()
	// }

	m := map[int]int{}
	for i := 0; i < n; i++ {
		key := nextInt()
		if _, ok := m[key]; ok {
			m[key]++
		} else {
			m[key] = 1
		}
	}

	vslice := []int{}
	for _, v := range m {
		vslice = append(vslice, v)
	}
	sort.Sort(sort.IntSlice(vslice))

	// fmt.Println(m)
	// fmt.Println(vslice)

	count := 0
	for len(vslice) > k {
		count += vslice[0]
		vslice = vslice[1:]
	}

	fmt.Println(count)

}


Measured memory_bytes: 14464
l,r=map(int,input().split())
if r-l>=2018:print(0);exit()
r-=l//2019*2019
l%=2019
ans=2019
for i in range(l,r+1):
    for j in range(i+1,r+1):
        ans=min(ans,(i*j)%2019)
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
int main()
{
    char S[15],T[15],U[15];
    int A,B;
    scanf("%s",S);
    scanf("%s",T);
    scanf("%d%d",&A,&B);
    scanf("%s",U);
    if(strcmp(S,U)==0)
    {
        A-=1;
    }
    else if(strcmp(T,U)==0)
    {
        B-=1;
    }
    printf("%d %d\n",A,B);
    return 0;
}


Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;

int const N = 10010;
int ans[N];

bool isprime(int x){
    for (int i = 2; i*i <= x; i++){
        if (x%i == 0) return false;
    }
    return true;
}

int main(int argc, char ** argv) {
    int k = 0, i = 2;
    ans[0] = 0;
    while (k != N){
        while (!isprime(i)) i++;
        ans[k + 1] = ans[k] + i;
        i++;
        k++;
    }
    int n;
    while (scanf("%d",&n), n != 0){
        printf("%d\n", ans[n]);
    }
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define what_is(x) cerr << #x <<" is " << x << endl;
typedef long long ll;
const int MOD = 998244353;
const double PI = 3.14159265358979;
const int INF =  1e9 + 7;
const int nax = 100005;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tc = 1;
	// cin >> tc;
	while (tc--) {
		int n;
		cin >> n;
		n = n % 10;


		if (n == 3)
			cout << "bon";
		else if (n == 0 || n == 1 || n == 6 || n == 8)
			cout << "pon";
		else cout << "hon";




	}
	return 0;
}




















Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int L = S.size();
  long ans = 0;
  int ct = 0;
  for(int i = 0; i < L; ++i){
    if(S[i] == 'W'){
      ans += i - ct;
      ++ct;
    }
  }
  cout << ans << '\n';
  
}


Measured memory_bytes: 3748
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()
 
int main(){
    ll a, b;
    cin >> a >> b;
    cout << max((ll)0, a-(2*b));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
using ll = long long;
const ll MOD = 1000000007;

ll A[520][520];

int main() {
	for (int i = 0;i < 520;i++) {
		for (int j = 0;j < 520;j++) {
			A[i][j] = -1;
		}
	}
	set<ll> S;
	priority_queue<ll> T;
	bool w;
	for (int i = 5;;i++) {
		w = 1;
		if (i % 2 == 0)continue;
		if (i % 3 == 0)continue;
		for (int x : S) {
			if (i % x == 0) {
				w = 0;
				break;
			}
		}
		if (w) {
			S.insert(i);
			if (i > 550)T.push(i);
			if (T.size() == 1200)break;
		}
	}
	for (int i = 1;i < 520;i += 2) {
		ll a = i, b = 1, c = T.top();T.pop();
		while (a < 520 && b < 520) {
			A[a][b] = c * (a + b);
			a++;b++;
		}
	}
	for (int i = 3;i < 520;i += 2) {
		ll a = 1, b = i, c = T.top();T.pop();
		while (a < 520 && b < 520) {
			A[a][b] = c * (a + b);
			a++;b++;
		}
	}

	for (int i = 5;i < 513;i++) {
		for (int j = 5;j < 513;j++) {
			if (A[i][j] >= 0)continue;
			A[i][j] = A[i - 1][j] * A[i + 1][j] + 1LL;
		}
	}

	int N;
	cin >> N;
	for (int i = 0;i < N;i++) {
		for (int j = 0;j < N;j++) {
			cout << A[i + 8][j + 8];
			if (j == N - 1)cout << "\n";
			else cout << " ";
		}
	}
}

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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<double, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<ll> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}


bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//const ll mod = 1e10;
//typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;


int rec(int i, vector<vector<int>> &i_win) {
    if (i_win[i].empty()) return 0;
    vector<int> d;
    for (int to : i_win[i]) {
        int now = rec(to, i_win);
        d.push_back(now);
    }
    sort(d.begin(), d.end());
    rep(j, d.size()) {
        d[j] = d[j] + d.size() - j;
    }
    int ans = *max_element(d.begin(), d.end());
    return ans;
}

int main() {

    int n;
    cin >> n;

    vector<vector<int>> i_win(n);

    rep(i, n - 1) {
        int a;
        cin >> a;
        a--;
        i_win[a].push_back(i + 1);
    }

    int ans = rec(0, i_win);
    cout << ans << endl;
}

Measured memory_bytes: 17876
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include <random>
#include <list>
#include <numeric>



#define rep(i,p,q) for(ll i = p;i < q;i++)
#define ll long long

using namespace std;

vector<vector<ll>> graph;
vector<ll> query;
vector<ll> ans;
vector<ll> visited;

//139 D
int main(void) {
	ll n;
	cin >> n;
	cout << n * (n - 1) / (ll)2 << endl;
}


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

int main(){
	string s;
	cin  >> s;
	sort(s.begin(), s.end());
	if((s[0] == s[1]) && (s[2] == s[3]) && (s[0] != s[2])){
		cout << "Yes\n";
	}
	else{
		cout << "No\n";
	}
	return 0;
}

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

                            typedef long long ll;
                            typedef  double ld;
                            #define rep(i,a,n) for(ll i=(a); i<(n); i++)
                            #define per(i,a,n) for(ll i=(n-1); i>=(a); i--)
                            #define F first
                            #define S second
                            #define maxx(a,b) a=max(a,b)
                            #define minn(a,b) a=min(a,b)
                            #define db(x) cerr<<#x<<" = "<<x<<endl
                            #define N 1111111
                            #define mod 1000000007
                            #define rt return
                            #define inf 12345678908761

                            using namespace std;

                            ll a[3111][3111];

                            int main(){

                                ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

                                //freopen("Ulug'bek","r",stdin);
                                //freopen("Abdimanabov","w",stdout);

                                string q,w; cin>>q>>w;
                                q='1'+q;
                                w='2'+w;
                                int n=q.length();
                                int m=w.length();

                                rep(i,1,n)
                                rep(j,1,m)
                                {
                                    if(q[i]==w[j])maxx(a[i][j],a[i-1][j-1]+1);
                                    else
                                    a[i][j]=max(a[i-1][j],a[i][j-1]);
                                }

                                int x=n-1,y=m-1,ma=a[n-1][m-1];

                                string ans;


                                while(a[x][y]>0)
                                {
                                    if(x>0&&a[x-1][y]==a[x][y])x--;
                                    else
                                    if(y>0&&a[x][y-1]==a[x][y])y--;
                                    else
                                        ans+=q[x],x--,y--;
                                }

                                reverse(ans.begin(),ans.end());
                                cout<<ans;

                            rt 0;
                            }



















Measured memory_bytes: 73984
import java.util.Scanner;

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

    public static void solve(Scanner sc) {
        String s = sc.nextLine();
        int halfLength = s.length() / 2 - 1;
        while(true) {
            String prefix= s.substring(0, halfLength);
            if (s.startsWith(prefix, halfLength)) {
                System.out.println(halfLength * 2);
                return;
            }
            halfLength--;
        }
    }
}

Measured memory_bytes: 21844
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int T[100];
int main() {
	int N;
	cin >> N;
	int sum = 0;
	for (int i = 0; i < N; i++) {
		cin >> T[i];
		sum += T[i];
	}
	int M;
	cin >> M;
	for (int i = 0; i < M; i++) {
		int P, X;
		cin >> P >> X;
		P--;
		cout << sum - T[P] + X << endl;
	}
}

Measured memory_bytes: 256
main()
{
  int n,i,a[10],b[10],h,g,c,x;
  for(scanf("%d",&n);n--;)
    {
      for(a[0]=b[0]=h=g=i=x=0;i<10;i++)
	{
	  scanf("%d",&c);
	  if(x!=0)continue;
	  if(a[h]>=c && b[g]>=c)
	    x=-1;
	  else
	    {
	      if(a[h]<c && (a[h]>b[g] || b[g]>=c))
		a[++h]=c;
	      else
		b[++g]=c;
	    }
	}
      puts(x?"NO":"YES");
    }
}

Measured memory_bytes: 0
n=int(input())
s=[];t=[]
for i in range(n):
    s.append(input())
m=int(input())
for i in range(m):
    t.append(input())

ans=0
for i in range(n):
    strtmp=s[i]
    anstmp=s.count(strtmp)-t.count(strtmp)
    if ans<anstmp:
        ans=anstmp

print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#define _USE_MATH_DEFINES
#include<math.h>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<map>
#include<unordered_map>
#include<set>
#include <algorithm>
#include <utility>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::set;
using std::vector;
using std::pair;
using std::make_pair;
using std::priority_queue;

typedef unsigned long long ull;
typedef long long ll;

#define Prime1 1000000007
#define Prime2 9999973

#define INF 0x7fffffffffffffff

ull i, j, k, l, m, n;
ull H, W, Q;
ull a, b, c, x, y;
ull K, L, N, M;
string str;

int main()
{
	cin >> N;
	M = 0;
	vector<ull> num(100000, 0);
	for(i=0;i<N;++i)
	{
		cin >> a;
		num[a]++;
		M = std::max(M, num[a]);
		if (a > 0)
		{
			num[a - 1]++;
			M = std::max(M, num[a-1]);
		}
		if (a < 99999)
		{
			num[a + 1]++;
			M = std::max(M, num[a+1]);
		}
	}
	cout << M << '\n';
	return 0;
}


Measured memory_bytes: 1024
def check(b0, b1):
    is_sheep[0] = b0
    is_sheep[1] = b1
    
    for i in range(1, N):
        if s[i]=='o':
            if is_sheep[i]:
                is_sheep[(i+1)%N] = is_sheep[i-1]
            else:
                is_sheep[(i+1)%N] = not is_sheep[i-1]
        else:
            if is_sheep[i]:
                is_sheep[(i+1)%N] = not is_sheep[i-1]
            else:
                is_sheep[(i+1)%N] = is_sheep[i-1]
    
    if b0==is_sheep[0]:
        if s[0]=='o':
            if b0:
                return is_sheep[N-1]==is_sheep[1]
            else:
                return is_sheep[N-1]!=is_sheep[1]
        else:
            if b0:
                return is_sheep[N-1]!=is_sheep[1]
            else:
                return is_sheep[N-1]==is_sheep[1]
    else:
        return False

N = int(input())
s = input()
is_sheep = [False]*N

for b0, b1 in [(False, False), (False, True), (True, False), (True, True)]:
    if check(b0, b1):
        ans = ['S' if is_sheep[i] else 'W' for i in range(N)]
        print(''.join(ans))
        break
else:
    print(-1)

Measured memory_bytes: 49648
#include <stdio.h>
int main (){
  int N=0,i=0;
  scanf("%d",&N);
  for(i=0;N>=1000;i++){
    N=N-1000;
  }
  N=1000-N;
  if(N==1000){
    N=0;
  }
  printf("%d",N);
}

Measured memory_bytes: 1736
#include<iostream>
#include<algorithm>
using namespace std;
#define N 100010
#define inf 0x3f3f3f3f
int n,k;
int h[N];
int main()
{
    ios::sync_with_stdio(false);
    while(cin>>n>>k)
    {
        for(int i=0;i<n;i++) cin>>h[i];
        sort(h,h+n);
        int ans=inf;
        for(int i=0;i<=n-k;i++)
        {
            ans=min(ans,h[i+k-1]-h[i]);
            //cout<<"cur ans:"<<ans<<endl;
        }
        cout<<ans<<endl;
    }
}

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

using namespace std;

int main() {
	int n; cin >> n;
	vector<int> a(n);
	for(auto&e:a) cin >> e;
	int ma=1;
	for(int i=1;i<n;++i)
		if(a[i-1]>=a[i]) ++ma;
	cout << ma << endl;
	cout << n << endl;
	
	return 0;
}



Measured memory_bytes: 3152
def c_sqrt_inequality():
    A, B, C = [int(i) for i in input().split()]
    # sqrt(a) + sqrt(b) < sqrt(c) を a, b, c が正整数の元で同値変形すると、
    # c-a-b > 0 and 4*a*b < (c-a-b)**2 を得る。
    s, t = C - A - B, 4 * A * B
    return ('No', 'Yes')[int(s > 0 and t < s**2)]

print(c_sqrt_inequality())

Measured memory_bytes: 2940
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class A
{
	public static void Main()
	{
		int N = GetInt();
		int[] a = new int[N];
		var num = new Dictionary<int, int>();
		for(int i = 0; i < N; i++)
		{
			a[i] = GetInt();
			int tmp = 0;
			num.TryGetValue(a[i], out tmp);
			num[a[i]] = tmp + 1;
		}

		int count = num.Keys.Count;
		if(N % 3 == 0)
		{
			switch(count)
			{
				case 1:
					Console.WriteLine((a[0] == 0) ? "Yes" : "No");
					return;

				case 2:
					int tmp = 0;
					if(num.TryGetValue(0, out tmp) && (tmp == N/3))
						Console.WriteLine("Yes");
					else
						Console.WriteLine("No");
					return;

				case 3:
					foreach(int val in num.Values)
					{
						if(val != N/3)
						{
							Console.WriteLine("No");
							return;
						}
					}

					int xor = 0;
					foreach(int key in num.Keys)
						xor ^= key;
				
					Console.WriteLine((xor == 0) ? "Yes" : "No");
					return;

				default:
					Console.WriteLine("No");
					return;
			}
		}
		else
		{
			if((count == 1) && (a[0] == 0))
				Console.WriteLine("Yes");
			else
				Console.WriteLine("No");
		}
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}

Measured memory_bytes: 25184
#include <iostream>
#include <vector>
#include <string>
#include <utility>
using namespace std;

int main() {
	string S;
	cin >> S;
	vector<int> p{0, 0}, ans(S.size(), 0);
	S += 'R';
	int now=0;
	for(int i=0; i<S.size(); ++i){
	    if(now==0 ^ S[i]=='R'){
	        now=1-now;
	        if(S[i]=='L') ++p[1];
	        else{
	            int r_side=(p[0]+1)/2 + p[1]/2;
	            ans[i-p[1]-1]=r_side;
	            ans[i-p[1]]=p[0]+p[1]-r_side;
	            p[0]=1;
	            p[1]=0;
	        }
	    }
	    else ++p[now];
	}
	cout << ans[0];
	for(int i=1; i<ans.size(); ++i) cout << ' ' << ans[i];
	cout << endl;
	return 0;
}


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

int main(){
    int N;
    cin >> N;
    int trains[N - 1][3];
    for(int i = 0; i < N - 1; i++){
        for(int j = 0; j < 3; j++){
            cin >> trains[i][j];
        }
    }
    for(int i = 0; i < N; i++){
        int time = 0;
        for(int j = i; j < N - 1; j++){
            time = max(time, trains[j][1]);
            time += (trains[j][2] * 1000000 - time) % trains[j][2];
            time += trains[j][0];
        }
        cout << time << endl;
    }
}

Measured memory_bytes: 256
N = gets.to_i
fs = []
N.times do |i|
    fs[i] = gets.gsub(' ', '').to_i(2)
end

ps = []
N.times do |i|
    ps[i] = gets.split.map(&:to_i)
end

ans = -Float::INFINITY
(1..1023).each do |bits|
    sum = 0
    N.times do |i|
        nb = (fs[i] & bits).to_s(2).count('1')
        sum += ps[i][nb]
    end
    ans = sum if ans < sum
end

puts ans

Measured memory_bytes: 1788
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
 
using namespace std;
 
#define pai 3.14159265359
#define mod 1000000007

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

Measured memory_bytes: 256
#include <cstdio>

int main(void)
{
    while (1) {
        int h, w;
        scanf("%d %d", &h, &w);
        if (!h && !w)
            break;

        for (int y=1; y<=h; y++) {
            for (int x=1; x<=w; x++) {
                if (y%2) {
                    if (x%2)
                        printf("#");
                    else
                        printf(".");
                } else {
                    if (!(x%2))
                        printf("#");
                    else
                        printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 2688
n,q = map(int,input().split())
s = input()
count = [0] * (n+1)
for i in range(n-1):
    if s[i] == 'A' and s[i+1] == 'C':
        count[i+1] = count[i] + 1
    else:
        count[i+1] = count[i]
for i in range(q):
    l,r = map(int,input().split())
    print(count[r-1] - count[l-1])

Measured memory_bytes: 11424
class PrimeFactor():

    def __init__(self, n):
        """
        エラトステネス　O(N loglog N)
        """
        self.n = n
        self.table = list(range(n+1))       # 最小素因数のリスト
        self.table[2::2] = [2]*(n//2)
        for p in range(3, int(n**0.5) + 2, 2):
            if self.table[p] == p:
                for q in range(p * p, n + 1, 2 * p):
                    if self.table[q] == q:
                        self.table[q] = p

    def is_prime(self, x):
        """ 素数判定　O(1) """
        if x < 2:
            return False
        return self.table[x] == x

    def prime_factors(self, x):
        """ 素因数分解 O(logN)  (試し割りだとO(sqrt(N))) """
        res = []
        if x < 2:
            return res
        while self.table[x] != 1:
            res.append(self.table[x])
            x //= self.table[x]
        return res

    def prime_counter(self, x):
        """
        素因数分解（個数のリスト） O(logN)
        {素因数: 個数}　の形で返す
        """
        res = dict()
        if x < 2:
            return res
        while self.table[x] != 1:
            res[self.table[x]] = res.get(self.table[x], 0) + 1
            x //= self.table[x]
        return res

    def divisors_counter(self, x):
        """ 約数の個数　O((logN)^2) """
        res = 1
        for value in self.prime_counter(x).values():
            res *= (value+1)
        return res

    def prime_gcd(self, X, mod=None):
        """ n個の最大公約数　X:n個のリスト  (O((logN)^2)) """
        exponents = self.prime_counter(X[0])
        for x in X[1:]:
            Y = self.prime_counter(x)
            for prime, exp in exponents.items():
                if Y[prime] < exp:
                    exponents[prime] = Y[prime]
        res = 1
        for prime, exp in exponents.items():
            res *= pow(prime, exp, mod)
        if mod == None:
            return res
        else:
            return res % mod

    def prime_lcm(self, X, mod=None):
        """ n個の最小公倍数　X:n個のリスト  (O((logN)^2)) """
        exponents = dict()
        for x in X:
            for prime, exp in self.prime_counter(x).items():
                if exp > exponents.get(prime, 0):
                    exponents[prime] = exp
        res = 1
        for prime, exp in exponents.items():
            res *= pow(prime, exp, mod)
        if mod == None:
            return res
        else:
            return res % mod

N = int(input())
P = PrimeFactor(N)
res = 0
for k in range(1,N):
    res += P.divisors_counter(k)
print(res)

Measured memory_bytes: 79716
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    string S;
    
    cin >> S;
    
    if(S == "Sunny"){
        
        cout<<"Cloudy"<<endl;
    }
    
    else if(S == "Cloudy"){
        
        cout<<"Rainy"<<endl;
    }
    
    else{
        cout<<"Sunny"<<endl;
    }
}

Measured memory_bytes: 3540
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

n = int(input())
i = 0
while 26 ** i < n:
    i += 1
    if 26**i > n:
        i -= 1
        break
start = ["a"]*i
#n -= 26**i
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)
m = num2alpha(n)

ans = []
print(m.lower())





Measured memory_bytes: 61888
// #include<iostream>
// #include<cctype>
// using namespace std;

#include<cstdio>
#include<cstring>

int main(){
  char x[1001];
  
  while(1){
    int c=0;
    scanf("%s", x);
    if (strcmp(x,"0")==0) break;
    int i=0;
    while(x[i]!='\0'){
      c+=x[i]-'0';
      i++;
    }
    printf("%d\n", c);
  }

  return 0;
}

Measured memory_bytes: 2680
use std::collections::HashMap;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    // switch num
    let switch_num: i32 = read();
    // bulb num
    let bulb_num: i32 = read();
    let mut map = HashMap::new();
    // bi: bulb index
    for bi in 1..bulb_num + 1 {
        let k: i32 = read();
        for _ in 1..k + 1 {
            // si: switch index
            let si: i32 = read();
            let entry = map.entry(si).or_insert(vec![]);
            entry.push(bi)
        }
    }
    let mut vec = vec![true];
    for _ in 1..bulb_num + 1 {
        vec.push(read::<i32>() == 0);
    }
    println!("{}", dfs(1, switch_num, &map, vec, 0));
}

fn dfs(
    depth: i32,
    last: i32,
    map: &HashMap<i32, Vec<i32>>,
    switch_state: Vec<bool>,
    ans: i32,
) -> i32 {
    if depth == last + 1 {
        if switch_state.iter().all(|&x| x == true) {
            return ans + 1;
        }
        return ans;
    }
    let mut switch_state_flip = switch_state.clone();
    match map.get(&depth) {
        Some(vec) => {
            for &i in vec {
                switch_state_flip[i as usize] ^= true;
            }
        }
        None => {}
    };
    let ans1 = dfs(depth + 1, last, &map, switch_state_flip, ans);
    let ans2 = dfs(depth + 1, last, &map, switch_state, ans);
    ans1 + ans2
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

template<typename T>
static inline void chmin(T & ref, const T  value) {
    if (ref > value) ref = value;
}

template<typename T>
static inline void chmax(T & ref, const T value) {
    if (ref < value) ref = value;
}

const ll mod = 1000000007;


int main() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0) return 0;
		vector<vector<int>> grid(n, vector<int>(5, 0));
		rep(i, n) {
			rep(j, 5) {
				cin >> grid[i][j];
			}			
		}
		bool updated = true;
		ll score = 0;
		while (updated) {
			updated = false;
			vector<vector<bool>> temp(n, vector<bool>(5, false));
			rep(i, n) {
				rep(j, 3) {
					int color = grid[i][j];
					if (color == -1) continue;
					bool match = true;
					for (int k = 1; k < 3 && j + k < 5; k++) {
						if (grid[i][j + k] != color) {
							match = false;
							break;
						}
					}
					if (match) {
						updated = true;
						rep(k, 3) {
							temp[i][j + k] = true;
						}
					}
				}
			}
			rep(i, n) rep(j, 5) {
				if (temp[i][j]) {
					score += grid[i][j];
				}
			}
			vector<vector<int>> nextGrid(n, vector<int>(5, -1));
			rep(j, 5) {
				int target = n - 1;
				for (int i = n - 1; i >= 0; i--) {
					while(target >= 0 && temp[target][j]) {
						target--;
					}
					if (target < 0) break;
					nextGrid[i][j] = grid[target][j];
					target--;
				}
			}
			swap(grid, nextGrid);
		}
		cout << score << endl;
	}
	return 0;
}




Measured memory_bytes: 3004
#ifdef _DEBUG
#define _CRT_SECURE_NO_WARNINGS
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define MGN 8
#define LINF (LONG_MAX/2)
using namespace std;
typedef long long ll; typedef unsigned long long ull;
typedef vector<int> vi; typedef vector<vi> vvi; 
typedef vector<ll> vl; typedef vector<vl> vvl;
typedef vector<double> vd; typedef vector<string> vs;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
typedef vector<bool> vb; typedef vector<vb> vvb;
template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
    return left.second > right.second;}
vs split(string str, char sep) {
    vs v; stringstream ss(str); string t;
    while (getline(ss, t, sep)) v.push_back(t);
    return v;}
vs re_search_g(string s, regex re) {
    vs ret; smatch mc; auto it = s.cbegin();
    while (regex_search(it, s.cend(), mc, re)) {
        ret.push_back(mc[0]);
        it += mc.position(0) + mc.length();}
    return ret;}
#endif

void init_global_B() {}


int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int A, B, C, D, E; cin >> A >> B >> C >> D >> E;
    map<char, int> mp;
    mp['A'] = A;
    mp['B'] = B;
    mp['C'] = C;
    mp['D'] = D;
    mp['E'] = E;
    int N = mp.size();

    int ans INF;
    vector<char> p{ 'A','B','C','D','E' };
    sort(p.begin(), p.end());
    do {
        int tm = 0;
        FOR(i,0,N){
            if (tm % 10 != 0) tm += 10 - (tm % 10);
            tm += mp[p[i]];
        }
        ans = min(ans, tm);
    } while (next_permutation(p.begin(), p.end()));

    cout << ans << endl;  

    return 0;
}

Measured memory_bytes: 256
# 第2回全国統一プログラミング王決定戦予選-A
if False:
    N=int(input())
    if N%2==0: print(N//2-1)
    else: print(N//2)

# 第1回同じ-A
if False:
    M,D=map(int,input().split())
    ans=0
    for m in range(1,M+1):
        for d in range(1,D+1):
            if len(str(d))==2:
                x,y=int(str(d)[0]),int(str(d)[1])
                if x>=2 and y>=2 and x*y==m:
                    ans+=1
    print(ans)

#d2019PC2 - A
if False:
    N,K=map(int,input().split())
    MAX=N-K+1
    print(MAX-1 if K!=1 else 0)

#https://atcoder.jp/contests/nikkei2019-qual/tasks/nikkei2019_qual_a
if False:
    N,A,B=map(int,input().split())
    MAX=min(A,B)
    MIN=A+B-N if A+B>=N else 0
    print(MAX,MIN)

# https://atcoder.jp/contests/yahoo-procon2019-qual/tasks/yahoo_procon2019_qual_b
if True:
    cnt=[0 for _ in range(4)]
    for _ in range(3):
        a,b=map(int,input().split())
        cnt[a-1]+=1
        cnt[b-1]+=1
    cnt.sort()
    print('YES' if cnt==[1,1,2,2] else 'NO')
            
        

        



Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int dp[3001][3001];
//return longest common subsequence of string
string lcs(string &s,string &t,int len)
{
	int i,j;
	i=j=0;
	string ans;
	while(len>0)
	{
		if(s[i]==t[j])
		{
			ans+=s[i];
			i++;
			j++;
			len--;
		}
		else
		{
			if(dp[i][j+1]>dp[i+1][j])
			{
				j++;
			}
			else
			i++;
		}
	}
	return ans;
}
// return longest length of common string
int get_len(string &s,string &t,int i,int j)
{
	if(i>=s.length() || j>=t.length())
		return 0;
	
	if(dp[i][j]!=-1)
		return dp[i][j];
	
	if(s[i]==t[j])
	{
		return dp[i][j]=1+get_len(s,t,i+1,j+1);
	}
	else
	{
		return dp[i][j]=max(get_len(s,t,i,j+1),get_len(s,t,i+1,j));
	}
}
string solve(string s,string t)
{
	memset(dp,-1,sizeof(dp));
	int len=get_len(s,t,0,0);
	return lcs(s,t,len);
}
int main()
{
	string a,b;
	cin>>a>>b;
	cout<<solve(a,b);
}

Measured memory_bytes: 39276
n = int(input())
la, lxy = [], []
for i in range(n):
  a = int(input())
  la.append(a)
  xy = []
  for j in range(a):
    xy.append(list(map(int, input().split())))
  lxy.append(xy)

lb = []
for i in range(2**n):
  lb += [str(bin(i))[2:].zfill(n)]
lc = [sum(int(j) for j in i) for i in lb]
lc, lb = zip(*sorted(zip(lc, lb), reverse=True))
lb = [[int(j) for j in i] for i in lb]

for l in lb:
  ok = 1
  for i in range(n):
    a = la[i]
    for j in range(a):
      x, y = lxy[i][j]
      if l[i] == 1 and l[x-1] != y:
        ok = 0
        break
  if ok:
    print(sum(int(k) for k in l))
    break
else:
  print(0)

Measured memory_bytes: 12792
#include<iostream>
using namespace std;
int main() {
  int a, b, c, d, i;
  int A[114514] = {};
  cin >> a >> b;
  for(i=0;i<b;i++) {
    cin >> c >> d;
    A[c] += 1;
    A[d] += 1;
  }
  for(i=1;i<=a;i++) {
    cout << A[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <iostream>
#include <math.h>
#include <map>
#include <set>
using namespace std;
int main ()
{
	int n;
	scanf("%i",&n);
	int a[n+1];
	for(int i=1;i<=n;i++)
	{
		scanf("%i",&a[i]);
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)
	{
		if(i<n && a[i]==a[i+1])
		{
			printf("NO");
			return 0;
		}
	}
	printf("YES");
	return 0;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    String B = sc.next();
     if(B.equals("A")){
       System.out.println("T");
    }else if(B.equals("T")){
    System.out.println("A");
     }else if(B.equals("C")){
    System.out.println("G");
  }else if(B.equals("G")){
    System.out.println("C");
  }
  }
}

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

int main(){
	int A, B;
	scanf("%d%d", &A, &B);
	for(int i = 0; ; i++){
		if(1 + i * (A - 1) >= B){
			printf("%d\n", i);
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
 
#define  rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i>=0; i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  int ans = 0;
  for(int i=0; std::pow(2,i)<=N; i++) ans = std::pow(2,i);
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int n;
  cin >> n;
  
  if(n%2 == 0){
    cout << 0.5 << endl;
  }
  else{
    double a = 0;
    a += n;
    a = (a - (a-1)/2)/a;
    cout << a << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define INF 1e12
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n; cin>>n;
	set<string> st;
	string last,now;
	cin>>last; st.insert(last);
	For(i,2,n)
	{
		cin>>now;
		if(st.count(now) || now.front()!=last.back())
		{
			cout<<"No\n";
			return 0;
		}
		st.insert(now);
		last=now;
	}
	cout<<"Yes\n";
	return 0;
}

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

long long N=100000;
int K=100;
vector <long long> h(N);
vector <long long> c(N, 1e13);

int main() {
    cin >> N >> K;
    for (long long i=0; i<N; i++) cin >> h.at(i);
    c.at(0) = 0;
    for (int i=1; i<N; i++) {
        for (int j=max(i-K, 0); j<i; j++) {
            c.at(i) = min(c.at(i), c.at(j)+abs(h.at(i)-h.at(j)));
        }
    }
    cout << c.at(N-1) << endl;
}

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

int n,k,sz;
int dat[1100000];

void upd(int pos,int val){
    pos+=sz-1;
    dat[pos]=val;
    while(pos>1){
        pos>>=1;
        dat[pos]=max(dat[pos<<1],dat[pos<<1|1]);
    }
}

int qry(int id,int l,int r,int ql,int qr){
    if(qr<l||r<ql)return 0;
    if(ql<=l&&r<=qr)return dat[id];
    return max(qry(id<<1,l,(l+r)>>1,ql,qr),qry(id<<1|1,((l+r)>>1)+1,r,ql,qr));
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>k;
    sz=1;
    while(sz<300001)sz<<=1;
    for(int i=1;i<=n;i++){
        int a;
        cin>>a;
        a++;
        upd(a,qry(1,1,sz,a-k,a+k)+1);
    }
    cout<<qry(1,1,sz,1,300001)<<endl;

    return 0;
}

Measured memory_bytes: 6064
#include<bits/stdc++.h>
#define FOR(i,a,b) for (register int i=(a);i<=(b);i++)
#define For(i,a,b) for (register int i=(a);i>=(b);i--)
#define mem(i,j) memset(i,j,sizeof(i))
#define GO(u) for (register int j=f[u];j!=-1;j=nxt[j])
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define MP make_pair
using namespace std;
typedef long long ll;
const int N=555;
int n,G[N][N],col[N],vis[N],dep[N],ans=0;
char s[N][N];
queue <int> q;
inline int read()
{
	int x=0,f=1;
	char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') {x=(x<<1)+(x<<3)+c-'0';c=getchar();}
	return f*x;
}
inline void write(int x)
{
	if (x<0) putchar('-'),x=-x;
	if (x>9) write(x/10);
	putchar(x%10+'0');
	return;
}
inline void no()
{
	printf("-1\n");
	exit(0);
}
inline void dfs(int u,int c)
{
	col[u]=c;
	FOR(v,1,n) if (G[u][v])
	{
		if (!col[v]) dfs(v,c^1);
		else if (col[u]==col[v]) no();
	}
	return;
}
inline void bfs(int shit)
{
	FOR(i,1,n) vis[i]=0,dep[i]=0;
	dep[shit]=1;
	while (q.size()) q.pop();
	q.push(shit);
	vis[shit]=1;
	while (q.size())
	{
		int tmp=q.front();
		q.pop();
		FOR(i,1,n) if (G[tmp][i]) if (!vis[i])
		{
			vis[i]=1;
			dep[i]=dep[tmp]+1;
			q.push(i);
		}
	}
	FOR(i,1,n) ans=max(ans,dep[i]);
	return;
}
int main()
{
	n=read();
	FOR(i,1,n) scanf("%s",s[i]+1);
	FOR(i,1,n) FOR(j,1,n) G[i][j]=(s[i][j]=='1');
	dfs(1,1);
	FOR(i,1,n) bfs(i);
	write(ans);
	return 0;
}

Measured memory_bytes: 896
#include "bits/stdc++.h"
using namespace std;

typedef pair<int, int>P;
char mp[500][500];
vector<P>pos[26];
int flg[26];
int ue[26][2];

int main(){
    int H, W;
    cin >> H >> W;
    for(int y = 0; y < H; y++){
        for(int x = 0; x < W; x++){
            cin >> mp[y][x];
            if(mp[y][x] != '.'){
                flg[mp[y][x] - 'A'] = 1;
                pos[mp[y][x] - 'A'].push_back(P(x, y));
            }
        }
    }
    for(int i = 0; i < 26; i++){
        if(flg[i] == 0)continue;
        if(abs(pos[i][0].first - pos[i][1].first) + abs(pos[i][0].second - pos[i][1].second) == 1){
            flg[i] = 0;
            continue;
        }
        int x2 = pos[i][1].first;
        int y2 = pos[i][1].second;
        int x = pos[i][0].first;
        int y = pos[i][0].second;
        while(x != x2){
            if(x < x2)x++;
            else if(x > x2)x--;
            if(mp[y][x] != '.' && mp[y][x] != 'A' + i){
                ue[i][0] |= (1 << (mp[y][x] - 'A'));
            }
        }
        while(y != y2){
            if(y < y2)y++;
            else if(y > y2)y--;
            if(mp[y][x] != '.' && mp[y][x] != 'A' + i){
                ue[i][0] |= (1 << (mp[y][x] - 'A'));
            }
        }
        x = pos[i][0].first;
        y = pos[i][0].second;
        while(y != y2){
            if(y < y2)y++;
            else if(y > y2)y--;
            if(mp[y][x] != '.' && mp[y][x] != 'A' + i){
                ue[i][1] |= (1 << (mp[y][x] - 'A'));
            }
        }
        while(x != x2){
            if(x < x2)x++;
            else if(x > x2)x--;
            if(mp[y][x] != '.' && mp[y][x] != 'A' + i){
                ue[i][1] |= (1 << (mp[y][x] - 'A'));
            }
        }
    }
    int ans = 0;
    int state = 0;
    for(int f = 1; f;){
        f = 0;
        for(int i = 0; i < 26; i++){
            for(int j = 0; j < 2; j++){
                if(flg[i] == 0)continue;
                if(state & (1 << i))continue;
                if((state & (ue[i][j])) == ue[i][j]){
                    ans+=2;
                    state |= (1 << i);
                    f = 1;
                }
            }
        }    
    }


    cout << ans << endl;

    
    return 0;    
}


Measured memory_bytes: 3340
N,K = map(int,input().split())

Ans = [0]*(N+2)
Sum_Ans = 0

def solution(N,K,Ans,Sum_Ans):
    for i in range(K,N+2):
        #max[i] = (2*N - i + 1)*i / 2
        #min[i] = i*(i - 1) / 2
        Ans[i] = i*(N - i + 1) + 1
        
        Sum_Ans += Ans[i]
    
    print(Sum_Ans%(10**9 + 7))

solution(N,K,Ans,Sum_Ans)

Measured memory_bytes: 19716
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
using namespace std;

int main(void)
{
	int i;
	int change;
	vector<char>n(3);
	vector<char>o(3);

	for (i = 0; i < 3; i++)
	{
		cin >> n[i];
	}
	for (i = 0; i < 3; i++)
	{
		change = n[i];
		o[2 - i] = change;
	}
	if (n == o)
	{
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
	return 0;

}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)

inline int read()
{
	int data = 0, w = 1; char ch = getchar();
	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
	if (ch == '-') w = -1, ch = getchar();
	while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();
	return data * w;
}

const int N(305);
int n, K, M, C[N][N], f[N][N], s[N][N];

int main()
{
	n = read(), K = read(), M = read();
	for (int i = 0; i <= n; i++) C[i][0] = 1;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= i; j++) C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % M;
	for (int i = K; ~i; i--) f[1][i] = 1, s[1][i] = (f[1][i] + s[1][i + 1]) % M;
	for (int i = 2; i <= n + 1; i++)
	{
		for (int j = K; ~j; j--)
		{
			for (int k = 1; k < i; k++)
				f[i][j] = (f[i][j] + 1ll * f[i - k][j] * C[i - 2][k - 1] % M * s[k][j + 1]) % M;
			s[i][j] = (f[i][j] + s[i][j + 1]) % M;
		}
	}
	printf("%d\n", f[n + 1][0]);
	return 0;
}


Measured memory_bytes: 1280
#include <stdio.h>

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  const int ml[ ][ 12 ]
    = { { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }
      , { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 } };

  for ( ; ; )
  {
    int y1, m1, d1, y2, m2, d2;
    int a1, a2;

    scanf ( "%d%d%d%d%d%d", &y1, &m1, &d1, &y2, &m2, &d2 );
    if ( y1 < 0 || m1 < 0 || d1 < 0
      || y2 < 0 || m2 < 0 || d2 < 0 ) break ;

    a1 = y1 * 365
       + ml[ !!( !( y1 % 4 ) && ( ( y1 % 100 ) || !( y1 % 400 ) ) ) ][ m1 - 1 ]
       + d1 + ( ( y1 - 1 ) / 4 ) - ( ( y1 - 1 ) / 100 ) + ( ( y1 - 1 ) / 400 );
    a2 = y2 * 365
       + ml[ !!( !( y2 % 4 ) && ( ( y2 % 100 ) || !( y2 % 400 ) ) ) ][ m2 - 1 ]
       + d2 + ( ( y2 - 1 ) / 4 ) - ( ( y2 - 1 ) / 100 ) + ( ( y2 - 1 ) / 400 );

    printf ( "%d\n", a2 - a1 );
  }

  return ( 0 );
}

Measured memory_bytes: 0