akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
using ll = long long;

using namespace std;



int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    rep(i,s.size()) {
        s[i] = 'A' + (s[i]-'A'+n)%26;
    }
    cout << s << endl;

    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define int long long
using namespace std;
int MOD = 1000000007;

signed main(){
    string S;
    cin >> S;
    
    if(S.length()%2 != 0){
        cout << "No" << endl;
        return 0;
    }
    
    int cnt = 0;
    for(int i=0;i<S.length();i+=2){
        if(S[i] == 'h' && S[i+1] == 'i'){
        }else{ cnt++;
        }
    }
    if(cnt == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね

//ここから編集する


int main() {
    int N, K;
    cin >> N >> K;
    vector<int> px(N);
    vector<int> py(N);
    vector<int> x(N);
    vector<int> y(N);
    bool flag[50][50][50][50];
    REP(i, 0, N) {
        REP(j, 0, N) {
            REP(k, 0, N) {
                REP(l, 0, N) {
                    flag[i][j][k][l] = false;
                }
            }
        }
    }

    REP(i, 0, N) {
        cin >> px[i] >> py[i];
        x[i] = px[i];
        y[i] = py[i];
    }

    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    REP(i, 0, N) {
        REP(j, 0, N) {
            REP(k, 0, N) {
                REP(l, 0, N) {
                    int cnt = 0;
                    REP(m, 0, N) {
                        if (x[i] <= px[m] && px[m] <= x[k] && y[j] <= py[m] && py[m] <= y[l]) {
                            cnt++;
                        }
                    }
                    if (cnt >= K) {
                        flag[i][j][k][l] = true;
                    }


                }
            }
        }
    }
    ll ans = (ll)(x[N-1] - x[0]) * (ll)(y[N-1] - y[0]);
    REP(i, 0, N) {
        REP(j, 0, N) {
            REP(k, 0, N) {
                REP(l, 0, N) {
                    if (flag[i][j][k][l]) {
                        ans = min(ans,(ll)(x[k] - x[i]) * (ll)(y[l] - y[j]));
                    }
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main() {
  string s, t;
  cin >> s >> t;
  if(s.size() > t.size()) {
    cout << "GREATER\n";
    return 0;
  } else if(s.size() < t.size()) {
    cout << "LESS\n";
    return 0;
  } else {
    int ss = s.size();
    for(int i = 0; i < ss; i++) {
      if(s[i] > t[i]) {
        cout << "GREATER\n";
        return 0;
      } else if(s[i] < t[i]) {
        cout << "LESS\n";
        return 0;
      }
    }
    cout << "EQUAL\n";
    return 0;
  }
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
//const ll MOD = 1e9+7;
const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N, S;
    cin >> N >> S;
    int A[N];
    rep(i, N) cin >> A[i];
    //dp[i][j]:=A[0]からA[i-1]までで総和をjになるようにとるとり方(重み付き)
    ll dp[N+1][S+1];
    ll ans = 0;
    fill(dp[0], dp[N+1], 0);
    rep(i, N){
        rep(j, S+1) dp[i+1][j] = dp[i][j];
        rep3(j, S, A[i]+1){
            dp[i+1][j] += dp[i][j-A[i]];
            dp[i+1][j] %= MOD;
        }
        if(A[i] <= S){
            dp[i+1][A[i]] += i+1;
          	dp[i+1][A[i]] %= MOD;
        }
        ans += (N-i)*(MOD+dp[i+1][S]-dp[i][S]);
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 70656
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int ans=0;
    if(d<0){
        if(a<0)
        ans=a*c;
        else{
            if(a==0){
                ans=0;
            }
            else{
                ans=d*a;
            }
        }
    }
    else if(b<0){
        if(c<0)
        ans=a*c;
        else{
            if(c==0){
                ans=0;
            }
            else{
                ans=b*c;
            }
        }
    }
    else{
        ans=b*d;
        ans=max(ans,a*c);
        ans=max(0ll,ans);
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 3636
n = int(input())
a = list(map(int, input().split()))
b = list(set(a))

if a.count(0) == n:
    print('Yes')
elif n%3 != 0:
    print('No')
elif a.count(max(a)) == 2*n//3 and a.count(0) == n//3:
    print('Yes')
elif len(b) == 3 and b[0]^b[1]^b[2] == 0 and a.count(b[0]) == a.count(b[1]) == a.count(b[2]):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 20556
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();

		String ans = "";
		if (n == 0)
			ans = "0";
		while (n != 0) {
			if (n % 2 != 0) {
				ans = "1" + ans;
				if (n < 0)
					n = n / -2 + 1;
				else
					n /= -2;
			} else {
				ans = "0" + ans;
				n /= -2;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23764
n,m = map(int,input().split())
ans = [0]*n

l = [list(map(int,input().split())) for i in range(m)]

for i in range(1000):
    if len(str(i)) == n:
        
        check = True
        for j,k in l:
            if int(str(i)[j-1]) != k:
                check = False
                
        if check:
            print(i)
            exit()
print(-1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    int H,W,h,w;
    cin>>H>>W>>h>>w;
    cout<<(H-h)*(W-w)<<endl;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
prev=A[0]-1
ans=B[prev]
for curr in A[1:]:
    curr-=1
    ans+=B[curr]
    if curr-prev==1:
        ans+=C[prev]
    prev=curr
print(ans)


Measured memory_bytes: 38544
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

result = 0
for i in range(N):
    result += B[A[i] - 1]
    if i < N - 1:
        if A[i+1] - A[i] == 1:
            result += C[A[i] - 1]

print(result)


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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define PB push_back
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, start_index, num)  (a).begin()+(start_index),(a).begin()+(num)

int main() {
	int n;
	cin >> n;
	map<int,int> st;
	int cnt = 0;

	FOR(i, 0, n - 1) {
		int a;
		cin >> a;
		st[a]++;
		
	}
	
	for (auto a : st) {
		if (a.second>=2) {
			cnt+=a.second;
			continue;
		}

		if (a.first == 1)continue;

		if (st.count(1)) {
			cnt++;
			continue;
		}

		int lim = sqrt(a.first);
		FOR(i,2,lim){
			if (a.first%i != 0)continue;
			if (st.count(i)) {
				cnt++;
				break;
			}
			if (st.count(a.first/i)) {
				cnt++;
				break;
			}
		}
	}
	pv(n-cnt);
	return 0;
}

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

bool dfs(int i);
int n,a[50];
bool fil[50];

bool dfs2(int i,int j,int rem){
    if(rem==0) return dfs(i+1);
    if(j==n) return false;

    if(!fil[j] && a[j]<=rem){
        fil[j]=true;
        if(dfs2(i,j+1,rem-a[j])) return true;
        fil[j]=false;
    }
    return dfs2(i,j+1,rem);
}

bool dfs(int i){
    if(i==n) return true;
    if(!fil[i]) return false;
    return dfs2(i,i+1,a[i]) || dfs(i+1);
}

int main(){
    for(;scanf("%d",&n),n;){
        rep(i,n){
            scanf("%d",a+i);
            fil[i]=false;
        }
        sort(a,a+n,greater<int>());
        fil[0]=true;
        puts(dfs(0)?"YES":"NO");
    }

    return 0;
}

Measured memory_bytes: 3068
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  std::string S;
  std::cin >> S;

  std::map<char, ll> mc;
  for (auto c : S) {
    mc[c]++;
  }

  char ans = '-';
  for (char c = 'a'; c <= 'z'; c++) {
    if (mc[c] < 1) {
      ans = c;
      break;
    }
  }

  bool judge = ans == '-';
  if (judge) print("None");
  else print(ans);

  return 0;
}


Measured memory_bytes: 512
#include<stdio.h>

int SelectionSort(int* a, int n){
	int i,j,cnt=0,tmp,min,pos;
	for(i=0;i+1<n;i++){
		min=a[i];	pos=i;
		for(int j=i+1;j<n;j++){
			if(min>a[j]){
				min=a[j];
				pos=j;
			}
		}

		if(pos!=i){
			cnt++;
			tmp=a[i];
			a[i]=a[pos];
			a[pos]=tmp;
		}
	}

	return cnt;
}

int main(){
	int i,n,cnt, a[100];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}

	cnt=SelectionSort(a,n);

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



Measured memory_bytes: 2708
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		int w, h;
		cin >> w >> h;
		vector< vector<int> > p(h, vector<int>(w, 0));
		vector< vector<int> > pp(h, vector<int>(w, 0));
		int x, y;
		for (int i = 0; i < n; i++) {
			cin >> x >> y;
			p[y - 1][x - 1]++;
		}
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				pp[i][j] = p[i][j];
				if (i > 0) {
					pp[i][j] += pp[i - 1][j];
				}
				if (j > 0) {
					pp[i][j] += pp[i][j - 1];
				}
				if (i > 0 && j > 0) {
					pp[i][j] -= pp[i - 1][j - 1];
				}
			}
		}
		//cout << pp[h - 1][w - 1] << endl;
		int s, t;
		cin >> s >> t;
		int ans = 0;
		for (int i = 0; i + t - 1 < h; i++) {
			for (int j = 0; j + s - 1 < w; j++) {
				int aa = pp[i + t - 1][j + s - 1];
				if (i > 0) {
					aa -= pp[i - 1][j + s - 1];
				}
				if (j > 0) {
					aa -= pp[i + t - 1][j - 1];
				}
				if (i > 0 && j > 0) {
					aa += pp[i - 1][j - 1];
				}
				ans = max(ans, aa);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,temp;
    cin>>n;
    vector<ll>v;
    for(ll i=0;i<n;i++){
        cin>>temp;
        v.push_back(temp);
    }
    ll c=1,final1=0;
    for(ll i=0;i<n;i++){
        if(c==v[i]){
            c++;
        }
        else{
            final1++;
        }
    }
    if(c!=1)
    cout<<final1<<endl;
    else
        cout<<-1<<endl;

    return 0;
}


Measured memory_bytes: 2420
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("faild to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token
        .parse()
        .ok()
        .expect("faild to parse token")
}

fn main(){
    let n: usize = read();
    let a: Vec<u64> = (0..n).map(|_| read()).collect();

    let all = (&a).into_iter().fold(0, |b, &c| b ^ c);

    for i in 0..n {
        if i == n - 1 {
            println!("{}", all ^ a[i]);
        } else {
            print!("{} ", all ^ a[i]);
        }
    }
}


Measured memory_bytes: 4056
import sys
sys.setrecursionlimit(1000000)
from math import factorial, ceil, floor
from bisect import bisect_right as bsr
from operator import itemgetter as ig
from collections import defaultdict as dd
from collections import deque, Counter as cnt

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)
def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]
def nlist(n, v):
    if not n: return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]

# エントリーポイント
def main():
    N, M, P = input([int, 3])
    ABC = input([[int, 3], M])

    # Nから到達できる辺のみ抽出する
    g = nlist([N + 1], [])
    for a, b, _ in ABC:
        g[b] += [a]
    que, rch = [N], {N}
    while que:
        cur = que.pop()
        for nxt in g[cur]:
            if nxt in rch: continue
            rch |= {nxt}
            que.append(nxt)
    edges = [(a, b, c) for a, b, c in ABC if a in rch and b in rch]

    # ベルマンフォード法で負の最短経路(スコアの最大値)を導出する
    g = nlist([N + 1], INF)
    g[1] = 0
    for _ in range(N):
        f = True
        for a, b, c in edges:
            c = -(c - P)
            if g[a] + c < g[b]:
                g[b] = g[a] + c
                f = False
        if f:
            break
    else:
        # 負の閉路を除外する
        print(-1)
        return
    print(max(0, -g[N]))
    return

if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()


Measured memory_bytes: 48492
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main() {
  int N;
  vector<int64_t> var(3);
  cin >> N >> var[0] >> var[1] >> var[2];

  vector<int> op;
  rep(i, N) {
    string s;
    cin >> s;

    if (s == "AB") {
      op.push_back(0);
    } else if (s == "BC") {
      op.push_back(1);
    } else {
      op.push_back(2);
    }
  }

  int64_t S = var[0] + var[1] + var[2];
  vector<int> result;
  if (S == 0) {
    cout << "No\n";
    return 0;
  } else if (S == 1) {
    rep(i, N) {
      int j = op[i];
      if (var[j] == 0 && var[(j + 1) % 3] == 0) {
        cout << "No\n";
        return 0;
      } else {
        result.push_back((var[j] < var[(j + 1) % 3] ? j : (j + 1) % 3));
        swap(var[j], var[(j + 1) % 3]);
      }
    }
  } else if (S == 2) {
    vector<vector<bool>> reach(N + 1, vector<bool>(27, false));

    rirep(i, N) rep(x, 3) rep(y, 3) rep(z, 3) {
      vector<bool>::reference curr = reach[i][x * 9 + y * 3 + z];
      if (i == N) {
        curr = (x + y + z == 2);
      } else {
        const int d[] = {1, -1, 0};
        int j = op[i];
        int dx = d[(3 - j) % 3];
        int dy = d[(4 - j) % 3];
        int dz = d[(5 - j) % 3];

        curr = ((x + dx >= 0 && y + dy >= 0 && z + dz >= 0 &&
                 reach[i + 1][(x + dx) * 9 + (y + dy) * 3 + z + dz]) ||
                (x - dx >= 0 && y - dy >= 0 && z - dz >= 0 &&
                 reach[i + 1][(x - dx) * 9 + (y - dy) * 3 + z - dz]));
      }
    }

    int x = var[0], y = var[1], z = var[2];
    rep(i, 3) rep(j, 3) rep(k, 3) {
      cerr << i << " " << j << " " << k << " : " << reach[0][x * 9 + y * 3 + z]
           << "\n";
    }
    if (!reach[0][x * 9 + y * 3 + z]) {
      cout << "No\n";
      return 0;
    }

    rep(i, N) {
      const int d[] = {1, -1, 0};
      int j = op[i];
      int dx = d[(3 - j) % 3];
      int dy = d[(4 - j) % 3];
      int dz = d[(5 - j) % 3];

      if (x + dx >= 0 && y + dy >= 0 && z + dz >= 0 &&
          reach[i + 1][(x + dx) * 9 + (y + dy) * 3 + z + dz]) {
        x += dx;
        y += dy;
        z += dz;
        result.push_back(j);
      } else {
        x -= dx;
        y -= dy;
        z -= dz;
        result.push_back((j + 1) % 3);
      }
    }

  } else {
    rep(i, N) {
      int j = op[i];
      if (var[j] == 0 && var[(j + 1) % 3] == 0) {
        cout << "No\n";
        return 0;
      } else {
        if (var[j] < var[(j + 1) % 3]) {
          result.push_back(j);
          var[j]++;
          var[(j + 1) % 3]--;
        } else {
          result.push_back((j + 1) % 3);
          var[j]--;
          var[(j + 1) % 3]++;
        }
      }
    }
  }

  cout << "Yes\n";
  rep(i, N) { cout << (char)("ABC"[result[i]]) << "\n"; }
  return 0;
}

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

#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 reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define repp(i, n) rep(i, n)
#define reppp(i, n) repp(i, n)
#define rrepp(i, n) rrep(i, n)
#define repss(i, n) reps(i, n)
#define repcc(i, n) repc(i, n)
#define repii(i, a, b) repi(i, a, b)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  int a, b, c;
  char _;
  int ans1 = 0, ans2 = 0;
  while (cin >> a >> _ >> b >> _ >> c) {
    if (a * a + b * b == c * c) {
      ans1++;
    } else if (a == b) {
      ans2++;
    }
  }
  cout << ans1 << '\n';
  cout << ans2 << '\n';
}



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

int main(){
  int D[101][10001], N, W, v[100], w[100], ans;
  cin >> N >> W;

  for(int i = 0;i < N; i++) cin >> v[i] >> w[i];
  for(int i = 0;i < 100*N+1; i++) D[0][i]=1000000001;
  D[0][0] = 0;
  for(int i = 1; i < N+1; i++)
    for(int j = 0; j < N*100+1; j++)
      D[i][j] = (j-v[i-1]>=0) ? D[i][j]=min(D[i-1][j], D[i-1][j-v[i-1]]+w[i-1]):D[i][j]=D[i-1][j];
    
  for (int i = 0; i <= N*100; i++)
    if (D[N][i] <= W) ans = i;
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 7068
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>
//#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
#define mod 1e9 + 7;
ll gcd(ll x, ll y)
{
	ll r;
	while ((r = x % y) != 0)
	{
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y)
{
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x * y);
}


int main() {
	string  s;
	int count = 0,i,j;
	cin >> s;
	char c = 'a';
	for (i = 0; i < 26;i++) {
		rep(j, s.size()) {
			if (s[j] == c)
				count++;
		}
		if (count == 0)
			break;
		c++;
		count = 0;
	}
	if (i == 26)
		cout << "None";
	else
		cout << c;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <cstdio>
#include <map>
#include <functional>
#include <algorithm>
#include <tuple>
#include <string.h>
using namespace std;

typedef tuple<int, int, int, int> T;

int main() {
	int a, b, c, n;
	while(cin >> a >> b >> c && (a || b || c)){
		cin >> n;
		vector<T> test;
		int w, x, y, z;
		for(int i = 0; i < n; ++i){
			scanf("%d %d %d %d", &w, &x, &y, &z);
			test.push_back(T(z, w, x, y));
		}
		sort(test.begin(), test.end(), greater<T>());
		int check[1001], j;
		for(int i = 0; i <= 1000; ++i)
			check[i] = 2;
		
		for(j = 0; get<0>(test[j]) != 0; ++j){
			check[get<1>(test[j])] = 1;
			check[get<2>(test[j])] = 1;
			check[get<3>(test[j])] = 1;
		}
		for(int i = j; i < n; ++i){
			int count = 0, a[3], t[3];
			t[0] = get<1>(test[i]);
			t[1] = get<2>(test[i]);
			t[2] = get<3>(test[i]);
			//cout << t[0] << " " << t[1] << " " << t[2] << endl;
		
			for(int k = 0; k < 3; ++k){
				if(check[t[k]] != 1)
					a[count++] = t[k];
			}
			//cout << a[0] << endl;
			if(count == 1){
				check[a[0]] = 0;
			}
			else if(count == 2 || count == 3){
				for(int l = 0; l < count; ++l){
					if(check[a[l]] != 0)
						check[a[l]] = 2;
				}
			}

		}
		for(int i = 1; i <= a + b + c; ++i)
			printf("%d\n", check[i]);
	}
	return 0;
}

Measured memory_bytes: 1244
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class ConnectNodeInfo{
	vector<vector<pair<ll,ll>>> graph;
public:
	ConnectNodeInfo(int node_num){
		graph.resize(node_num);
	}
	void AddNonDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
		graph[v].emplace_back(u,w);
	}
	void AddDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
	}
	vector<pair<ll,ll>>& operator[](ll index){
		return graph[index];
	}
	size_t size(){return graph.size();}
};

class Dijkstra{
	using Point = pair<ll,ll>;
	vector<ll> dist;
public:
	void CalcShortestPath(int start,ConnectNodeInfo& connect){
		dist.resize(connect.size(),1LL<<60);
		dist[start] = 0;

		priority_queue<Point,vector<Point>,greater<Point>> Q;
		Q.emplace(0,start);
		while(!Q.empty()){
			auto p = Q.top();
			Q.pop();
			int v = p.second;
			if(dist[v]<p.first){
				continue;
			}
			for(auto e:connect[v]){
				if(dist[e.first]>dist[v]+e.second){
					dist[e.first] = dist[v]+e.second;
					Q.emplace(dist[e.first],e.first);
				}
			}
		}
	}
	ll GetDistance(int i){
		return dist[i];
	}
};

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

	int N=in(),M=in();
	ConnectNodeInfo connect(N);
	REP(i,N-1){
		connect.AddDirectionalConnection(i+1,i,0);
	}
	REP(i,M){
		int L=in()-1,R=in()-1,C=in();
		connect.AddNonDirectionalConnection(L,R,C);
	}
	Dijkstra Dij;
	Dij.CalcShortestPath(0,connect);
	auto dist = Dij.GetDistance(N-1);
	out(dist>=1LL<<60?-1:dist);
	
	return 0;
}

Measured memory_bytes: 13044
/**
 * @author Finn Lidbetter
 */
import java.util.*;
import java.io.*;
import java.awt.geom.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringBuilder sb = new StringBuilder();
    
    int n = Integer.parseInt(br.readLine());
    int min = 987654321;
    for (int i=1; i<=n/2 + 1; i++) {
      int a = i;
      int b = n-i;
      if (a<=0 || b<=0)
        continue;
      int sum = sumDigits(a)+sumDigits(b);
      if (sum<min)
        min = sum;
    }
    System.out.println(min);
  }
  static int sumDigits(int a) {
    int copy = a;
    int sum = 0;
    while (copy>0) {
      sum += copy%10;
      copy/=10;
    }
    return sum;
  }
}


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

int main(int argc, const char * argv[]) {
    
    vector<int> A(3);
    cin >> A.at(0) >> A.at(1) >> A.at(2);
    
    sort(A.begin(), A.end());
    
    cout << A.at(2) * 10 + A.at(0) + A.at(1) << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
char x[5] = {'M','A','R','C','H'};
ll cnt[5] = {0};
int main() {
    int n; cin >> n;
    vector<string> s(n);
    rep(i, n) {
        cin >> s[i];
        rep(j, 5) {
            if(s[i][0] == x[j]) {
                cnt[j]++;
            }
        }
    }
    ll ans = 0;
    for(int i=0;i<3;i++) for(int j=i+1;j<4;j++) for(int k=k=j+1;k<5;k++) {
         ans += cnt[i]*cnt[j]*cnt[k];
    }
    cout << ans;
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  ll n,ans=1;
  cin >> n;
  for (ll i=1;i<=n;i++){
    (ans*=i)%=MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);

int N, A, B, C;
vi ans;

void dfs(int i, int a, int b, int c, vi &l, int cost) {
    if (i == N) {
        if (!a || !b || !c) return;
        ans.push_back(abs(a - A) + abs(b - B) + abs(c - C) + cost);
        return;
    }
    dfs(i + 1, a, b, c, l, cost);
    dfs(i + 1, a + l.at(i), b, c, l, cost + (a ? 10 : 0));
    dfs(i + 1, a, b + l.at(i), c, l, cost + (b ? 10 : 0));
    dfs(i + 1, a, b, c + l.at(i), l, cost + (c ? 10 : 0));
}

int main() {
    cin >> N >> A >> B >> C;
    vi l(N);
    rep(i, N) { cin >> l.at(i); }
    dfs(0, 0, 0, 0, l, 0);
    cout << *min_element(all(ans)) << endl;
}


Measured memory_bytes: 3728
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <unordered_set>
// #include <prettyprint.hpp>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;++i)
#define repi(i,n) for(ll i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define slf(n) scanf("%lf", &n);
typedef long long ll;
typedef double lf;
static const ll max_n = 100010;
static const ll mod = 1000000007;
static const ll max_value = 100000000000100;
// vector<ll> height(max_n, -1);
// vector<pair<ll,ll>> edge_list(max_n);

ll N, M, Q;


void Main(){
    // bool is_ok = true;
    // printf("------------- V=%lld---------\n", V);
    ll N, M, X, c, a;
    sll(N);
    sll(M);
    sll(X);
    vector<ll> prices(N);
    vector<vector<ll>> skills(N, vector<ll>(M));
    rep(i, N){
        sll(c);
        prices[i] = c;
        rep(j, M){
            sll(a);
            skills[i][j] = a;
        }
    }

    ll min_cost = max_value;
    bool is_ok = false;
    for(ll i=0;i<(1<<N);++i){
        vector<ll> get_skills(M, 0);
        ll cost = 0;
        for(ll j=0; j<N;j++){
            if(i & (1<<j)){
                rep(k, M){
                    get_skills[k] += skills[j][k];
                }
                cost += prices[j];
            }
        }

        bool this_ok = true;
        for(auto s:get_skills){
            if(s < X){
                this_ok = false;
                break;
            }
        }

        if(this_ok){
            min_cost = min(min_cost, cost);
        }

        is_ok = (is_ok || this_ok);

    }

    if(is_ok){
        printf("%lld\n", min_cost);
    }else{
        printf("-1\n");
    }

    // printf("%lld\n", N-(ll)low_set.size());


    // cout<<fixed<<setprecision(10)<<num<<endl;
    // cout << num << endl;

}

int main(){
    Main();

    return 0;

}

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

int main(){
  int n;
  cin >> n;
  int A[3][110] = {0};
  rep(i,2){
    rep(j,n){
      cin >> A[i][j]; 
    }
  }
  rep(i,2){
    rep(j,n){
      if(i == 2 && j == 1){
        A[i][j] += A[i-1][j];
      }
      else if(i == 1 && j > 1){
        A[i][j] += A[i][j-1]; 
      }
      else{
        A[i][j] += max(A[i-1][j],A[i][j-1]);
      }
       
    }
  }
  cout << A[2][n] << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())

A = []

for i in range(N):
    A.append(int(input()))

maxA=max(A)
maxAi=A.index(maxA)

A[maxAi] = 0
maxA2 = max(A)

for i in range(N):
    if i == maxAi :
        print(maxA2)
    else :
        print(maxA)


Measured memory_bytes: 68568
#include<bits/stdc++.h>
#define int long long
#define endl "\n"
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;

const int N = 1e6+7;
int n,l;

int32_t main()
{
	fast;

	cin>>n>>l;
	int min = N;
	for(int i=1;i<=n;i++)
		if(llabs(l+i-1)<min)
			min = llabs(l+i-1);

	int sum = 0, cnt = 0;
	for(int i=1;i<=n;i++)
	{
		if(llabs(l+i-1)==min&&!cnt)
		{
			cnt++;
			continue;
		}
		sum+=(l+i-1);
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
def solve():
    from itertools import accumulate

    N, W = map(int, input().split())

    e = tuple([] for _ in range(4))
    w1, v1 = map(int, input().split())
    e[0].append(v1)

    for _ in range(N - 1):
        _w, _v = map(int, input().split())
        e[_w - w1].append(_v)

    g = [None for _ in range(4)]
    for j in range(4):
        e[j].sort(reverse=True)
        g[j] = (0,) + tuple(accumulate(e[j]))

    ret = 0
    for a in range(min(len(e[0]), N) + 1):
        for b in range(min(len(e[1]), N - a) + 1):
            for c in range(min(len(e[2]), N - a - b) + 1):
                diff = W - (w1 * a + (w1 + 1) * b + (w1 + 2) * c)
                if diff < 0:
                    break
                d = min(len(e[3]), diff // (w1 + 3))
                ret = max(ret, g[0][a] + g[1][b] + g[2][c] + g[3][d])
    return ret


print(solve())

# https://atcoder.jp/contests/arc073/submissions/2794675


Measured memory_bytes: 39920
#include<bits/stdc++.h>
using namespace std;
void dfs(vector<vector<int> > &g,vector<bool>& vis,vector<int> &dp,int node){
    vis[node]=true;

    for(int i=0;i<g[node].size();i++){
        if(!vis[g[node][i]])
            dfs(g,vis,dp,g[node][i]);
        
        dp[node]=max(dp[node],1+dp[g[node][i]]);
    }
}
int main(){
    int n,m;
    cin>>n>>m;
    vector<vector<int> > v(n+1);
    for(int i=0;i<m;i++){
        int u,w;
        cin>>u>>w;
        v[u].push_back(w);
    }

    vector<int> dp(n+1,0);
    vector<bool> vis(n+1,false);

    for(int i=1;i<=n;i++){
        if(!vis[i])
        {
            dfs(v,vis,dp,i);
        }
    }
    int maxi=-1;
    for(int i=1;i<=n;i++){
        maxi=max(dp[i],maxi);
    }
    cout<<maxi;
    return 0;
}

Measured memory_bytes: 9600
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <valarray>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <list>
#include <limits>
#include <numeric>
#include <utility>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <array>
#include <bitset>
#include <complex>
#include <tuple>
#include <random>

using namespace std;
using ll = long long;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  string g;
  int y, m, d;
  while (cin >> g >> y >> m >> d, g != "#")
  {
    if (y < 31)
      cout << g << ' ' << y << ' ' << m << ' ' << d << endl;
    else
    {
      if (y == 31 && m < 5)
        cout << g << ' ' << y << ' ' << m << ' ' << d << endl;
      else
      {
        cout << "? " << y - 30 << ' ' << m << ' ' << d << endl;
      }
    }
  }

  return 0;
}



Measured memory_bytes: 3148
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int stat=0;
    for(int i=0;i<n;i++){
        char a;
        cin>>a;
        if(a=='o') stat=0;
        else stat++;
        if(stat==2) {
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<n<<endl;
    return 0;
}


Measured memory_bytes: 3136
n = int(input())
mod = 10**9+7
ans = 1
if n == 1:
    print(1)
    exit()

pf= {}

for m in range(2,n+1):
    for i in range(2,int(m**0.5)+1):
        while m%i==0:
            pf[i]=pf.get(i,0)+1
            m//=i
    if m>1:
        pf[m]=pf.get(m,0)+1

for v in pf.values():
    ans *= v+1
    ans %= mod

print(ans)

Measured memory_bytes: 3188
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define case(i) cout<<"Case #"<<i<<": "
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 1e18;


int main() {
	int n, k; cin >> n >> k;
	vector<int> a(n);
	rep(i, 0, n) cin >> a[i];
	vector<vector<int>> dp(n + 1);
	rep(i, 0, n + 1) dp[i].resize(k + 2, 0);
	dp[0][0] = 1;
	rep(i, 1, n + 1) {
		int sum[100010]; sum[0] = 0;
		rep(j, 1, k + 2) sum[j] = (sum[j - 1] + dp[i - 1][j - 1]) % mod;
		rep(j, 0, k + 1) {
			dp[i][j] = (sum[j + 1] - sum[max(0, j - a[i - 1])] + mod) % mod;
		}
	}
	cout << dp[n][k] << endl;
	return 0;
}

Measured memory_bytes: 40192
N,M = map(int,input().split())
A= list(map(int,input().split()))
BC=[list(map(int,input().split())) for _ in range(M)]
A.sort()
#print(A)
BC.sort(key=lambda x:-x[1])
#print(BC)
i = 0
for B,C in BC:
    for j in range(i,min(N,i+B)):
        if A[j]<C:A[j]=C
    i = i+B
print(sum(A))


Measured memory_bytes: 36076
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;

int main() {
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	if (h < a || w < b) {
		cout << h * w << endl;
		return 0;
	}

	int x = (h % a)* w + (w % b) * h - (h % a) * (w % b);

	cout << x << endl;
}




Measured memory_bytes: 3104
#include<stdio.h>
#include<string>
#include<algorithm>
#include<iostream>
#include<queue>
#include<math.h>
char nh[2005][2005];
using namespace std;
int n,m;
int dfs(int x,int y)
{
    int sum=1;
    if(x+1<n)
    {
        for(int i=x+1; i<n; i++)
        {
            if(nh[i][y]=='.') sum++;
            else break;
        }
    }
    if(x-1>=0)
    {
        for(int i=x-1; i>=0; i--)
        {
            if(nh[i][y]=='.') sum++;
            else break;
        }
    }
    if(y+1<m)
    {
        for(int i=y+1; i<m; i++)
        {
            if(nh[x][i]=='.') sum++;
            else break;
        }
    }
    if(y-1>=0)
    {
        for(int i=y-1; i>=0; i--)
        {
            if(nh[x][i]=='.') sum++;
            else break;
        }
    }
    return sum;

}
int main()
{
    int maxx=0;
    scanf("%d%d",&n,&m);
    for(int i=0; i<n; i++)
    {
        scanf("%s",nh[i]);
    }
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<m; j++)
        {
            if(nh[i][j]=='.')
            {
                if(dfs(i,j)>maxx)
                    maxx=dfs(i,j);
                    if(maxx==n+m-1) break;
            }
        }
    }
    printf("%d\n",maxx);
}


Measured memory_bytes: 4224
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
int main(){
	ll m,k;
	cin>>m>>k;
	if(m==1&&k==0){
		//まさかのサンプルがコーナー
		cout<<0<<" "<<0<<" "<<1<<" "<<1<<"\n";
		return 0;
	}
	ll d=0;
	deque<ll> deq;
	if(k!=0){
	for(int i=0;i<(1<<m);i++){
		if(i==k)continue;
		d^=i;
	}
	if(d!=k){
		cout<<-1<<"\n";
		return 0;
	}
	}
	deq.push_back(k);
	for(int i=0;i<(1<<m);i++){
		if(i==k)continue;
		deq.push_front(i);
		deq.push_back(i);
	}
	deq.push_back(k);
	while(deq.size()){
		cout<<deq.front()<<(deq.size()==1?"\n":" ");
		deq.pop_front();
	}

}

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

const int MAX_N = 410;
const int MAX_X = 3e5+10;
const int MOD = 1e9+7;

int dp[MAX_N][MAX_X];
// i番目までで先頭の値がjの時の総和をdp[i][j]をおく

void modadd(int &a, int b ){ 
  a = (a+b)%MOD;
}

signed main(void){ 
  
  int N,X; cin >> N >> X;
  vector<int> s(N);
  map<int,int> mp;
  for(int i = 0; i < N; i++){ cin >> s[i]; }
  
  sort(s.begin(),s.end());
                             
  for(int i = 0; i < MAX_X; i++){ dp[0][i] = i;}  
                            
  
  for(int i = 0; i < N; i++){
    // 次にi+1コメを見る
    for(int x = 0; x < MAX_X; x++){ //先頭の文字全体を探索する
      //未更新から飛ばさない方がいい？
      modadd(dp[i+1][x],dp[i][x%s[i]]);
      modadd(dp[i+1][x],dp[i][x]*i);
    }
  }
      
                     
  cout << dp[N][X] << endl;
  
  return 0;
}
  

Measured memory_bytes: 473344
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};
use std::collections::{VecDeque, HashSet};

fn main() {
    input!{
        n: usize,
        m: usize,
        es: [(usize1, usize1); m]
    }
    let mut g = vec![vec![]; n];
    for &(a, b) in &es {
        g[a].push(b);
    }
    let mut ans = vec![];
    for i in 0..n {
        if let Some(p) = bfs(i, &g) {
            if ans.len() == 0 || ans.len() > p.len() {
                ans = p;
            }
        }
    }
    if ans.len() > 0 {
        println!("{}", ans.len());
        for &v in &ans {
            println!("{}", v + 1);
        }
    } else {
        println!("-1");
    }
}

fn bfs(r: usize, g: &Vec<Vec<usize>>) -> Option<Vec<usize>> {
    let n = g.len();
    let mut q = VecDeque::new();
    let mut prev = vec![n; n];
    q.push_back(r);
    while let Some(s) = q.pop_front() {
        for &t in &g[s] {
            if t == r {
                let mut ret = vec![s];
                let mut v = s;
                while v != r {
                    v = prev[v];
                    ret.push(v);
                }
                return Some(ret);
            }
            if prev[t] < n {
                continue;
            }
            prev[t] = s;
            q.push_back(t);
        }
    }
    return None;
}


Measured memory_bytes: 4352
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val s = sc.next()
    println(problem146a(s))
}

fun problem146a(s: String): Int {
    return when(s) {
        "SUN" -> 7
        "MON" -> 6
        "TUE" -> 5
        "WED" -> 4
        "THU" -> 3
        "FRI" -> 2
        "SAT" -> 1
        else -> 0
    }
}

Measured memory_bytes: 29600
using System;
using System.Collections.Generic;

class Program
{
    public static void Main(string[] args)
    {
        Program pg = new Program();
        pg.Exe();
    }
    public void Exe()
    {
        int[] input_ary = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        int human_num = input_ary[0];
        int sweets_num = input_ary[1];

        List<int> sweets_list = new List<int>(human_num);
        for(int i = 0; i < human_num; i++)
        {
            sweets_list.Add(0);
        }
        int n = 0;
        int[] ary;
        for(int i = 0; i < sweets_num; i++)
        {
            n = int.Parse(Console.ReadLine());
            ary = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            foreach(int k in ary)
            {
                sweets_list[k-1] += 1;
            }
        }
        int ans = 0;
        foreach(int k in sweets_list)
        {
            if(k == 0) ans++;
        }
        Console.WriteLine(ans);
    }
}



Measured memory_bytes: 28004
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	 
    static long solve(long arr[],int i,int j,long dp[][]){
        
        if(i>j){
            return 0;
        }
        if(i==j){
            return arr[i];
        }
        if(dp[i][j]!=0){
            return dp[i][j];
        }
        
        long op1=arr[i]+Math.min(solve(arr,i+2,j,dp),solve(arr,i+1,j-1,dp));
        
        long op2=arr[j]+Math.min(solve(arr,i,j-2,dp),solve(arr,i+1,j-1,dp));
    
        
        return dp[i][j]= Math.max(op1,op2);
        
    }
	
	
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner s=new Scanner(System.in);
	 int n=s.nextInt();
		    long arr[]=new long[n];
		    long sum=0;
		    for(int i=0;i<n;i++){
		        arr[i]=s.nextLong();
		  
		  sum+=arr[i];  }
		    long dp[][]=new long[3005][3005];
		  long m= solve(arr,0,n-1,dp);
	long qw=sum-m;
	long ee=m-qw;
	System.out.println(ee);
	}
}


Measured memory_bytes: 129784