akhauriyash/Code-Regression huggingface dataset:
import java.util.Iterator;
import java.util.PrimitiveIterator;
import java.util.Scanner;
import java.util.function.Supplier;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Main{
	static Scanner s=new Scanner(System.in);


	static final int[] dx={0,1,0,-1},dy={1,0,-1,0};
	void solve(){
		int h=gInt(),w=gInt();
		char[][] f=new char[h][w];
		for(int i=0;i<h;++i)
			s.next().getChars(0,w,f[i],0);
		for(int i:rep(h)){
			loop:
			for(int j:rep(w)){
				if(f[i][j]=='#'){
					for(int d:rep(4)){
						int I=i+dy[d];
						int J=j+dx[d];
						if(0<=I&&I<h&&0<=J&&J<w&&f[I][J]=='#')
							continue loop;
					}
					System.out.println("No");
					return;
				}
			}
		}
		System.out.println("Yes");
	}
	public static void main(String[] A){
		new Main().solve();
	}

	static int gInt(){
		return Integer.parseInt(s.next());
	}
	static long gLong(){
		return Long.parseLong(s.next());
	}
	static double gDouble(){
		return Double.parseDouble(s.next());
	}

	SupplyingIterator<Integer> ints(int n){
		return new SupplyingIterator<>(n,Main::gInt);
	}
	SupplyingIterator<Long> longs(int n){
		return new SupplyingIterator<>(n,Main::gLong);
	}
	SupplyingIterator<Double> doubles(int n){
		return new SupplyingIterator<>(n,Main::gDouble);
	}
	SupplyingIterator<String> strs(int n){
		return new SupplyingIterator<>(n,s::next);
	}

	Range rep(int i){
		return Range.rep(i);
	}
	Range rep(int f,int t,int d){
		return Range.rep(f,t,d);
	}
	Range rep(int f,int t){
		return rep(f,t,1);
	}
	Range rrep(int f,int t){
		return rep(t,f,-1);
	}

	IntStream REP(int v){
		return IntStream.range(0,v);
	}
	IntStream REP(int l,int r){
		return IntStream.rangeClosed(l,r);
	}

	IntStream INTS(int n){
		return IntStream.generate(Main::gInt).limit(n);
	}
	Stream<String> STRS(int n){
		return Stream.generate(s::next).limit(n);
	}

}
class SupplyingIterator<T> implements Iterable<T>,Iterator<T>{
	int			t;
	Supplier<T>	supplier;

	SupplyingIterator(int t,Supplier<T> supplier){
		this.t=t;
		this.supplier=supplier;
	}

	@Override
	public Iterator<T> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return t>0;
	}

	@Override
	public T next(){
		--t;
		return supplier.get();
	}

}
class Range implements Iterable<Integer>,PrimitiveIterator.OfInt{
	int to,cur,d;

	Range(int from,int to,int d){
		this.cur=from-d;
		this.to=to;
		this.d=d;
	}

	Range(int n){
		this(0,n-1,1);
	}

	@Override
	public Iterator<Integer> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return cur+d==to||(cur!=to&&(cur<to==cur+d<to));
	}

	@Override
	public int nextInt(){
		return cur+=d;
	}

	static Range rep(int i){
		return new Range(i);
	}
	static Range rep(int f,int t,int d){
		return new Range(f,t,d);
	}
	static Range rep(int f,int t){
		return rep(f,t,1);
	}
	static Range rrep(int f,int t){
		return rep(f,t,-1);
	}

}


Measured memory_bytes: 28500
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;


class Program {
    

    internal static void Main(string[] args)
    {

        int N = int.Parse(ReadLine());
        int[] X = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var sortX = new int[X.Length];
        Array.Copy(X, sortX, X.Length);
        Array.Sort(sortX);
        int a = sortX[(X.Length / 2) - 1];
        int b = sortX[X.Length / 2];

        for (int i = 0; i < N; i++) {
            if (X[i] <= a) {
                WriteLine(b);
            } else {
                WriteLine(a);
            }
        }

    }
}

Measured memory_bytes: 36680
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;



int main() {
  int n;
  scanf("%d", &n);
  vector<int> in(n);
  for(int i = 0; i < n; ++i) {
    scanf("%d", &in[i]);
    --in[i];
  }
  vector<int> ans(n, -1);
  for(int i = n - 1; i >= 0; --i) {
    int x = in[i];
    int position = x;
    for(int j = 0; j <= position && j < n; ++j) {
      if(ans[j] != -1) {
        ++position;
      }
    }
    if(position >= n || ans[position] != -1) {
      puts("-1");
      return 0;
    }
    ans[position] = x;
  }
  for(int x : ans) {
    printf("%d\n", x + 1);
  }
}


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

int main()
{
    int n, m, l;
    cin >> n >> m >> l;
    long long a[n][m], b[m][l], c[n][l] = {};
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < m; i++)
    {
        for (int j = 0; j < l; j++)
        {
            cin >> b[i][j];
        }
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < l; j++)
        {
            for (int k = 0; k < m; k++)
            {
                c[i][j] += a[i][k] * b[k][j];
            }
            if (j == l - 1)
            {
                cout << c[i][j];
            }
            else
            {
                cout << c[i][j] << " ";
            }
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3344
#include <stdio.h>

int main(void)
{
    int a, b, i;

    scanf("%d %d" ,&a, &b);

    if (a < b)
        for (i = 1; i <= b; i++)
            printf("%d" ,a);
    else
        for (i = 1; i <= a; i++)
            printf("%d" ,b);
    return 0;
}


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

// 插入此處

int main() {
    LL x, y;
    cin >> x >> y;
    if (abs(x - y) <= 1) {
        printf("Brown\n");
    } else {
        printf("Alice\n");
    }
}


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

int main() {
  long long n,t;
  cin>>n>>t;
  vector<long long>a(n);
  for(int i=0;i<n;i++) cin>>a[i];
  long long ans=t;
  for(int i=0;i<n-1;i++){
    if(a[i+1]-a[i]>t) ans+=t;
    else ans+=a[i+1]-a[i];
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  string s;
  cin >> s;
  
  int ans = 0;
  int cnt = 0;
  for (int i=0; i<N; i++) {
    if (s[i] == 'I') {
      cnt++;
    }
    else {
      cnt--;
    }
    ans = max(ans,cnt);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
int fr[3];

int main(){
  char ch;
  int i;
  for(i = 0; i < 3; i++){
    ch = fgetc(stdin);
    fr[ch - 'a']++;
  }
  for(i = 0; i < 3; i++){
    if(fr[i] != 1){
      printf("No");return 0;
    }
  }
  printf("Yes"); return 0;
}


Measured memory_bytes: 128
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {

            var (a, b) = Slice2<long>();
            var n = b - a - 1;
            WriteLine(n * (n + 1) / 2 - a);
        }

        static long Mod = 998244353;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

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

// ACをまとめて扱うと，「TTTA|CTTACTT|TTTT」みたいな文字列で答えが合わないので
// 「右隣にCがあるようなA」の個数をカウントすると問題を読み替える
// さらに「TTACTTA|C」みたいな右端のAの右隣にCがあるようなときのAを除外するために区間[l,r)を考える

int main() {
    int N, Q; cin >> N >> Q;
    string str; cin >> str;

    vector<int> s(N+1, 0); // s[i]: i文字目までに存在する「右隣にCがあるようなA」の個数
    for (int i = 0; i < N; i++) {
        if (i+1 < N && str[i] == 'A' && str[i+1] == 'C') {
            s[i+1] = s[i] + 1;
        } else {
            s[i+1] = s[i];
        }
    }
    for (int q = 0; q < Q; q++) {
        int l, r; cin >> l >> r;
        l--; r--;
        cout << s[r] - s[l] << endl;
    }
    return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    int ans=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]!=t[i])
        ans++;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3916
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=9e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int main(){cout<<fixed<<setprecision(20);
           int n,m;
           cin>>n>>m;
           vin a(n),b(n);
           vin c(m),d(m);
           rep(i,0,n)cin>>a[i]>>b[i];
           rep(i,0,m)cin>>c[i]>>d[i];
           rep(i,0,n){
            int ans=0;
             int cnt=inf;
             rep(j,0,m){
               if(chmin(cnt,abs(a[i]-c[j])+abs(b[i]-d[j]))){
                 ans=j+1;
               }
             }
                     cout<<ans<<endl;
           }
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mod 1000000007
// order_of_key and *find_by_order
int32_t main()
{
	fast;
	string s, t;
	cin >> s >> t;
	if (s.length() != t.length() - 1) {
		cout << "No";
		return 0;
	}
	if (s == t.substr(0, s.length())) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}











}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
#include <math.h>
#include <time.h>
using namespace std;
const long long mod = 1000000007;
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
bool dbg = false;
long long gcd(long long a, long long b){
   if (a % b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a % b));
   }
}
long long lcm(long long a, long long b){
   return (a / gcd(a, b))* b;
}
//---------------------------------------------------------------------------------------------------
/*ここからいじる*/
//---------------------------------------------------------------------------------------------------

void solve(){
}
int main(){
    int n;
    cin >> n;
    vector<string> data(n);
    map<string, int>cnt;
    for(int i = 0; i < n; i++){
        cin >> data.at(i);
    }
    for(int i = 0; i < n; i++){
        if(cnt.count(data.at(i))){
            cnt.at(data.at(i))++;
        }
        else{
            cnt[data.at(i)] = 1;
        }
    }
    int tmpmax = 0;
    for (auto p : cnt){
    string key = p.first;
    int value = p.second;
    tmpmax = max(tmpmax, p.second);
  // key, valueを使う
}
    for (auto p : cnt){
    string key = p.first;
    int value = p.second;
    if(value == tmpmax){
        cout << key << endl;
    }
  // key, valueを使う
}

    return 0;
}



Measured memory_bytes: 26752
#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";

pii f(pii a, pii b){
    int p[] = {a.first, a.second, b.first, b.second};
    sort(p, p+4, greater<int>());
    return pii(p[0], p[1]);
}

int main(){
    int N;
    cin >> N;
    int A[1<<N];
    pii dp[1<<N];
    rep(i, (1<<N)){
        cin >> A[i];
        dp[i] = pii(A[i], 0);
    }
    rep(j, N){
        rep3(i, (1<<N)-1, 0){
            if(i & (1<<j)){
                //i & ~(1<<j) = iの下からjビット目を0にしたもの
                dp[i] = f(dp[i], dp[i & ~(1<<j)]);
            }
        }
    }
    int now = 0;
    rep2(i, 1, (1<<N)-1){
        now = max(now, dp[i].first + dp[i].second);
        cout << now << endl;
    }
}

Measured memory_bytes: 6144
#include "bits/stdc++.h"
using namespace std;
int dp[2019][2];
signed main()
{
	string s;
	cin >> s;
	int ans = 0;
	for(int i = 0; i < s.size(); ++i)
	{
		for(int j = 0; j < 2019; ++j)
		{
			dp[(j * 10 + s[i] - '0') % 2019][i % 2] += dp[j][!(i % 2)];
			dp[j][!(i % 2)] = 0;
		}
		++dp[s[i] - '0'][i % 2];
		ans += dp[0][(i % 2)];
	}
	cout << ans << "\n";
}

Measured memory_bytes: 3728
import sys


def input():
    return sys.stdin.readline()[:-1]


def main():
    m, d = map(int, input().split())
    ans = 0
    for i in range(1, m+1):
        for k in range(1, d+1):
            if k >= 22 and int(str(k)[1]) >= 2:
                if i == int(str(k)[0])*int(str(k)[1]):
                    ans += 1
                    # print(i, k)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 39408
#include<stdio.h>
int main()
{

    int n,a=0,i;
    float ans;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        if(i%2!=0)
        {
            a++;
        }
    }
    ans = (float)a/n;
    printf("%f",ans);
}


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

public class BinarySearch{
	public static void Main()
	{
		Console.ReadLine();
		var sList = ReadLineAndToIntList();
		Console.ReadLine();
		var tList = ReadLineAndToIntList();
	
		int count = 0;
	
		foreach (int t in tList)
		{
			if(sList.BinarySearch(t) > -1) count++;
		}
		
		Console.WriteLine(count);
	}
	
	//??????????????????????????????
	public static List<int> ReadLineAndToIntList()
	{
		return Console.ReadLine().Split().Select (c => int.Parse(c)).ToList();
	}
}

Measured memory_bytes: 15672
# coding: utf-8
import sys


def main(argv=sys.argv):

    actual_stay = int(input())

    init_stay = int(input())

    init_charge = int(input())

    extra_charge = int(input())

    total_charge = 0

    if actual_stay > init_stay:

        total_charge = init_stay * init_charge + \
                       (actual_stay - init_stay) * extra_charge

    else:

        total_charge = actual_stay * init_charge

    print(total_charge)

    return 0


if __name__ == '__main__':
    sys.exit(main())


Measured memory_bytes: 3060
open Batteries
open Printf
let () =
  let n = Scanf.scanf "%d " (fun a -> a) in
  let s_lst = Array.to_list @@ Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in

  let l = List.sort compare s_lst in
  let max_ans = List.fold_left (+) 0 s_lst in
  
  let ans = 
  if max_ans mod 10 <> 0 then max_ans else
  try
  let tmp = List.find (fun x -> x mod 10 <> 0) l in
  max_ans - tmp
  with _ -> 0
  in
  Printf.printf "%d\n" ans


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

using namespace std;

int main(){
  int n;
  string s;
  cin >> n >> s;
  int pos=0,count=0;
  while(pos != string::npos){
    pos = s.find("ABC");
    if(pos != string::npos){
      s = s.substr(pos+3);
      count++;
    }
  }

  cout << count << endl;
}


Measured memory_bytes: 3632
/*
				GAURAV KUMAR
				 MNNIT
				  BTECH 3RD YEAR
*/

#include<bits/stdc++.h>
using namespace std;
#define debug1(x) cout << # x << " " << x << endl;
#define debug2(x,y) cout << #x << " " << x << " " << #y << " " << y << endl;
#define debug3(x,y,z) cout << #x << " " << x << " " << #y << " " << y << " " << #z << " " << z << endl;
typedef long long int ll;
const ll INF=1e12;
ll dp[3001][3001][2];
ll dp1[3001][3001][2];
ll a[3001];
ll fun(int i,int j,int t)
{
	if(i==j)
	{
		if(t==0)return a[i];
		return -a[i];
	}
	ll ans;
	if(dp1[i][j][t]!=0)return dp[i][j][t];
	if(t==0)
	{
		ans=fun(i+1,j,1-t)+a[i];
		ans=max(ans,fun(i,j-1,1-t)+a[j]);
	}
	else
	{
		ans=fun(i+1,j,1-t)-a[i];
		ans=min(ans,fun(i,j-1,1-t)-a[j]);
	}
	dp1[i][j][t]=1;
	return dp[i][j][t]=ans;



}

int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	cout<<fun(0,n-1,0)<<endl;
}

Measured memory_bytes: 281088
import sys


def main():
    args = sys.stdin.readline().split()
    N = int(args[0])
    A = map(int, input().split())

    non_factor_cnt = 0
    factor_of_two_cnt = 0
    factor_of_four_cnt = 0
    for num in A:
        remainder = num % 4
        if remainder != 0:
            if remainder == 2:
                factor_of_two_cnt += 1
            else:
                non_factor_cnt += 1
        else:
            factor_of_four_cnt += 1

    if factor_of_two_cnt == 0:
        if factor_of_four_cnt >= non_factor_cnt - 1:
            print('Yes')
            sys.exit()
    if factor_of_four_cnt >= non_factor_cnt: # + factor_of_two_cnt % 2:
        print('Yes')
        sys.exit()
    print('No')

main()

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

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    stack<int> st;
    for(int i = 0; i < n; i++){
        cin>>a[i];
    }
    st.push(a[0]);
    for(int i = 1; i < n; i++){
        if(st.top() >= a[i]){
            st.push(a[i]);
        }
    }
    int res = st.size();
    cout<<res<<endl;
    return 0;
}

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

using namespace std;

int N;
int a[100005], b[100005];

vector<int> Adj[100005];

int dis_F[100005], dis_S[100005];

void visit_F(int K, int d) {

	dis_F[K] = d; //cout << "訪問 " << K << endl;

	for (int m = 0; m < (int)Adj[K].size(); m++) {
		int M = Adj[K][m];
		if (/* M != N && */ dis_F[M] < 0) { visit_F(M, d + 1); }
	}

};

void visit_S(int K, int d) {

	dis_S[K] = d; //cout << "訪問 " << K << endl;

	for (int m = 0; m < (int)Adj[K].size(); m++) {
		int M = Adj[K][m];
		if (/* M != N && */ dis_S[M] < 0) { visit_S(M, d + 1); }
	}

};

int main(void) {

	cin >> N;
	int tmp;
	for (int i = 1; i <= N-1; i++) {
		cin >> tmp; a[i] = tmp;
		cin >> tmp; b[i] = tmp;
	}
	//===============================
	for (int i = 1; i <= N - 1; i++) {
		Adj[a[i]].push_back(b[i]);
		Adj[b[i]].push_back(a[i]);
	}

	for (int i = 1; i <= N; i++) { dis_F[i] = -1; dis_S[i] = -1; }

	//cout << "check" << endl;
	visit_F(1, 0);
	visit_S(N, 0);

	for (int i = 1; i <= N; i++) {
	//cout<< i << " " << dis_F[i]<<" " <<dis_S[i] << endl;
	}

	int N_F=0, N_S;

	for (int i = 1; i <= N; i++) {
		if (dis_F[i] <= dis_S[i]) { N_F++; }
	}
	N_S = N - N_F;

	//cout << "N_F= " << N_F << endl;
	//cout << "N_S= " << N_S << endl;

	if (N_F > N_S) { cout << "Fennec" << endl; }
	else { cout << "Snuke" << endl; }

	//system("pause");
	return 0;
}

Measured memory_bytes: 11904
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int a = scan.nextInt();
    int b = scan.nextInt();

    int c = a*(a-1)/2;
    int d = b*(b-1)/2;

    System.out.println(c+d);
  }
}


Measured memory_bytes: 35900
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    ll x,k,d;
    cin>>x>>k>>d;
    if(llabs(x)/d>k){
        ll ans=llabs(llabs(x)-k*d);
        cout<<ans<<endl;
    }else{
        ll dis=llabs(x)%d;
        ll dis2=llabs(dis-d);
        ll num=llabs(x)/d;
        //cout<<dis<<" "<<dis2<<endl;
        if((num%2==1 && k%2==0) || (num%2==0 && k%2==1)){
            cout<<dis2<<endl;
        }else{
            cout<<dis<<endl;
        }
    }
}

Measured memory_bytes: 3592
import glob
import os

bn = os.path.basename(__file__).split('.')[0]
dn = os.path.dirname(__file__).split('/')

# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = dn[len(dn)-2] + '\\' + dn[len(dn)-1] + '\\' + bn

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'

class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class Solver(Common):

    alph = []

    def rec(self, result, now, max, N):

        if now == N:
            res = ""
            for i in result:
                res += self.alph[i]
            print(res)
            return

        if now == 0:
            result[0] = 0
            self.rec(result, now+1, 0, N)
            return

        for i in range(0, max+2):
            if i == N:
                return
            result[now] = i
            if i > max:
                self.rec(result, now+1, i, N)
            else:
                self.rec(result, now+1, max, N)

    def resolve(self):

        N, K = map(int, self.input_data().split())
        A = list(map(int, self.input_data().split()))
        A.insert(0, 0)
        town_visit_time = [-1]*(N+1)

        num_loop = 0
        loop_start_count = 0
        loop_start_town = 0

        next_town = 1
        for i in range(0,N+1):
            if town_visit_time[next_town] != -1:
                num_loop = i - town_visit_time[next_town]
                loop_start_count = town_visit_time[next_town]
                loop_start_town = next_town
                break

            town_visit_time[next_town] = i
            next_town = A[next_town]

            if i+1 == K:
                print(str(next_town))
                exit(0)

        remain = (K - loop_start_count) % num_loop

        result =  loop_start_town
        for i in range(remain):
            result = A[result]

        print(str(result))

solver = Solver(REL_PATH)
solver.exec_resolve()


Measured memory_bytes: 33988
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1000000007;
#define rep(i,n) for(long long i=0;i<(n);i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back



ll gcd(ll a , ll b){
    ll bigger=max(a,b);
    ll smaller=min(a,b);
    if (bigger%smaller==0){
        return smaller;
    }
    else {
        return gcd(smaller, bigger%smaller);
    }

}






int main(){

    string s,t;
    cin>>s>>t;

    int n;
    n=int(s.size());

    int answer=0;

    rep(i,n){
        if (s.at(i)!=t.at(i)){
            answer++;
        }
    }

    cout<<answer<<endl;











}

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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}

int main(){
ll K, A, B;
cin >> K >> A >> B;
if(K == 1){
  print(2);
  return 0;
}


if(B - A <= 2 || K < A + 1){
  print(1 + K);
  return 0;
}

ll x = (K - (A - 1)) / 2;
ll ans = A + (B - A) * x;
if((K - (A - 1)) % 2 == 1) ans++;
print(ans);

}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input = br.readLine();
        String[] s = input.split(" ");
        int width = Integer.parseInt(s[0]);
        int height = Integer.parseInt(s[1]);
        int perimeter = (width + height) * 2;
        int square = width * height;
        System.out.println(square + " " + perimeter);
    }
}

Measured memory_bytes: 24080
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define rFORe(i, a, n) for(int (i) = (int)(n); (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 1, (n))
#define REPo(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rREPe(i, n) rFORe((i), 1, (n))
#define rREPo(i, n) rFORe((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;

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

int main() {
  int n, m;
  cin >> n >> m;
  vi a(m);
  REP(i, m) cin >> a[i];
  REP(i, m) n -= a[i];
  if(n < 0) n = -1;
  cout << n << endl;

  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;
 
#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 REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())

typedef long long ll;

int N,C;
int s[100010];
int t[100010];
int c[100010];

int acc[200010];
int line[30][200010];

int main() {

	cin >> N >> C;
	REP(i,N) cin >> s[i] >> t[i] >> c[i];
	REP(i,N) {
		s[i] *= 2;
		t[i] *= 2;
	}

	REP(i,N) {
		line[c[i] - 1][s[i]]++;
		line[c[i] - 1][t[i]]--;
	}

	REP(i,C) REP(j,200005) {
		line[i][j + 1] = line[i][j] + line[i][j + 1];
	}

	vector < pair < int,int> > range;
	REP(i,C) {
		stack < int > pos;
		REP(j,200005) {
			if (line[i][j] == 0 && line[i][j + 1] == 1) {
				pos.push(j);
			} else if (line[i][j] == 1 && line[i][j + 1] == 0) {
				range.push_back(make_pair(pos.top(), j));
				pos.pop();
			}
		}
	}

	REP(i,range.size()) {
		acc[range[i].first - 1]++;
		acc[range[i].second]--;
	}

	REP(i,200006) acc[i + 1] = acc[i + 1] + acc[i];

	int ans = 0;
	REP(i,200006) ans = max(ans, acc[i]);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 26744
#include <bits/stdc++.h>
using namespace std;
template<class C>constexpr int sz(const C&c){return int(c.size());}
using ll=long long;constexpr const char nl='\n',sp=' ';

int main() {
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  // freopen("err.txt", "w", stderr);
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int H, W;
  cin >> H >> W;
  map<int, int> S, freq;
  for (int i = 0; i < W; i++) {
    S[i] = i;
    freq[0]++;
  }
  for (int i = 0; i < H; i++) {
    int A, B;
    cin >> A >> B;
    --A; --B;
    int mx = -1;
    while (true) {
      auto it = S.upper_bound(B);
      if (it == S.begin()) break;
      --it;
      if (it->first < A) break;
      mx = max(mx, it->second);
      if (--freq[it->first - it->second] == 0) freq.erase(it->first - it->second);
      S.erase(it);
    }
    if (mx != -1 && B + 1 != W) {
      if (S.count(B + 1)) {
        if (--freq[B + 1 - S[B + 1]] == 0) freq.erase(B + 1 - S[B + 1]);
        S[B + 1] = max(S[B + 1], mx);
      } else S[B + 1] = mx;
      freq[B + 1 - S[B + 1]]++;
    }
    if (freq.empty()) cout << -1 << nl;
    else cout << (i + 1) + freq.begin()->first << nl;
  }
  return 0;
}


Measured memory_bytes: 12952
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
a, b = map(int, input().split())
if (a*b) % 2 == 0:
    print('Even')
else:
    print('Odd')


Measured memory_bytes: 60012
from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
#from functools import lru_cache   #use @lru_cache(None)
if os.path.exists('in.txt'): sys.stdin=open('in.txt','r')
if os.path.exists('out.txt'): sys.stdout=open('out.txt', 'w')
#
def input(): return sys.stdin.readline()
def mapi(arg=0): return map(int if arg==0 else str,input().split())
#------------------------------------------------------------------


n = int(input())
a = list(mapi())
b = a[:]
for i in range(n-2,-1,-1):
    b[i] += b[i+1]
res = 0
mod =  int(1e9+7)
for i in range(n-1):
    res = (res+a[i]*b[i+1]%mod)%mod
print(res)


Measured memory_bytes: 33912
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int w[1000005],i,j,k,num;
char s[1000005];
int main()
{
	scanf("%s",s);
	j=strlen(s);
	for(i=0;i<j;++i)
		w[i]=(s[j-i-1]-'0')*9;
	for(i=0;i<=500100;++i)
	{
		w[i+1]+=w[i]/10;
		w[i]%=10;
		num+=w[i];
	}
	for(k=1;;++k)
	{
		num-=w[0];
		w[0]+=9;
		for(i=0;w[i]>9;++i)
		{
			num-=w[i+1];
			w[i+1]+=w[i]/10;
			w[i]%=10;
			num+=w[i];
		}
		num+=w[i];
		if(num<=9*k)
		{
			printf("%d",k);
			return 0;
		}
	}
	return 0;
}


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

int main(){
  int N,K; cin >> N >> K;
  int A[N];
  for(int i=0; i<N; i++){cin >> A[i];}
  sort(A,A+N);
  
  vector<int> V; int c=1;
  for(int i=0; i<N-1; i++){
    if(A[i]==A[i+1]){c++;}
    else{V.push_back(c); c=1;}
  }
  V.push_back(c);
  
  if(V.size()<=K){cout << 0;}
  else{
    int s=0; sort(V.begin(), V.end());
    for(int i=0; i<V.size()-K; i++){s = s+V[i];}
   	cout << s;
  }
  
  return 0;
}

Measured memory_bytes: 2168
#include <cstdio>
#include <vector>

using namespace std;

int main() {
    size_t r, c;
    scanf("%zu %zu", &r, &c);

    vector<vector<int>> a(r+1, vector<int>(c+1));
    for (size_t i=0; i<r; ++i) {
        for (size_t j=0; j<c; ++j) {
            scanf("%d", &a[i][j]);
            printf("%d ", a[i][j]);

            a[r][j] += a[i][j];
            a[i][c] += a[i][j];
        }
        printf("%d\n", a[i][c]);
    }

    for (size_t j=0; j<c; ++j) {
        printf("%d ", a[r][j]);
        a[r][c] += a[r][j];
    }

    printf("%d\n", a[r][c]);
    return 0;
}

Measured memory_bytes: 2660
I,O,T,J,L,S,Z=map(int,input().split())
AI=(I//2)*4
AO=O*2
AJ=(J//2)*4
AL=(L//2)*4
OI=I%2
OJ=J%2
OL=L%2
if min(I,J,L)==0:
    print((AI+AO+AJ+AL)//2)
elif (OI+OJ+OL)==3:
    print((AI+AO+AJ+AL)//2+3)
elif (OI+OJ+OL)<=1:
    print((AI+AO+AJ+AL)//2)
else:
    print((AI+AO+AJ+AL)//2+1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long H, W;
  cin >> H >> W;
 
  if (H==1) {
    cout << 1 << endl;
  }
  else if (W==1) {
    cout << 1 << endl;
  }
    
  else if (H*W%2==0) {
    cout << (H*W)/2 << endl;
  }
 
  else if (H*W%2==1) {
    cout << (H*W)/2+1 << endl;
  } 
}

Measured memory_bytes: 256
import java.io.*;
  
class Main{
	public static void main(String[] args) throws IOException{

		int x,y,z;
		int count = 0;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str[] = br.readLine().split(" ");
		x = Integer.parseInt(str[0]);
		y = Integer.parseInt(str[1]);
		z = Integer.parseInt(str[2]);

		for(int i=x; i<=y; i++){
			if(z%i == 0){
				count++;
			}
		}
		System.out.println(count);
    	}
}

Measured memory_bytes: 16952
x, y, z = gets.chomp.split.map(&:to_i)

def swap1(x, y, z)
  [y, x, z]
end

def swap2(x, y, z)
  [z, y, x]
end


x, y, z = swap1(x, y, z)

x, y, z = swap2(x, y, z)

puts "#{x} #{y} #{z}"


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

using namespace std;

#define ll long long 

void chmax (ll& a, ll b) {
  if (a < b) a = b;
}  


int main() {
  ll N, W;
  cin >> N >> W;
  
  ll w[N+1] = {0};
  ll v[N+1] = {0};
  
  for (int i = 0; i < N; i++)  cin >> w[i+1] >> v[i+1];
  
  ll dp[N+1][W+1] = {0}; // dp[i][j] i番目までの商品で，合計j[g]のときの価値の最大値
  for (int i = 0; i < W+1; i++) {
    dp[0][i] = 0;
  }
  

  for (ll i = 0; i < N; i++) {
    for (ll j = 0; j < W; j++) {
      if (j + w[i+1] <= W) {
        chmax(dp[i+1][j + w[i+1]], dp[i][j] + v[i+1]);
      } 
      chmax(dp[i+1][j], dp[i][j]);
    }
  }
  ll ans = 0;
  
  for (int i = 1; i <= W; i++) {
    if (ans < dp[N][i]) ans = dp[N][i];
  }
  
  cout << ans << endl;
  
              
}



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

int main() {

    string str;
    int n,i,sum=0;
    long long int tot=0;
    cin>>n;
    vector<string> vect;
    for(i=0;i<n;i++){
        cin>>str;
        sort(str.begin(),str.end());
        vect.push_back(str);
    }
    sort(vect.begin(),vect.end());

    for(i=0;i<vect.size()-1;i++){
        if(vect[i]==vect[i+1])sum++;
        else sum=0;
        tot+=sum;
    }
    cout<<tot<<endl;


    return 0 ;

}


Measured memory_bytes: 5748
#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>
#include <climits>

#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() {
    char a,b;
    cin >> a >> b;
    if(a == b){
        cout << "=" << endl;
    }else if(a < b){
        cout << "<" << endl;
    }else{
        cout << ">" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

#ifdef DEBUG
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
#else
template <class T, class... Args>
void debug(const T &x, const Args &... args) {}
template <class T> void debugVector(const vector<T> &v) {}
#endif

using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s[3];
    for(int i = 0; i < 3; i++) {
        cin >> s[i];
    }
    int nowTurn = 0;
    int nowId[3] = {0, 0, 0};
    while(1) {
        if(nowId[nowTurn] >= s[nowTurn].size()) {
            cout << (char)('A' + nowTurn) << endl;
            break;
        }
        int nxtTurn = s[nowTurn][nowId[nowTurn]] - 'a';
        nowId[nowTurn]++;
        nowTurn = nxtTurn;
    }
}

Measured memory_bytes: 3652
"""
author : halo2halo
date : 24, Jan, 2020
"""

import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, A, C = map(int, readline().split())

print('Yes' if N + A >= C else 'No')


Measured memory_bytes: 3060
#include <stdio.h>
#define M 110
int main(void)
{
	int n,m,l;
	
	int a[M][M],b[M][M];
	long long ans[M][M];
	
	int i,j,k;
	
	scanf("%d %d %d",&n,&m,&l);
	
	for(i=0 ; i<n ; i++){	//aの入力
		for(j=0 ; j<m ; j++)
			scanf("%d",&a[i][j]);
	}
	for(i=0 ; i<m ; i++){	//bの入力
		for(j=0 ; j<l ; j++)
			scanf("%d",&b[i][j]);
	}
	
	for(i=0 ; i<n ; i++){	//n
		for(j=0 ; j<l ; j++){	//l
			for(k=0 ; k<m ; k++){	//m
				ans[i][j]+=a[i][k]*b[k][j];
			}//m
		}//l
	}//n

	for(i=0 ; i<n ; i++){
		for(j=0 ; j<l ; j++){
			if(j!=l)printf("%ld",ans[i][j]);
			if(j!=l-1)printf(" ");
		}
		printf("\n");
	}

	return 0;
}


Measured memory_bytes: 2076
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#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++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
typedef priority_queue<string> priquest;
typedef priority_queue<string,vector<string>,greater<string>> rpriquest;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

const ll big=1000000007;
int exp(int x,int y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x)%big;
    int t=exp(x,y/2);
    return (t*t)%big;
}
void chmin(ll a,ll b){
    if(a>b)a=b;
    return;
}

int main(){
    int n;cin >> n;
    vector<ll> a(n+1);
    map<ll,ll> ans;
    a[0]=0;
    ans[0]++;
    rep(i,n){
        int b;
        cin >> b;
        a[i+1]=a[i]+b;
        ans[a[i+1]]++;
    }
    ll cnt=0;
    for(auto v:ans){
        cnt+=v.second*(v.second-1)/2;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 14336
#include <iostream>
#include <algorithm>
using namespace std;
struct team{
	char name;
	int win,lose,draw;
	team(){
		win = lose = draw = 0;
	}
};
bool checker(team a,team b){
	if(a.win > b.win) return true;
	if(a.win == b.win && a.lose < b.lose) return true;
	return false;
}
int main(){
	int n,a;
	char b;
	while(cin >> n,n){
		team c[10];
		for(int i = 0;i < n;++i){
			cin >> b;
			c[i].name = b;
			for(int j = 0;j < n - 1;++j){
				cin >> a;
				if(a == 0) ++c[i].win;
				else if(a == 1) ++c[i].lose;
				else ++c[i].draw;
			}
		}
		sort(c,c+n,checker);
		for(int i = 0;i < n;++i){
			cout << c[i].name << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int x=1;
  while(true){
    if(x%2!=0) c-=b;
    else a-=d;
    if(c<=0){cout<<"Yes"; break;}
    else if(a<=0){cout<<"No"; break;}
    x++;
  }
  return 0;
}

Measured memory_bytes: 3600
INF = float("inf")
n = int(input())
a = list(map(int, input().split())) + ([0]*5)
s = 2 + n % 2 
dp = [[-INF] * s for _ in range(n+5)]
for i in range(s): dp[i][i] = a[i]

for i in range(n):
    for j in range(s):
        dp[i+2][j] = max(dp[i+2][j], dp[i][j] + a[i+2])
        if j == s-1: break
        dp[i+3][j+1] = max(dp[i+3][j+1], dp[i][j] + a[i+3])

print(max([dp[n-i][s-i] for i in range(1, s+1)]))


Measured memory_bytes: 131260
// atcoder/abc060/A/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  string a, b, c;
  while (cin >> a >> b >> c) {
    cout << (a.back() == b.front() && b.back() == c.front() ? "YES" : "NO") << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std;
using ll = long long;

// DMC
int main() {
  int N, Q;
  string str;
  cin >> N >> str >> Q;
  
  for (int q = 0; q < Q; q++) {
    int k;
    cin >> k;
    
    ll cnt = 0;
    ll d_cnt = 0;
    ll m_cnt = 0;
    ll dm_cnt = 0;
    for (int i = 0; i < N; i++) {
      if (str[i] == 'D') {
        d_cnt++;
      } else if (str[i] == 'M') {
        m_cnt++;
        dm_cnt += d_cnt;
      } else if (str[i] == 'C') {
        cnt += dm_cnt;
      }
      
      if (i >= k - 1) {
        if (str[i - k + 1] == 'D') {
          dm_cnt -= m_cnt;
          d_cnt--;
        } else if (str[i - k + 1] == 'M') {
          m_cnt--;
        }
      }
    }
    
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 1540
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
int par[26];
int ran[26];
void init()
{
	for(int i=0;i<26;i++) par[i]=i,ran[i]=0;
}
int find(int x)
{
	if(par[x] == x) return x;
	else return par[x]=find(par[x]);
}
void unite(int x,int y)
{
	x=find(x);
	y=find(y);
	if(x == y) return ;
	if(ran[x]<ran[y]) par[x]=par[y];
	else 
	{
		par[y]=par[x];
		if(ran[x] == ran[y]) ran[x]++;
	}
}
bool same(int x,int y)
{
	return find(x)==find(y);
}


int main()
{
    while(1)
    {
        int n;
        int dif[26]={};
        bool ok[26]={};
        int t = 0;
        cin >> n;
        if(n == 0) return 0;
        init();
        for(int i=0;i<n;i++)
        {
            string x; cin >> x;
            if(!ok[(x[0]-'a')])
            {
            	ok[(x[0]-'a')] = true; t++;
            }
            if(!ok[(x[x.size()-1]-'a')])
            {
            	ok[(x[x.size()-1]-'a')] = true; t++;
            }
            if(!same((x[0]-'a'),(x[x.size()-1]-'a')))
            {
            	unite((x[0]-'a'),(x[x.size()-1]-'a')); t--;
            }
            dif[(x[0]-'a')]++;
            dif[(x[x.size()-1]-'a')]--;
        }
        if(t != 1) goto out;
        for(int i=0;i<26;i++)
        {
            if(dif[i] != 0) goto out;
        }
        puts("OK"); continue; out:; puts("NG");
    }
}

Measured memory_bytes: 1180
def ok(n):
    if n > 0 and n < 13:
        return True
    else:
        return False

s = list(input())
a = int(''.join(s[:2]))
b = int(''.join(s[2:]))
if ok(a) and ok(b):
    print('AMBIGUOUS')
elif ok(a):
    print('MMYY')
elif ok(b):
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3060