akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define INF 1e17
#define int long long

#define deb(...) cerr << "[" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__) 
void DBG() {
  cerr << "]\n";
}
template<typename T, typename ...Args> void DBG(T first, Args... args) {
  cerr << first; if (sizeof...(args))cerr<<", "; DBG(args...);
}

/////////////////////////// GLOBAL ///////////////////////////

/////////////////////////// GLOBAL ///////////////////////////

void solve() {
  int h, w, m;
  cin>>h>>w>>m;
  int a, b;
  int row[h+1],col[w+1];
  memset(row,0,sizeof(row));
  memset(col,0,sizeof(col));
  vector<pair<int,int>> mr;
  vector<pair<int,int>> mc;
  map<pair<int, int>, int> mx;
  for(int i=0;i<m;i++){
    cin>>a>>b;
    row[a]++;
    col[b]++;
    mx[{a,b}]++;
  }
  for(int i=1;i<=h;i++){
    mr.push_back({row[i],i});
  }
  for(int i=1;i<=w;i++){
    mc.push_back({col[i],i});
  }
  int ans=0;
  sort(mr.rbegin(),mr.rend());
  sort(mc.rbegin(),mc.rend());
  for(int i=1;i<=w;i++){
    int cnt=mr[0].first+mc[i-1].first;
    if(mx.count({mr[0].second,mc[i-1].second}))--cnt;
    ans = max(ans,cnt);
  }
  for(int i=1;i<=h;i++){
    int cnt=mr[i-1].first+mc[0].first;
    if(mx.count({mr[i-1].second,mc[0].second}))--cnt;
    ans = max(ans,cnt);
  }

  cout<<ans<<"\n";

 


  
}


int32_t main() {
  #ifndef ONLINE_JUDGE
  clock_t tStart = clock();
  freopen("in.txt", "r", stdin);
  //freopen("output.txt","w",stdout);
  #endif 
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t=1;
  // cin >> t;
  for (int tt=1;tt<=t;tt++) {
    //cout << "Case #"<<tt<<": ";
    solve();
  }
  #ifndef ONLINE_JUDGE
    cerr << "\nRun Time -> "<<(double)(clock()-tStart)/CLOCKS_PER_SEC <<" sec\n";
  #endif
}


Measured memory_bytes: 43700
#include <bits/stdc++.h>
using namespace std;
int a[9];
int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    int temp;
    for(int i=0;i<n;++i)
    {
        cin>>temp;
        if(temp>=3200)
        {
            a[8]++;
        }
        else
        {
            a[temp/400]++;
        }
    }
    int cnt=0;
    for(int i=0;i<8;i++)
    {
        if(a[i]>0)
        {
            ++cnt;
        }
    }
    if(cnt==0)
    {
        cout <<1<<" "<<a[8]<<endl;
        return 0;
    }
    int maximum=(cnt+a[8]);
    int minimum=cnt;
    cout <<minimum<<" "<<maximum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
long long n,m,i,j,dp[25][2];
vector<long long> dig;
long long dfs(long long x,bool lim)
{
	if (x==-1) return 0;
	if (!lim&&dp[x][lim]!=-1) return dp[x][lim];
	dp[x][lim]=0;
	long long i,t=lim?dig[x]:9;
	for (i=0;i<=t;i++)
	{
		dp[x][lim]=max(dp[x][lim],i+dfs(x-1,lim&&i==t));
	}
	return dp[x][lim];
}
int main()
{
	cin>>n;
	while (n)
	{
		dig.push_back(n%10);
		n/=10;
	}
	memset(dp,-1,sizeof(dp));
	cout<<dfs(dig.size()-1,1);
	return 0;
}

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

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc= new Scanner(System.in);
		long a= sc.nextInt();
		long b= sc.nextInt();
		long c= sc.nextInt();
		long d= sc.nextInt();
		
		sc.close();
		
		long ans= a*c;
		
		if(a*d > ans)ans= a*d;
		
		if(b*c > ans)ans= b*c;
		if(b*d > ans)ans= b*d;
		
		System.out.println(ans);
		
		
	}

}


Measured memory_bytes: 35724
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n;
  double pp,tp;
  double pcal,tcal[1000];
  cin >> n;
  cin >> pp >> tp;
  cin >> pcal;
  for(int i = 0 ; i < n ; i++ ){
    cin >> tcal[i];
  }

  sort(tcal,tcal + n , greater<int>());

  double mx = pcal/pp;
  double sumcal = pcal;
  for(int i = 0 ; i < n ; i++){
    if(mx < sumcal/(pp + tp*i) ) mx = sumcal/(pp + tp*i);
    sumcal += tcal[i];
  }

  cout << (int)mx << endl;
  return 0;
}

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> s(h+2,vector<char>(w+2, '.'));
  rep(i,h)rep(j,w) cin >> s.at(i+1).at(j+1);
  bool ok = true;
  auto check = [&](int a, int b) {
    if(s[a-1][b]=='#') return true;
    else if(s[a+1][b]=='#') return true;
    else if(s[a][b-1]=='#') return true;
    else if(s[a][b+1]=='#') return true;
    else return false;
  };
  rep(i,h)rep(j,w) {
    if(s[i+1][j+1]=='#') if(!check(i+1,j+1)) ok = false;
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;

int num[10][10];

signed main() {
    int N;
    cin >> N;
    for (int i = 1; i <= N; ++i) {
        int bottom = i % 10;
        int top = bottom;
        int tmp = i;
        while (tmp / 10) {
            tmp /= 10;
            top = tmp;
        }
        num[top][bottom]++;
    }
    int ans = 0;
    rep(i, 10) {
        rep(j, 10) {
            ans += num[i][j] * num[j][i];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N ;
  vector<string> S(N);
  
  vector<string> L(N,"");//ソート後
  vector<int>count(N,0);
  
  for(int i=0; i<N; i++){
  	cin >> S.at(i);
  }
  sort(S.begin(),S.end());
  string zen=S.at(0);
  int c=1,kind=0,cm=0;
  //cout << S.at(0) << endl;
  for(int i=1; i<N; i++){
    //cout << S.at(i) << endl;
  	if(zen==S.at(i))c++;
    cm=max(c,cm);
    if(zen!=S.at(i)){
      L.at(kind)=zen;
      count.at(kind)=c;
      //cout << i <<" "<< c << endl;
      kind++;c=1;
    }
    zen=S.at(i);
  }
  L.at(kind)=zen;
  count.at(kind)=c;
  for(int i=0; i<N; i++){
    //cout << L.at(i) <<" "<< count.at(i) << endl;
  	if(count.at(i)==cm)cout << L.at(i) <<endl;
  }
}

Measured memory_bytes: 16640
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pii pair <int, int>
#define F first
#define S second
#define ll long long
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define M_PI 3.14159265358979323846
const int N = 100005;
const int mod = 1e9 + 7;
int main() {
    io;
    int n;
    cin >> n;
    cout << 1-n;
}


Measured memory_bytes: 3644
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e8;

signed main() {
	string s, t;
	cin >> s >> t;
	sort(t.begin(), t.end(), greater<int>());
	sort(s.begin(), s.end());
	if (s < t)cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 256
from collections import defaultdict, deque
v, n = map(int, input().split())
n += v-1
es = [tuple(map(int, input().split())) for _ in range(n)]
outs = defaultdict(list)
ins = defaultdict(int)
for v1, v2 in es:
    outs[v1].append(v2)
    ins[v2] += 1
q = deque(v1 for v1 in range(v) if not ins[v1])
res = []
p = [0]*(v+1)
while q:
    v1 = q.popleft()
    res.append(v1)
    for v2 in outs[v1]:
        ins[v2] -= 1
        if ins[v2] == 0:
            q.append(v2)
            p[v2] = v1

for t in p[1:]:
    print(t)


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

namespace 競プロ_Csharp {
    class Program {
        static void Main(string[] args) {

            int i = 1;

            while (true) {

                int a = NextInt();
                if (a == 0) return;

                Println("Case " + i + ": " + a);

                i++;

            }

        }

        public static void Println (Object o) {
            Console.WriteLine(o);
        }

        public static string NextString() {
            return Console.ReadLine();
        }

        public static int NextInt () {
            return int.Parse(Console.ReadLine());
        }

        public static int[] NextInts () {
            string[] a = Console.ReadLine().Split();
            int[] b = new int[a.Length];
            for (int i = 0; i < a.Length; i++) {
                b[i] = int.Parse(a[i]);
            }
            return b;
        }

    }
}



Measured memory_bytes: 17896
#include<iostream>
#include<string>
#include<stack>
using namespace std;
stack<char> t;
int main(){
	string s;
	while(getline(cin,s)){
		if(s==".")
		break;
		int m=0,k=0;
		t.push('a');
		for(int i=0;i<s.size();i++){
			if(s[i]=='(' || s[i]=='[')
			t.push(s[i]);
			if(t.top()=='(' && s[i]==')' || t.top()=='[' && s[i]==']')
			t.pop();
			else if(t.top()!='(' && s[i]==')' || t.top()!='[' && s[i]==']'){
				t.push('x');
				break;
			}
		}
		if(t.top()=='a')
		cout<<"yes"<<endl;
		else
		cout<<"no"<<endl;
		
	}
	return 0;
}

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

const ll M = 1e9 + 7;

ll mod(ll a){return ((a % M) + M) % M;}
ll pow(ll a, ll b){
	if(b == 0) return 1ll;
	if(b % 2) return mod(a * pow(a, b - 1));
	ll s = pow(a, b / 2);
	return mod(s * s);
}

int main(){
	ll n;
	cin >> n;
	ll tot = pow(10ll, n), no1 = pow(9ll, n), no2 = pow(8ll, n);
	cout << mod(tot - 2ll * no1 + no2) << endl;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int main() {
  int A, B, a, b;
  cin >> A >> B;
  int ans = 10;
  while(10000 > ans) {
    a = ans * 8 / 100;
    b = ans * 10 / 100;
    if(A==a&&B==b) {
      cout << ans;
      return 0;
    }
    ++ans;
  }
  cout << -1;
}


Measured memory_bytes: 256
import numpy as np
h,w = list(map(int, input().split()))
xs = []
for _ in range(h):
    xs.append(list(map(int, input().split())))
#     xs.append(np.random.binomial(10,0.5,w))

def move_yoko(k,x):
    temp = np.where(x[k] == 1)[0]
    ms = []
    if len(temp)%2 == 0:
        for j in range(int(len(temp)/2)):
            a = temp[2*j]
            b = temp[2*j+1]
            for i in range(b - a):
                ms.append([k,a+i,k,a+1+i])
        x[k] = 0
    else:
        for j in range(int((len(temp)-1)/2)):
            a = temp[2*j]
            b = temp[2*j+1]
            for i in range(b - a):
                ms.append([k,a+i,k,a+1+i])
        a = temp[-1]
        b = w - 1
        for i in range(b - a):
            ms.append([k,a+i,k,a+1+i])
        x[k] = 0
        x[k,-1] = 1
    return ms,x

def move_tate(k,x):
    temp = np.where(x[:,k] == 1)[0]
    ms = []
    if len(temp)%2 == 0:
        for j in range(int(len(temp)/2)):
            a = temp[2*j]
            b = temp[2*j+1]
            for i in range(b - a):
#                 ms.append([k,a+i,k,a+1+i])
                ms.append([a+i,k,a+1+i,k])
        x[:,k] = 0
    else:
        for j in range(int((len(temp)-1)/2)):
            a = temp[2*j]
            b = temp[2*j+1]
            for i in range(b - a):
                ms.append([a+i,k,a+1+i,k])
                
        a = temp[-1]
        b = h - 1
        for i in range(b - a):
            ms.append([a+i,k,a+1+i,k])
        x[:,k] = 0
        x[-1,k] = 1
    return ms,x

x = np.vstack(xs)
x = x%2

mss = []
for k in range(h):
    ms, x = move_yoko(k,x)
    mss += ms
ms, x = move_tate(w-1,x)
mss += ms
ms = mss

import sys
print(len(ms))
for a in ms:
    for k in range(len(a)):
        if k == len(a)-1:
            sys.stdout.write('{}'.format(a[k] + 1))
        else:
            sys.stdout.write('{} '.format(a[k] + 1))
    sys.stdout.write('\n')

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

#define ll long long int
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define sep(i,b,a) for(ll i=b-1;i>=a;i--)
#define hell (ll)(1e9+7)

using namespace std;

void solve()
{
    string s,t;
    cin>>s>>t;
    ll l1,l2;
    l1=s.length();
    l2=t.length();
    ll dp[l1+1][l2+1];
    rep(i,0,l1+1)
    {
        rep(j,0,l2+1)
        {
            if(i==0||j==0)
                dp[i][j]=0;
            else
                dp[i][j]=s[i-1]==t[j-1]?1+dp[i-1][j-1]:max(dp[i][j-1],dp[i-1][j]);
        }
    }
    ll i,j;
    i=l1;
    j=l2;
    string ans="";
    while(i>0&&j>0)
    {
        if(s[i-1]==t[j-1])
        {
            ans+=s[i-1];
            i--;
            j--;
        }
        else if(dp[i-1][j]>dp[i][j-1])
            i--;
        else
            j--;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 70656
package main

import (
  "fmt"
)

func main() {
  var r int
  fmt.Scan(&r)
  var ans string
  if r < 1200 {
    ans = "ABC"
  } else if r < 2800 {
    ans = "ARC"
  } else {
    ans = "AGC"
  }
  fmt.Println(ans)
}

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

int main(){
  int n,k,i,j,ans=0,cur=0,res=0;
  cin >> n >> k;
  vector<int> s(n);
  char c;
  for(i=0; i<n; i++){
    cin >> c;
    s[i]= (c=='0' ? 0 : 1);
  }
  
  vector<pair<int,int>> t(n+1);
  i=0;
  for(cur=0; i<n; cur++){
    t[cur].first = s[i];
    while(i<n && s[i]==t[cur].first){
      i++; t[cur].second++;
    }
  }
  
  if(t[0].first==0){
    for(i=cur; i>0; i--){
      t[i]= t[i-1];
    }
    t[0].first=1; t[0].second=0;
    cur++;
  }
  
  if(t[cur-1].first==0){
    t[cur].first==1; t[cur].second==0;
    cur++;
  }
  
  if(cur/2 < k){
    cout << n; return 0;
  }
  
  for(i=0; i<=cur/2-k; i++){
    res=0;
    for(j=i; j<i+k; j++){
      res+=t[2*j].second+t[2*j+1].second;
    }
    res+=t[2*j].second;
    ans=max(ans,res);
  }
  
  cout << ans;
}
  

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

using namespace std;


int TotalCount[3];

int calculation(int a, int b, int c) {
	int totalMoney = 0;

	totalMoney += (a / 5 * 5 * 0.8 + a % 5) * 380;
	totalMoney += (b / 4 * 4 * 0.85 + b % 4) * 550;
	totalMoney += (c / 3 * 3 * 0.88 + c % 3) * 850;

	return totalMoney;
}

int main() {
	int g, minMoney;

	while (cin >> g, g) {
		memset(TotalCount, 0, sizeof(TotalCount));

		TotalCount[0] = g / 200;
		TotalCount[1] = g / 300;
		TotalCount[2] = g / 500;

		minMoney = INT_MAX;
		for (int a = 0; a <= TotalCount[0]; a++) {
			for (int b = 0; b <= TotalCount[1]; b++) {
				for (int c = 0; c <= TotalCount[2]; c++) {
					if (a * 200 + b * 300 + c * 500 == g) {
						minMoney = min(minMoney, calculation(a, b, c));
					}
				}
			}
		}

		cout << minMoney << endl;
	}


	return 0;
}


Measured memory_bytes: 3080
using System;

public class Test
{
    public static void Main()
    {
        int numbers = int.Parse(Console.ReadLine());
        String directions = Console.ReadLine();

        int min = numbers;

        int[] needToFaceFromWestToEast = new int[directions.Length];
        int[] needToFaceFromEastToWest = new int[directions.Length];

        for (int i = 1; i < directions.Length; i++)
        {
            if (directions[i - 1] == 'W')
            {
                needToFaceFromWestToEast[i] = needToFaceFromWestToEast[i - 1] + 1;
            }
            else
            {
                needToFaceFromWestToEast[i] = needToFaceFromWestToEast[i - 1];
            }
        }
        
        for (int i = directions.Length - 2; i >= 0; i--)
        {
            if (directions[i + 1] == 'E')
            {
                needToFaceFromEastToWest[i] = needToFaceFromEastToWest[i + 1] + 1;
            }
            else
            {
                needToFaceFromEastToWest[i] = needToFaceFromEastToWest[i + 1];
            }
        }

        for (int i = 0; i < directions.Length; i++)
        {
            if (min > needToFaceFromWestToEast[i] + needToFaceFromEastToWest[i])
            {
                min = needToFaceFromWestToEast[i] + needToFaceFromEastToWest[i];
            }
        }

        Console.WriteLine(min);
    }
}

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

using namespace std;

#define LL           long long
#define ULL          long long unsigned
#define LD           long double
#define FOR(i,n)     for(int i=0;i<n;i++)
#define FLR(i,n)     for(LL i=0;i<n;i++)
#define RFOR(i,n)    for(int i=n-1;i>=0;i--)
#define RFLR(i,n)    for(LL i=n-1;i>=0;i--)
#define rep(i,a,b)   for(int i=a;i<=b;i++)
#define repl(i,a,b)  for(LL i=a;i<=b;i++)
#define fast         ios_base::sync_with_stdio(0);cin.tie(0);
#define all(a)       a.begin(),a.end()
#define ABS(x)       ((x)<0?-(x):(x))
#define endl         "\n"
#define PB           push_back
int main()
{
    fast;
    int a,b,c,kount=0,N,i;
    vector<int>v1,v2;
    cin>>N;
    FOR(i,N){
        cin>>a;
        v1.PB(a);
        v2.PB(a);
    }
    sort(all(v1));
    FOR(i,N){
        if(v1[i]!=v2[i])kount++;
    }
    if(kount>2)cout<<"NO";
    else cout<<"YES";
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int K,S;
    cin >> K >> S;
    int X,Y,Z;
    X = Y = 0;
    Z = S-X-Y;
    long long ans = 0;
    while(X <= K){
        Y = 0;
        while((Y <= K)){
            Z = S-X-Y;
            if(0 <= Z && Z <= K) ans++;
            Y++;
        }
        X++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    string s;
    cin >> n >> s;
    ll r=0,g=0,b=0;
    rep(i,n) {
        if(s[i] == 'R') r++;
        else if(s[i] == 'G') g++;
        else b++;
    }
    ll ans = r*g*b;
    rep(i,n) rep(j,n) {
        if(i >= j) continue;
        if(s[i] == s[j]) continue;
        int k = 2*j-i;
        if(k < n && s[k] != s[i] && s[k] != s[j]) ans--;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3596
#include <stdio.h>

int main(){
  int a,b,k;
  scanf("%d %d %d",&a,&b,&k);
  int count = 0;
  int answer;
  for(int i = a; i > 0; i--){
    if(a % i == 0 && b % i == 0) count++;
    if(count == k){
      answer = i;
      break;
    }
  }
  printf("%d\n",answer);
  return 0;
}

Measured memory_bytes: 128
from functools import reduce
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)
def lcm_all(A):
    return reduce(lcm, A, 1)

n, M = map(int, input().split())
A = set(map(lambda x: int(x)//2, input().split()))

scm_core = lcm_all(A)

canmake_scm = True
for a in A:
    if scm_core // a % 2 == 0:
        canmake_scm = False
        break

if canmake_scm:
    print(((M // scm_core)+1) // 2)
else:
    print(0)

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

int main(void)
{
    int n;
    int s;
    int i, j;

    scanf("%d", &n);
    for (i = 0; i < n; i++){
        scanf("%d", &s);
        printf("Case %d:\n", i + 1);
        for (j = 0; j < 10; j++){
            s = s * s / 100 % 10000;
            printf("%d\n", s);
        }
    }

    return (0);
}

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

#define st first
#define nd second
#define ll long long
#define ld long double
#define pb push_back
#define emp emplace_back
#define pii pair<int, int>
#define usg unsigned
#define sg signed
#define mp make_pair

using namespace std;

void setIO(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

const ld PI = 4*atan((ld)1);
const int INF = 1e9+7;
const int mxN = 1e5+7;

vector<int>ed[mxN];
int ans[mxN];

int main(){
	setIO();
	int n, m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int a, b;
		cin>>a>>b;
		ed[a].emp(b);
		ed[b].emp(a);
	}
	queue<pii>q;
	q.push({1, -1});
	while(!q.empty()){
		pii v = q.front();
		q.pop();
		if(!ans[v.st]){
			ans[v.st]=v.nd;
			for(auto x : ed[v.st])
				if(x!=v.nd)
					q.push({x,v.st});
		}
	}
	bool ok=true;
	for(int i=2;i<=n;i++){
		if(!ans[i]) ok=false;
	}
	if(!ok) cout<<"No\n";
	else{
		cout<<"Yes\n";
		for(int i=2;i<=n;i++){
			cout<<ans[i]<<endl;
		}
	}
}

Measured memory_bytes: 11308
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <utility>
#define EPS 1e-10
using namespace std;

double add(double a,double b){
	if(fabs(a+b)<EPS*(fabs(a)+fabs(b)))return 0;
	return a+b;
}

class P{
public:
	double x,y;
	P(double xx=0,double yy=0){
		x=xx;
		y=yy;
	}
	P operator +(P p){
		return P(add(x,p.x),add(y,p.y));
	}
	P operator -(P p){
		return P(add(x,-p.x),add(y,-p.y));
	}
	P operator *(double d){
		return P(x*d,y*d);
	}
	P operator /(double d){
		return P(x/d,y/d);
	}
	bool operator<(const P &p)const{
		if(add(x,-p.x)==0.0)return y<p.y;
		return x<p.x;
	}
};

typedef P Vector;

double norm(P p){
	return p.x*p.x+p.y*p.y;
}

double abs(P p){
	return sqrt(norm(p));
}

double dot(Vector a,Vector b){
	return add(a.x*b.x,a.y*b.y);
}

double cross(Vector a,Vector b){
	return add(a.x*b.y,-a.y*b.x);
}

class Segment{
public:
	P p1,p2;
	Segment(P pp1=P(),P pp2=P()){
		p1=pp1;
		p2=pp2;
	}
};

typedef Segment Line;

P project(Segment s,P p){
	Vector base=s.p2-s.p1;
	double r=dot(p-s.p1,base)/norm(base);
	return s.p1+base*r;
}

class Circle{
public:
	P c;
	double r;
	Circle(P cc=P(),double rr=0.0){
		c=cc;
		r=rr;
	}
};

double getDistanceLP(Line l,P p){
	return abs(cross(l.p2-l.p1,p-l.p1)/abs(l.p2-l.p1));
}


bool intersect(Circle c,Line l){
	return getDistanceLP(l,c.c)<=c.r;
}

pair<P,P> getCrossPoints(Circle c,Line l){
	assert(intersect(c,l));
	Vector pr=project(l,c.c);
	Vector e=(l.p2-l.p1)/abs(l.p2-l.p1);
	double base=sqrt(c.r*c.r-norm(pr-c.c));
	return make_pair(pr+e*base,pr-e*base);
}


int main(void){
	Circle c;
	scanf("%lf %lf %lf",&c.c.x,&c.c.y,&c.r);
	int q;
	scanf("%d",&q);
	for(int i=0;i<q;i++){
		Line l;
		scanf("%lf %lf %lf %lf",&l.p1.x,&l.p1.y,&l.p2.x,&l.p2.y);
		pair<P,P> res=getCrossPoints(c,l);
		if(res.second<res.first)swap(res.first,res.second);
		printf("%.9f %.9f %.9f %.9f\n",res.first.x,res.first.y,res.second.x,res.second.y);
	}
	return 0;
}

Measured memory_bytes: 1096
#include<stdio.h>
#define MAX 100000

int partition(int *,int,int);
int n;

int main() {

  int i;
  int num[MAX];

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&num[i]);

  int a = partition(num,0,n-1);

  for(i=0;i<n;i++) {
    if(i>0) printf(" ");
    if(i==a) printf("[");
    printf("%d",num[i]);
    if(i==a) printf("]");
  }
  printf("\n");

  return 0;

}

int partition(int A[n],int p,int r) {
  
  int x = A[r];
  int i = p-1;
  int j,a;

  for(j=p;j<=r-1;j++) {
    if(A[j]<=x) {
      i = i+1;
      a=A[i]; A[i]=A[j]; A[j]=a;
    }
  }
  a=A[i+1]; A[i+1]=A[r]; A[r]=a;
    
  return i+1;
}


Measured memory_bytes: 2140
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;

// c1, c2 ª'r', 'g', 'b', ©Â(c1 != c2)ÌÆ«
// m[c1+c2] Å c1, c2 ÅÈ¢'r', 'g', 'b'ªÔÁÄ­é
map<int,char> m;

// S¯¶F©Ç¤©
bool isSameColor(const string& s){
	char c[3] = {'r','g','b'};
	for(int i = 0 ; i < 3 ; i++ ){
		int cnt = 0;
		for(int j=0 ; j < s.size() ; j++ ){
			if( s[j] == c[i] )
				cnt++;
		}
		if( cnt == s.size() )
			return true;
	}
	return false;
}

int solve(string s_ ){
	// memo[s] = true ÈçTõÏÝ
	map<string,bool> memo;
	// q.front().first Í ÌóÔ(string) q.front().second Íè(int)
	queue< pair<string,int> > q;
	
	// úóÔðL[Éüêé
	pair<string,int> ini( s_ , 0  );
	q.push( ini );
	memo[s_] = true;
	
	// L[ªóÉÈéÜÅ[v
	while( !q.empty() ){
		// stirng s; ÍÌóÔ, int cnt; Íè
		string s = q.front().first;
		int cnt = q.front().second;
		q.pop();
		
		// S¯¶FÈçTõI¹
		if( isSameColor(s) ){
			return cnt;
		}
		
		// Ü¾TõµÄ¢È¢ÌóÔðL[Éüêé
		for(int i=1 ; i < s.size() ; i++ ){
			if( s[i-1] != s[i] ){
				char next_color = m[s[i-1]+s[i]];
				char c1 = s[i-1];
				char c2 = s[i];
				s[i-1] = s[i] = next_color;
				if( memo[s] != true ){
					memo[s] = true;
					pair<string,int> next;
					next.first = s;
					next.second = cnt + 1;
					q.push( next );
				}
				s[i-1] = c1;
				s[i] = c2;
			}
		}
	}
	return -1;
}

int main(){
	string s;
	m['r'+'g'] = 'b';
	m['g'+'b'] = 'r';
	m['b'+'r'] = 'g';
	
	while( cin >> s , s != "0" ){
		int ans = solve( s );
		if( ans == -1 )
			cout << "NA" << endl;
		else
			cout << ans << endl;
	}
}

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

int main()
{
    int64_t N, A, B;
    cin >> N >> A >> B;
    if ((B - A) % 2 == 0)
    {
        cout << (B - A) / 2 << endl;
    }
    else
    {
        int64_t ans;
        ans = min(A - 1, N - B) + 1 + (B - A - 1) / 2;
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
static mt19937 _g(time(nullptr));
 
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N,K;
vector<int> A;
void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path p = __FILE__;
        fs::path input,output;
        input = output = p.parent_path();
        input += string("/input/") + string(p.stem()) + string(".txt");
        output += string("/output/") + string(p.stem()) + string(".txt");
        freopen(input.c_str(), "r", stdin);
        freopen(output.c_str(), "w", stdout);
    #endif
    cin >> N >> K;
    A = fetch_vec<int>(N);
}

int solve(){
    auto itr = min_element(A.begin(),A.end());
    int idx_left = itr-A.begin();
    int left_n = ceil((double)idx_left/(K-1));
    int idx_right = (N-1)-left_n*(K-1);
    int right_n = ceil((double)idx_right/(K-1));
    cout << (left_n+right_n) << endl;
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h> 
 
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const double EPS=1e-10;

double add(double a,double b){
    if(abs(a+b)<EPS*(abs(a)+abs(b)))return 0;
    return a+b;
}
struct P{
    double x,y;
    P(){}
    P(double x,double y):x(x),y(y){
    }
    P operator + (P p){
        return P(add(x,p.x),add(y,p.y));
    }
    P operator - (P p){
        return P(add(x,-p.x),add(y,-p.y));
    }
    P operator * (double d){
        return P(x*d,y*d);
    }
    double dot(P p){
        return add(x*p.x,y*p.y);
    }
    double det(P p){
        return add(x*p.y,-y*p.x);
    }
};
bool cmp_x(const P&p,const P& q){
    if(p.x!=q.x)return p.x<q.x;
    return p.y<q.y;
}
vector<P> convex_hull(P* ps,int n){
    sort(ps,ps+n,cmp_x);
    int k=0;
    vector<P>qs(n*2);
    REP(i,n){
        while(k>1&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)k--;
        qs[k++]=ps[i];
    }
    for(int i=n-2,t=k;i>=0;i--){
        while(k>t&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)k--;
        qs[k++]=ps[i];
    }
    qs.resize(k-1);
    return qs;
}
P ps[101];
int main(){
    double pi=atan(1.0)*4.0;
    int N;
    cin>>N;
    map<PII,int>mp;
    REP(i,N){
        int x,y;
        cin>>x>>y;
        ps[i]=P(x,y);
        mp[MP(x,y)]=i;
    }
    vector<P>qs=convex_hull(ps,N);
    P divp;
    vector<double>res(N,0);
    long double sum=0.0;
    int Q=SZ(qs);
    REP(i,SZ(qs)){
        divp=qs[(i+1)%Q]-qs[i%Q];
        double d1=sqrt(divp.x*divp.x+divp.y*divp.y);
        P p1=divp;
        divp=qs[(i-1+Q)%Q]-qs[i%Q];
        double d2=sqrt(divp.x*divp.x+divp.y*divp.y);
        P p2=divp;
        double as=acos(p1.dot(p2)/(d1*d2));
        //cout<<mp[MP(qs[i].x,qs[i].y)]<<" "<<as<<endl;
        //cout<<mp[MP(qs[i].x,qs[i].y)]<<" "<<M_PI-abs(as)<<endl;
        sum+=abs(pi-as);
        res[mp[MP((int)qs[i].x,(int)qs[i].y)]]=abs(pi-as);
    }
    if(Q==2){
        REP(i,N){
            if(res[i]!=0)cout<<0.5<<endl;
            else cout<<0.0<<endl;
        }
        return 0;
    }
    REP(i,N){
        cout<<fixed<<setprecision(10)<<res[i]/sum<<endl;
    }
    return 0;
}

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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
    
int main(){
    int n;
    cin>>n;
    vector<int> cnt(26,100);
    vector<string> s(n);
    cin>>s;
    for(auto &it:s)for(auto &jt:it)jt-='a';
    REP(i,n){
        vector<int> c(26,0);
        for(auto &it:s[i])c[it]++;
        REP(i,26)chmin(cnt[i],c[i]);
    }
    REP(i,26)REP(j,cnt[i])cout<<(char)(i+'a');
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
import  java.util.*;
class Main{
    int a;
    int b;
    int c;
    Main(){
	Scanner sc=new Scanner(System.in);
	a=sc.nextInt();
        b=sc.nextInt();
	c=sc.nextInt();

	if(a==1 && b==1 && c==0 || a==0 && b==0 && c==1){
	    System.out.println("Open");
	}else if(a==1 && b==0 && c==0 || a==0 && b==1 && c==0 || a==0 && b==0 && c==0){
	    System.out.println("Close");
	}
    }

    public static void main(String[] args){
	new Main();
    }
}

Measured memory_bytes: 17156
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	string s;
	cin >> s;
	int n = s.size();
	for(int i = 0;i < n;i++){
		if(i + 6 < n){
			string emp = "";
			for(int j = 0;j < 7;j++){
				emp += s[i+j];
			}
			if(emp == "dreamer"){
				if(i + 7 >= n){
					i = i+6;
					continue;
				}
				else if(i + 7 < n && s[i+7] != 'a'){
					i = i+6;
					continue;
				}
				else{
					i += 4;
					continue;
				}
			}
		}
		if(i + 5 < n){
			string emp = "";
			for(int j = 0;j < 6;j++){
				emp += s[i+j];
			}
			if(emp == "eraser"){
				i += 5;
				continue;
			}
		}
		if(i + 4 < n){
			string emp = "";
			for(int j = 0;j < 5;j++){
				emp += s[i+j];
			}
			if(emp == "erase" || emp == "dream"){
				i += 4;
				continue;
			}
		}
		cout << "NO" << endl;
		return 0;
	}

	cout << "YES" << endl;
}


Measured memory_bytes: 512
import java.util.Scanner;

//20180508
//09

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

		int num = scanner.nextInt();
		for(int i = 1;i <= num;i++) {
			x = i;
			if(i % 3 == 0) {
				System.out.printf(" %d", i);
			} else {
				while(true) {
					if(x % 10 == 3) {
						System.out.printf(" %d", i);
						break;
					}
					x /= 10;
					if(x == 0) {
						break;
					}
				}
			}
		}
		System.out.println();

    	scanner.close();
    }
}


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

const long N = 100;
long M[N + 1][N + 1];
long d[N + 1];
long n;
const long INFTY = 101;

long solve(long id, long dist){
	if (id == 1) d[1] = 0;
	for (long i = 2; i <= n; i++){
		if (M[id][i]){
			if (dist + 1 < d[i]){
				d[i] = dist + 1;
				solve(i, dist + 1);
			} 
		}
	}
}

int main(){
	cin >> n;
	for (long i = 1; i <= n; i++){
		d[i] = INFTY;
		for (long j = 1; j <= n; j++){
			M[i][j] = 0;
		}
	}
	for (long i = 0; i < n; i++){
		long v, k;
		cin >> v >> k;
		for (long j = 0; j < k; j++){
			long nh;
			cin >> nh;
			M[v][nh] = 1;
		}
	}
	solve(1, 0);
	for (long i = 1; i <= n; i++){
		if (d[i] == INFTY) d[i] = -1;
		cout << i << " " << d[i] << endl;
	}
	return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  int64_t D, A;
  cin >> N >> D >> A;
  vector<int64_t> X(N), H(N);
  for (int i = 0; i < N; i++) {
    cin >> X[i] >> H[i];
  }
  vector<int> idx(N);
  iota(idx.begin(), idx.end(), 0);
  sort(idx.begin(), idx.end(), [&](int a, int b) { return X[a] < X[b]; });
  queue<pair<int, int64_t>> que;
  int64_t res = 0, d = 0;
  for (int i : idx) {
    while (!que.empty() && X[i] > que.front().first) {
      d -= que.front().second;
      que.pop();
    }
    H[i] -= d;
    if (H[i] <= 0) continue;
    int cnt = (H[i] + A - 1) / A;
    res += cnt;
    d += cnt * A;
    que.push(make_pair(X[i] + 2 * D, cnt * A));
  }
  cout << res << '\n';
  return 0;
}


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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define REPRl(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < (int)n; i++)
#define FORl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define ALL(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}

int main() {
  int n;cin>>n;
  int tmpmax=0, count=0;
  REP(i,n){
  	int h;cin>>h;
    if(h>=tmpmax){
      count++;
      tmpmax=h;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;

//関数getinputdata宣言
vector<vector<string>> getinputdata();
vector<vector<int>> getinputdata2();

void abc042(vector<vector<int>> v) {

    
   vector<int> data = v[0];
   
   sort( data.begin(), data.end() );
   
   if(data[0]==5 && data[1]==5 && data[2]==7){
       cout << "YES" <<endl;
       
   }else{
       cout << "NO" <<endl;
       
   }

  
}

void nikkei2019_qual_a(vector<vector<int>> v) {


    int n = v[0][0];
    int a = v[0][1];
    int b = v[0][2];

    int maxdata = min(a, b);
    int mindata = (a - b >= 0 ? b : 0);

    cout << maxdata << " " << mindata << endl;
}

int main() {

//    vector<vector < string>> vec_arr_result;
        vector<vector<int>> vec_arr_result;
    vec_arr_result = getinputdata2();

    //    nikkei2019_qual_a(vec_arr_result);

    abc042(vec_arr_result);

    return 0;
}

//関数getinputdata実装

vector<vector<int>> getinputdata2() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector<int>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<int> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(atoi(ret.c_str()));
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;


}

//関数getinputdata実装

vector<vector<string>> getinputdata() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector < string>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<string> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(ret);
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;

}

Measured memory_bytes: 256
package main

import "fmt"

func main(){
	var n,ans int
	fmt.Scan(&n)
	a := make([]int,n)
	for i:=0 ; i<n ; i++ {
		fmt.Scan(&a[i])
	}
	for i:=0 ; i<n ; i+=2 {
		if a[i]%2 == 1 {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1776
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
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 (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N,W;cin >> N >> W;
    vector<LL> w(N);
    vector<LL> v(N);
    rep(i,N)cin >> w[i] >> v[i];
    LL dp[110][111111] = {0};

    rep(i,N){   // 何個目のアイテムまで選択済みにしたかのループ
        for(int sum_w = 0;sum_w <= W;sum_w++){  // 容量の上限をインクリメントしていくループ
            
            if(sum_w - w[i] >= 0){  //i番目を入れるとき
                chmax(dp[i+1][sum_w],dp[i][sum_w - w[i]] + v[i]);
            }

            chmax(dp[i+1][sum_w],dp[i][sum_w]); //i番目を入れないとき
        }
    }

    // 上のループによって、縦軸がアイテムの2^Ω、横軸が各タイミングの容量限界、というような高々　N*M(*2)　のループが完成。
    // これをDPテーブルとする。

    LL ans = dp[N][W];  // i = 0 はそもそもアイテムが無く虚無なので、N-1　ではなく、Nになる。
    cout << ans << endl;
}



Measured memory_bytes: 95744
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();
		int getAIndex = 0;
		int getZIndex = 0;
		char[] ch =s.toCharArray();
		for(int i = 0;i < ch.length;i++) {
			if(ch[i] == 'A') {
				getAIndex = i;
				break;
			}
		}
		for(int i = ch.length-1;i > 0;i--) {
			if(ch[i] == 'Z') {
				getZIndex = i;
				break;
			}
		}
		System.out.println(getZIndex - getAIndex + 1);
	}
}

Measured memory_bytes: 25812
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr ll MOD = 1000000007;

int main() {
	int n, m; cin >> n >> m;
	vector<vector<P>> q(n+1);
	for (int i = 0; i < m; ++i) {
		int l, r, x; cin >> l >> r >> x;
		q[r].push_back(make_pair(l, x));
	}
	vector<vector<vector<ll> > > dp(n+1, vector<vector<ll> >(n+1, vector<ll>(n+1, 0)));
	dp[0][0][0] = 1;
	vector<vector<ll> > cum(n+1, vector<ll>(n+1, 0));

	for (int r = 1; r < n+1; ++r) {
		for (int g = 0; g < r; ++g) {
			for (int b = 0; b < r; ++b) {
				if (g+b > 0 and b >= g) continue;
				dp[r][g][b] = dp[r-1][g][b];
				if (g == r-1 or b == r-1) {
					dp[r][g][b] += cum[g][b];
					dp[r][g][b] %= MOD;
				}
				for (P p : q[r]) {
					int l = p.first; int x = p.second;
					if (x == 1) {
						if (g >= l or b >= l) dp[r][g][b] = 0;
					}
					if (x == 2) {
						if ((g >= l and b >= l) or (g < l and b < l)) dp[r][g][b] = 0;
					}
					if (x == 3) {
						if (g < l or b < l) dp[r][g][b] = 0;
					}
				}
				cum[g][b] += dp[r][g][b];
				cum[g][b] %= MOD;

				if (g+b > 0) {
					dp[r][b][g] = dp[r][g][b];
					cum[b][g] += dp[r][g][b];
					cum[b][g] %= MOD;
					dp[b][r][g] = dp[r][g][b];
					cum[r][g] += dp[r][g][b];
					cum[r][g] %= MOD;
					dp[b][g][r] = dp[r][g][b];
					cum[g][r] += dp[r][g][b];
					cum[g][r] %= MOD;
					dp[g][r][b] = dp[r][g][b];
					cum[r][b] += dp[r][g][b];
					cum[r][b] %= MOD;
					dp[g][b][r] = dp[r][g][b];
					cum[b][r] += dp[r][g][b];
					cum[b][r] %= MOD;
				}
				else {
					dp[0][r][0] = dp[r][0][0];
					dp[0][0][r] = dp[r][0][0];
					cum[r][0] += dp[r][0][0];
					cum[r][0] %= MOD;
					cum[0][r] += dp[r][0][0];
					cum[0][r] %= MOD;
				}
			}
		}
	}
	ll ans = (3 * dp[n][0][0]) % MOD;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < i; ++j) {
			ans += 6 * dp[n][i][j];
			ans %= MOD;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 220276
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] t = sc.next().split("");
		for(int i = 0;i < t.length;i++) {
			if(!t[i].equals("?")) {
				continue;
			}
			// 左隣りがPだったらDにする
			if(i >0 && t[i-1].equals("P")) {
				t[i] = "D";
				continue;
			}
			// 右隣りがDだったらPにする
			if(i <t.length-1 && t[i+1].equals("D")) {
				t[i] = "P";
				continue;
			}
			// それ以外はDにする。
			t[i] = "D";
		}
		StringBuilder answer = new StringBuilder();
		for(String s:t) {
			answer.append(s);
		}
		System.out.println(answer);
	}

}

Measured memory_bytes: 55760
#include <iostream>
#include <set>
#define ll long long
using namespace std;

int main()
{
    ll N;
    cin >> N;
    set<int> ans;
    if (N == 2)
        cout << 1 << endl;
    else
    {
        for (int i = 2; 1ll * i * i <= N; i++)
        {
            if ((N - 1) % i == 0)
            {
                ans.insert(i);
                ans.insert((N - 1) / i);
            }
            if (N % i == 0)
            {
                ll M = N;
                while (M % i == 0)
                    M /= i;
                if (M % i == 1)
                    ans.insert(i);
            }
        }
        cout << ans.size() + 2 << endl;
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
#define endl '\n'
using namespace std;
using i64 = long long;
using pii = pair<int, int>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}}

signed main()
{
    cin.tie(nullptr); ios::sync_with_stdio(false);

    int H, W, D, Q;
    int x[90090], y[90090];

    cin >> H >> W >> D;
    for (int i = 1; i <= H; ++i) {
        for (int j = 1; j <= W; ++j) {
            int a; cin >> a;
            y[a] = i;
            x[a] = j;
        }
    }

    int dist[909090] {};

    for (int i = D+1; i <= H*W; ++i) {
        dist[i] = dist[i-D] + abs(y[i] - y[i-D]) + abs(x[i] - x[i-D]);
    }

    cin >> Q;
    while (Q--) {
        int L, R;
        cin >> L >> R;
        cout << dist[R] - dist[L] << endl;
    }


    return 0;
}


Measured memory_bytes: 5376
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define INF 1000000007
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2)*pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int jo(int n) {
	int ans = 1;
	rep(i, n) {
		ans *= 2;
	}
	return ans;
}
signed main() {
	int a;
	string s;
	int d = 0, f = 0;
	cin >> a >> s;
	rep(i, s.size()) {
		if (s[i] == 'R')d++;
		else f++;
	}
	if (d > f)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func digitNum(n int) int {
    count := 0

    for {
        count++
        n /= 10
        if n == 0 {
            return count
        }
    }
}

func main() {
    sc.Split(bufio.ScanWords)
    n, m := nextInt(), nextInt()

    var s, c []int

    for i := 0; i < m; i++ {
        s = append(s, nextInt())
        c = append(c, nextInt())
    }

    for i := 0; i < 1000; i++ {
        if n == digitNum(i) {
            str := strconv.Itoa(i)
            f := true
            for j := 0; j < m; j++ {
                str2 := strconv.Itoa(c[j])
                if string(str[s[j]-1]) != str2 {
                    f = false
                    break
                }
            }
            if f {
                fmt.Println(i)
                os.Exit(0)
            }
        }
    }

    fmt.Println(-1)

}





//===========================
//
// Library
//
//===========================

func max(a, b int) int {
    if a > b {
        return a
    }
    return b
}

func min(a, b int) int {
    if a < b {
        return a
    }
    return b
}

func gcd(x, y int) int {
    if y == 0 {
        return x
    }

    return gcd(y, x%y)
}

//====================
//  var q Queue
//  q.Enqueue(n)
//  n := q.Dequeue()
//====================
type Queue struct {
    data []int
}

func (q *Queue) Enqueue(n int) {
    q.data = append(q.data, n)
}

func (q *Queue) Dequeue() int {
    tmp := q.data[0]
    q.data = q.data[1:]
    return tmp
}

func nextLine() string {
    sc.Scan()
    return sc.Text()
}

func nextInt() int {
    sc.Scan()
    i, _ := strconv.Atoi(sc.Text())
    return i
}

func nextIntArr(n int) []int {
    var a []int
    for i := 0; i < n; i++ {
        a = append(a, nextInt())
    }
    return a
}

// 数値を桁区切りのスライスにする
func digit(n int, list []int) []int {
   if n > 0 {
       return digit(n/10, append(list, n%10))
   }
   return list
}

func sortIntsRev(list []int) {
    sort.Sort(sort.Reverse(sort.IntSlice(list)))
}

func strReverse(s string) string {
    runes := []rune(s)
    for i := 0; i < len(s)/2; i++ {
        runes[i], runes[len(s)-1-i] = runes[len(s)-1-i], runes[i]
    }
    return string(runes)
}



Measured memory_bytes: 640