akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<string.h>
#include<algorithm>
using namespace std;

int main() {
	string s("ABC");
	string s2;
	cin >> s2;
	s += s2;
	cout << s << endl;


	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String a = sc.next();
		String b = sc.next();
		String c = sc.next();

		String aLast  = a.substring(a.length()-1, a.length());
		String bFirst = b.substring(0, 1);
		String bLast  = b.substring(b.length()-1, b.length());
		String cFirst = c.substring(0, 1);

		if (aLast.compareTo(bFirst) == 0 && bLast.compareTo(cFirst) == 0){
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}

}


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

#define reps(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) reps(v, 0, n)
#define lep(v, n) reps(v, 1, n + 1)

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }
template<typename T> void show(T& a, char del='\n', char last='\n'){ rep(i, a.size() - 1) cout << a[i] << del; cout << a[a.size() - 1] << last; }

int main()
{
  string n;
  char type;
  while (cin >> n >> type, type != 'X'){
    rep(i, n.size()){
      if (type == 'U'){
        if (i == 0){
          putchar(toupper(n[i]));
        }
        else if (n[i] == '_'){
          putchar(toupper(n[i + 1]));
          i++;
        }
        else {
          putchar(n[i]);
        }
      }
      if (type == 'L'){
        if (i == 0){
          putchar(tolower(n[i]));
        }
        else if (n[i] == '_'){
          putchar(toupper(n[i + 1]));
          i++;
        }
        else {
          putchar(n[i]);
        }
      }
      if (type == 'D'){
        if (i == 0){
          putchar(tolower(n[i]));
        }
        else if (isupper(n[i])){
          putchar('_');
          putchar(tolower(n[i]));
        }
        else {
          putchar(n[i]);
        }
      }
    }
    puts("");
  }
  return 0;
}

Measured memory_bytes: 1156
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		// 整数の入力
		String S = sc.next();
		String p = S.substring(0, 2);
		String o = S.substring(2);

		boolean pIs = isMonth(p);
		boolean oIs = isMonth(o);

		if(pIs && oIs){
			System.out.println("AMBIGUOUS");
		}else{
			if(oIs){
				System.out.println("YYMM");
			}else if(pIs){
				System.out.println("MMYY");
			}else{
				System.out.println("NA");
			}
		}

		System.out.println("");

		sc.close();
	}

	private static boolean isMonth(String S){
		if (S.equals("01") || S.equals("02") || S.equals("03") || S.equals("04") || S.equals("05")
				|| S.equals("06") || S.equals("07") || S.equals("08") || S.equals("09") || S.equals("10")
				|| S.equals("11") || S.equals("12")) {
			return true;
		}

		return false;
	}
}


Measured memory_bytes: 23636
n=int(input())
arr=[list(map(int,input().split())) for _ in range(n)]
if n%2==0:
  l=0
  r=10**9+1
  while r-l!=1:
    mid=(l+r)//2
    cnt1=0
    cnt2=0
    cnt3=0
    for a,b in arr:
      if mid<a:
        cnt1+=1
      elif mid>b:
        cnt2+=1
      else:
        cnt3+=1
    if cnt1>n//2:
      l=mid
    elif cnt2>n//2-1:
      r=mid
    else:
      l=mid
  r1=l
  l=0
  r=r1+1
  while r-l!=1:
    mid=(l+r)//2
    cnt1=0
    cnt2=0
    cnt3=0
    for a,b in arr:
      if mid<a:
        cnt1+=1
      elif mid>b:
        cnt2+=1
      else:
        cnt3+=1
    if cnt1>n//2:
      l=mid
    elif cnt2>n//2-1:
      r=mid
    else:
      r=mid
  l1=r
  l=0
  r=10**9+1
  while r-l!=1:
    mid=(l+r)//2
    cnt1=0
    cnt2=0
    cnt3=0
    for a,b in arr:
      if mid<a:
        cnt1+=1
      elif mid>b:
        cnt2+=1
      else:
        cnt3+=1
    if cnt1>n//2-1:
      l=mid
    elif cnt2>n//2:
      r=mid
    else:
      l=mid
  r2=l
  l=0
  r=r2+1
  while r-l!=1:
    mid=(l+r)//2
    cnt1=0
    cnt2=0
    cnt3=0
    for a,b in arr:
      if mid<a:
        cnt1+=1
      elif mid>b:
        cnt2+=1
      else:
        cnt3+=1
    if cnt1>n//2-1:
      l=mid
    elif cnt2>n//2:
      r=mid
    else:
      r=mid
  l2=r
  print((r1+r2)-(l1+l2)+1)  
elif n%2==1:
  l=0
  r=10**9+1
  while r-l!=1:
    mid=(l+r)//2
    cnt1=0
    cnt2=0
    cnt3=0
    for a,b in arr:
      if mid<a:
        cnt1+=1
      elif mid>b:
        cnt2+=1
      else:
        cnt3+=1
    if cnt1>n//2:
      l=mid
    elif cnt2>n//2:
      r=mid
    else:
      l=mid
  l1=l
  r1=r
  l=0
  r=l1+1
  while r-l!=1:
    mid=(l+r)//2
    cnt1=0
    cnt2=0
    cnt3=0
    for a,b in arr:
      if mid<a:
        cnt1+=1
      elif mid>b:
        cnt2+=1
      else:
        cnt3+=1
    if cnt1>n//2:
      l=mid
    elif cnt2>n//2:
      r=mid
    else:
      r=mid
  l2=l
  r2=r
  print(l1-r2+1)

Measured memory_bytes: 103292
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N = int(input())
Alist = [int(x) for x in input().split()]
Abslist = [abs(x) for x in Alist]

if 0 in Alist:
    ans = sum(Abslist)
else:
    count = 0
    for i in Alist:
        if i < 0:
            count += 1
    if count % 2 == 0:
        ans = sum(Abslist)
    else:
        ans = sum(Abslist) - 2* min(Abslist)

print(ans)
        


Measured memory_bytes: 14224
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<time.h>
#include<tuple>
#include<utility>
#include<vector>

using namespace std;
const long mod = 1000000007;

int main() {

	long N; cin >> N;
	long s[1000]; for (int i = 1; i <= N; i++) cin >> s[i];

	bool isn10 = false;
	long sum = 0;
	long mymin = INT_MAX;
	for (int i = 1; i <= N; i++) {
		if (s[i] % 10 != 0) isn10 = true;

		sum += s[i];
		if (s[i] % 10 != 0) mymin = min(mymin, s[i]);
	}

	if (!isn10) { cout << 0 << endl; return 0; }

	if (sum % 10 != 0) { cout << sum << endl; return 0; }

	cout << sum - mymin << endl;

}

Measured memory_bytes: 256
#include<stdio.h>
int d[100010][30],n;
int main(){
  char s[100010],t[100010];
  long long ans=0,a,l,i,b[30];
  scanf("%s %s",s,t);
  for(l=0;s[l];l++);
  for(i=0;i<30;i++)b[i]=-1;
  for(i=l;i--;)b[s[i]-'a']=i+l;
  for(a=l;a--;){
    for(i=0;i<30;i++)d[a][i]=b[i];
    b[s[a]-'a']=a;
  }
  ans=a=b[t[0]-'a'];//printf("%lld\n",ans);
  if(ans<0)goto END;
  for(i=1;t[i];i++){//printf("%d\n",d[a][t[i+1]+'a']);
    n=d[a][t[i]-'a'];//printf("%d\n",n);
    if(n<0)goto END;
    ans+=n-a;
    a=n%l;
  }
  printf("%lld\n",ans+1);
  return 0;
 END:;
  printf("-1\n");
  return 0;
}


Measured memory_bytes: 12032
#include <bits/stdc++.h>
using namespace std;
#define EB emplace_back
#define MP make_pair
#define PB push_back
#define fi first
#define se second

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(__null);
  
  int n; cin >> n;
  int target = n;
  vector<pair<int, int> > v;
  
  for (int i = 2; i * i <= n; ++i){
    if (n % i != 0) continue;
    int cnt = 0;
    while (n % i == 0){
      n /= i; ++cnt;
    }
    v.PB(MP(i, cnt));
  }
  if (n != 1) v.PB(MP(n, 1));
  
  cout << target << ':';
  for (int i = 0; i < (int) v.size(); ++i){
    for (int j = 0; j < v[i].se; ++j){
      cout << " " << v[i].fi;      
    }
  }
  cout << '\n';
  
  return 0;
}


Measured memory_bytes: 3224
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <sstream>
#include <string>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

#define EPS 1e-14
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) FOR(i, 0, n)
#define PI 2*acos(0.0)
#define ALL(a) (a).begin(),(a).end()
#define DEBUG(x) cout<<#x <<": "<< x << "\n"
#define DEBUG_ARR(a) REP(i, size(a)){ cout << #a << "[" << i << "]: " << a[i] << "\n"; }
const int VX[] = { 0, 1, 0, -1 };
const int VY[] = { 1, 0, -1, 0 };
const long MOD = 1000000007;

int H, W;
string S[51];

int CountMine(int x, int y)
{
	int ret = 0;
	for(int i = max(x - 1, 0); i <= min(H, x + 1); i++)
	{
		for(int j = max(y - 1, 0); j <= min(W, y + 1); j++)
		{
			if (i == x && j == y) continue;
			if (S[i][j] == '#') ret++;
		}
	}

	return ret;
}

int main() {
	//	--- I/O 高速化 ---
	cin.tie(0);
	ios::sync_with_stdio(false);
	// --- ここまで ---

	cin >> H >> W;
	
	REP(i, H)
	{
		cin >> S[i];
	}

	REP(i, H)
	{
		REP(j, W)
		{
			if (S[i][j] == '#') cout << "#";
			else cout << CountMine(i, j);

		}
		cout << "\n";
	}

	return 0;
}



Measured memory_bytes: 256
def main():
    n = int(input())
    a = map(int, input().split())
    if all(x % 3 == 0 or x % 5 == 0 for x in a if x % 2 == 0):
        print('APPROVED')
    else:
        print('DENIED')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define INF 999999999
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;


int main(){
  int n,action,num;
  vector<int> v;
  scanf("%d",&n);
  REP(i,n){
    scanf("%d",&action);
    switch(action){
      case 0:
        scanf("%d",&num);
        v.push_back(num);
        break;
      case 1:
        scanf("%d",&num);
        printf("%d\n",v[num]);
        break;
      case 2:
      v.pop_back();
      break;

    }
  }
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

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

    int Q; cin >> Q;
    multiset<ll> data;
    bool start = false;
    int index = 0;
    int count = 0;
    ll ans = 0;
    auto it = data.begin();
    F0R(query, Q) {
        int qType; cin >> qType;
        if (qType == 2) {
            cout << *it << " ";
            cout << ans << endl;
        } else {
            ll A, B; cin >> A >> B;

            if (start == false) {
                ans += B;
                data.insert(A); it = data.begin();
                start = true;
                count = 1;
            } else {
                ans += B;
                data.insert(A);
                if (A < *it) index++;
                count++;
                ans += abs(A - *it);
                int goal = count / 2; if (count % 2 == 0) goal--;
                if (index < goal) {
                    ll old = *it; it++;
                    ll newVal = *it;
                    ans += (index+1) * (newVal - old);
                    ans -= (count-index-1) * (newVal - old);
                    index++;
                } else if (index > goal) {
                    ll old = *it; it--;
                    ll newVal = *it;
                    index--;
                    ans -= (index+1) * (newVal - old);
                    ans += (count-index-1) * (newVal - old);
                }
            }
        }
    }

    return 0;
}

// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 9600
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if (n % 2 == 0) {
			System.out.println(n);
		}else {
			System.out.println(2 * n);
		}
	}

}


Measured memory_bytes: 35600
N = int(input())
S = list(input())

m = S.count('.')
mi = m
# すべて黒にするためのコスト
for s in S:
    if s == '.':
        m -= 1
    else:
        m += 1
    mi = min(mi,m)
# .....####### から
# ......###### にする

print(mi)

Measured memory_bytes: 4840
#include <algorithm>
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <cmath>
#include <iomanip>
#include <set>
#include <climits>
#include <utility>
using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<pair<pair<string, int>, int>> spls(n);
	int i = 1;
	for (auto& sp : spls) {
		cin >> sp.first.first >> sp.first.second;
		sp.second = i;
		++i;
	}

	sort(spls.begin(), spls.end(), [](pair<pair<string, int>, int> l, pair<pair<string, int>, int> r) {
		return l.first.first < r.first.first || (l.first.first == r.first.first && l.first.second > r.first.second);
		});

	for (auto sp : spls) {
		cout << sp.second << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;
int n, m, k;

int main() {
    scanf("%d %d %d", &n, &m, &k);
    vector<int> a(n + 1, 0), b(m + 1, 0);
    vector<long long> sumA(n + 1, 0), sumB(m + 1, 0);

    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
        sumA[i] = sumA[i - 1] + a[i];
    }
    for (int i = 1; i <= m; ++i) {
        scanf("%d", &b[i]);
        sumB[i] = sumB[i - 1] + b[i];
    }

    int max_ans = 0;
    int j = m;
    for (int i = 0; i <= n; ++i) {
        if (sumA[i] > k) {
            break;
        }
        int p = upper_bound(sumB.begin(), sumB.end(), k - sumA[i]) - sumB.begin();
        max_ans = max(max_ans, i + (p - 1));
    }

    printf("%d\n", max_ans);
}


Measured memory_bytes: 7988
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define RREP(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)++)
#define p(...) printf(__VA_ARGS__); cout << endl;
#define input(x) x; cin >> x;
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](const a, const b){ return c ;}
#define key(t, x, compare) [](const t& a, const t& b){ return a x compare b x ;}

using namespace std;

using pii = pair<int, int>;

int main(){
  int input(n);
  int input(k);
  int list_input(d, k);
  string ds[k];
  rep(i, k){
    ds[i] = to_string(d[i]);
  }
  while(true){
ONE_MORE:
    for(string i: ds){
      if(to_string(n).find(i) != string::npos){
        n++;
        goto ONE_MORE;
      }
    }

    cout << n << endl;
    break;
  }
}


Measured memory_bytes: 256
/**
 * Author: PraveenKumarRana
**/

#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
using namespace std;

void solve(){
    ll h,w; cin>>h>>w;
    vector< vector<ll> > dp(h, vector<ll> (w,0));
    vector< string > lis(h);
    for(int i=0; i<h; i++) cin>>lis[i];
    for(int i=0; i<h; i++){
        if(lis[i][0]=='.') dp[i][0]=1;
        else break;
    }
    for(int i=0; i<w; i++){
        if(lis[0][i]=='.') dp[0][i]=1;
        else break;
    }
    for(int i=1; i<h; i++){
        for(int j=1; j<w; j++){
            if(lis[i][j]=='.') dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
        }
    }
    
    cout<<dp[h-1][w-1]<<"\n";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}



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

int main(){
 int N,M,C;
  cin >> N >> M >> C;
  vector<int> B(M);
  vector<vector<int>> A(N,vector<int> (M));
  for(int i=0;i<M;i++){
    cin >> B.at(i);
  }
  
  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++){
      cin >> A.at(i).at(j);
    }
  }
  
  int cnt=0;
  
  for(int i=0;i<N;i++){
    int tmp=0;
    for(int j=0;j<M;j++){
      tmp += A.at(i).at(j)*B.at(j);
    }
    tmp += C;
    if(tmp > 0)
      cnt++;
  }
  
  cout << cnt << endl;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int M[100][100];

int main()
{
    int n;
    int r,node,c;

    cin >> n;

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            M[i][j]=0;
            //cout << "hhh" << endl;
        }
    }

    for(int i=0;i<n;i++)
    {
        cin >> r;
        if(i==r-1)
        {
            //cout << "hhh" << endl;
            cin >> node;
            for(int j=0;j<node;j++)
            {
                cin >> c;
                M[r-1][c-1]=1;
            }
        }

    }

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(j>0)cout << " ";
            cout << M[i][j];
        }
        cout << endl;
    }


    return 0;
}



Measured memory_bytes: 3120
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>
#include <map>
#include <queue>
#include <set>
typedef long long ll;
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define mod 1000000007
#define fst first
#define pb push_back

int main()
{
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    reverse(h.begin(),h.end());
    int ans = 0;
    int val = 0;
    for(int i = 1; i < n; i++){
        if(h[i-1] <= h[i]) val++;
        else val = 0;
        ans = max(ans, val);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <queue>
#include <vector>
using namespace std;

#define max_n 100000
#define max_m 1000
#define max_w 1000
#define max_h 1000
#define INF 1000000000


typedef long long lint;


int main()
{
    //入力
    lint a,b,x;
    cin>>a>>b>>x;
    lint count;
    count=b/x-a/x;
    if(a%x==0)count++;
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math

    #inf = 10**17
    #mod = 10**9 + 7

    s = input().rstrip()
    ls = len(s)
    t = input().rstrip()
    lt = len(t)
    alphabet = 'abcdefghijklmnopqrstuvwxyz' #26
    moji = [[] for _ in range(26)]
    for i in range(ls):
        idx = alphabet.index(s[i])
        moji[idx].append(i+1)
    
    cnt = 0
    res = 0
    while cnt < lt:
        for i in range(cnt, lt):
            idx = alphabet.index(t[i])
            if not moji[idx]:
                print(-1)
                exit()
            if i == cnt:
                now = moji[idx][0] + 1
            else:
                nex = bisect_left(moji[idx], now)
                if nex == len(moji[idx]):
                    res += ls
                    cnt = i
                    break
                now = moji[idx][nex] + 1
        else:
            res += now - 1
            break
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 7916
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <stack>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;
int n;
vector<vector<int>>edge;
int num(int a,int b,int n)
{
  if(a>b)swap(a,b);
  return a*n+b;
}
vector<int>flag,flag2,hh;

bool topo_sort(int v)
{
  //頂点数v、辺の数e
  auto g=edge;
  vector<int>h(v);

  //入次数が0の頂点の集合
  stack<int> st;
  rep(i,v)
  {
    for(auto j:edge[i])h[j]++;
  }
  hh=h;
  //入次数が0の頂点であればstに追加
  rep(i, v) if(h[i] == 0) st.push(i);

  //ソートされた後のグラフ
  vector<int> ans;
  //stがなくなるまでループ
  while(st.size()) {
    //stの集合のから一つ取り出す
    int i = st.top(); st.pop();
    ans.push_back(i);
    for(auto j: g[i]) {
      //隣接する頂点の入次数をマイナス1
      h[j]--;
      //これによって入次数が0になればstに追加
      if(h[j] == 0) st.push(j);
    }
  }

  //ansを順に出力
//  for(int i: ans) cout << i << endl;
  //cout<<"ans.size()"<<ans.size()<<endl;
  return ans.size()==v;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin>>n;
  edge.resize(n*n+1);
  flag.resize(n*n+1,0);
  flag2=flag;
  rep(i,n)
  {
    int b;
    cin>>b;b--;
    int ab=num(i,b,n);
    edge[n*n].push_back(ab);
//    cout<<"ab"<<ab<<endl;
    rep(j,n-2)
    {
      int tb;
      cin>>tb;tb--;
      int nab=num(i,tb,n);
      edge[ab].push_back(nab);
      //cout<<"ab"<<nab<<" "<<i<<tb<<endl;
      ab=nab;
    }
  }
  if(!topo_sort(n*n+1)){cout<<-1<<endl;return 0;};
  queue<int>que;
  que.push(n*n);flag[n*n]=0;
  int res=0;
//  cout<<topo_sort(n*n+1)<<endl;
  //cout<<edge[n*n].size()+(n)*(n-1)/2<<endl;


  while(!que.empty())
  {
    auto tq=que.front();que.pop();
    for(auto nn:edge[tq])
    {
      flag2[nn]++;
      chmax(flag[nn],flag[tq]+1);

      if(flag2[nn]==hh[nn])que.push(nn);
    }

  }
  rep(i,n*n)chmax(res,flag[i]);
  cout<<res<<endl;


  return 0;

}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<bool> v(3, true);
    REP(i,2){
        int32 a;
        cin >> a;
        v[a-1] = false;
    }
    REP(i,3){
        if(v[i])cout << i + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
using lint = long long int;
#define FOR(i,from,to) for(i=(from);i<(to);i++)

const int NMAX = 100005;

int cluc_dist(int x, int xx) {
	int dx = xx - x;
	if (dx < 0) dx *= -1;
	return dx;
}

int main() {
	int i, j, k, l;
	int N; cin >> N;
	int t[NMAX], x[NMAX], y[NMAX];
	t[0] = x[0] = y[0] = 0;

	int tt, d, dx, dy;
	FOR(i, 1, N + 1) {
		cin >> t[i] >> x[i] >> y[i];
		tt = t[i] - t[i - 1];
		dx = cluc_dist(x[i - 1], x[i]);
		dy = cluc_dist(y[i - 1], y[i]);
		d = dx + dy;

		if (tt < d) {
			cout << "No" << endl;
			return 0;
		}
		if (tt % 2 != d % 2) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 1408
namespace VainZero.Procon.FSharp

open System
open System.Collections.Generic

[<AutoOpen>]
module Operators =
  let read f = Console.ReadLine().Split([|' '|]) |> Array.map f

module Program =
  [<EntryPoint>]
  let main _ =
    let [|n; m|] = read int
    let edges =
      [|
        for _ in 0..(m - 1) do
          let [|a; b|] = read int
          yield (a - 1, b - 1)
      |]

    let calc () =
      let degrees = [|for _ in 0..(n - 1) -> 0|]
      for (a, b) in edges do
        degrees.[a] <- degrees.[a] + 1
        degrees.[b] <- degrees.[b] + 1
      degrees

    calc () |> Seq.iter (printfn "%d")
    0


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

namespace _0053
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> prime = new List<int>();
            for (int i = 2; prime.Count != 10000; i++)
            {
                bool b = true;
                for (int j = 0; j < prime.Count && b; j++)
                {
                    if (i % prime[j] == 0)
                    {
                        b = false;
                    }
                }
                if (b)
                {
                    prime.Add(i);
                }
            }
            while (true)
            {
                int i = int.Parse(Console.ReadLine());
                if (i == 0)
                {
                    break;
                }
                Console.WriteLine(prime.Take(i).Sum());
            }
        }
    }
}

Measured memory_bytes: 9476
#include <bits/stdc++.h>
using namespace std;
int main() 
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    string s;
    cin>>s;
    int k;
    cin>>k;
    long int ans=0,l=0,r=0,n=s.length(),z=0;
    vector<long int> v;
    while(1)
    {
        if(r>=n)
        break;
        while(r<n&&s[l]==s[r])
        r++;
        v.push_back((r-l)/2);
        if(r==n&&v.size()>1)
        {
            while(s[l]==s[r%n])
            r++;
            if(r>n)
            z=(r-l)/2;
            break;
        }
        l=r;
    }
    if(v.size()==1)
    ans=(k*s.length())/2;
    else if(z)
    {
        ans+=v[0]+v[v.size()-1];
        for(int i=1;i<v.size()-1;i++)
        ans+=k*v[i];
        ans+=(k-1)*z;
    }
    else
    {
    	for(int i=0;i<v.size();i++)
    	ans+=k*v[i];
	}
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
const LL INF = 1000000000;
using P = pair<LL, LL>;
LL H, W;
char a[51][51];
bool f[51][51];
LL d[51][51];
queue<P> que;
LL dx[4] = {1, 0, -1, 0};
LL dy[4] = {0, -1, 0, 1};

int main(){
    cin >> H >> W;
    LL wcount = 0;
    for(int i = 1;i < H+1;i++){
        for(int j = 1;j < W+1;j++){
            cin >> a[i][j];
            if(a[i][j] == '.')  wcount++;
            d[i][j] = INF;
        }
    }
    d[1][1] = 1;
    f[1][1] = true;
    que.push(make_pair(1, 1));
    while(!que.empty()){
        P p = que.front();
        que.pop();
        LL cy = p.first;
        LL cx = p.second;
        if(cy == H && cx == W)   break;
        for(int i = 0;i < 4;i++){
            LL nx = cx+dx[i];
            LL ny = cy+dy[i];
            if(!f[ny][nx] && nx > 0 && nx < W+1 && ny > 0 && ny < H+1 && a[ny][nx] == '.'){
                que.push(make_pair(ny, nx));
                d[ny][nx] = d[cy][cx]+1;
                f[ny][nx] = true;
            }
        }
    }
    LL ans = wcount-d[H][W];
    if(d[H][W] == INF)  cout << -1 << endl;
    else    cout << ans << endl;
}



Measured memory_bytes: 256
n, y = map(int,input().split())
for a in range(n+1):
  for b in range(n+1-a):
    if 9000*a+4000*b+1000*n == y:
      print(a,b,n-a-b)
      break
    elif a == n:
      print(-1,-1,-1)
      break
  else:
     continue
  break



Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>


#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)

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

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

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> v(N);

    rep(i, N){
        cin >> v[i];
    }

    ll max = -2*INF;
    ll min = INF;
    for(int i=0; i<N; i++){
        ll tmp = v[i] - min;
        if(tmp > max) max = tmp;
        if(v[i]<min) min = v[i];
    }
    cout << max << endl;
}


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

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

#define rep(i,N) for(int i=0; i < (int)N; i++)
#define all(v) (v).begin(),(v).end()

const int INF = 100000002;

int main(){
	int n; cin >> n;
	for (int i=1; i<=n; i++){
		if(int(i*1.08) == n){
			 cout << (int) i;
			return 0;	
		}
	}
	cout << ":(";
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import math
YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, M: int, A: "List[int]"):
    criteria = math.ceil(sum(A)/(4*M))

    def check(n):
        return n >= criteria
    print(YES if len(list(filter(check, A))) >= M else NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, M, A)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <vector>
#include <cstdlib>
using namespace std;
int main(void){
  int x;
  cin >> x;
  if(x % 10 == 9 || x / 10 == 9){
    cout << "Yes";
  } else {
    cout << "No";
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	@SuppressWarnings("resource")
	public static void main(String[] args) {
		Scanner imput =  new Scanner(System.in);
		int  A,B;
		A=imput.nextInt();
		B=imput.nextInt();
		int max=A+B;
		if(2*A-1>max)
			max=2*A-1;
		else if(2*B-1>max)
			max=2*B-1;
		System.out.println(max);
	}
}

Measured memory_bytes: 22356
// ABC124
// A - Buttons
#include<bits/stdc++.h>

using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    if(a>b) cout << 2*a-1 << endl;
    else if(a<b) cout << 2*b-1 << endl;
    else cout << 2*a << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    string s;
    cin >> s;
    ll n = s.size();
    
    if(n%2 == 1) {
        out("No");
        re0;
    }

    for(ll i = 0; i < n-1; i += 2) {
        if(s[i] == 'h' && s[i+1] == 'i') {
            ;
        }
        else {
            out("No");
            re0;
        }
    }
    
    out("Yes");
    re0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int k,s,i,j;
	long long ans=0;
	scanf("%d%d",&k,&s);
	for(i=0;i<=k;i++)
	for(j=0;j<=k;j++)
	{
		if(s-(i+j)<=k&&s-(i+j)>=0)
		{
			ans++;
		}
	}
	printf("%lld",ans);
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define MAX 100000
void inarray(int a[], int n){
    for(int i = 0; i < n; i++) cin >> a[i];
}

int main(){
    int h,w,k; cin >> h >> w >> k;
    char c[h][w];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> c[i][j];
        }
    }

    int ans = 0;
    for(int i = 0; i < pow(2,h); i++){
        for(int j = 0; j < pow(2,w); j++){
            // 2進数表記で1の時ぬる

            int b = 0;
            for(int i2 = 0; i2 < h; i2++){
                if(i&(1<<i2)) continue;
                for(int j2 = 0; j2 < w; j2++){
                    if(j&(1<<j2)) continue;
                    if(c[i2][j2] == '#') b++;
                }
            }
            if(b == k) ans++;

        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4120
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

static int
solve(int H, int A)
{
  return (H + A - 1) / A;
}

int
main()
{
  int H, A;
  cin >> H >> A;
  cout << solve(H, A) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#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--)

vector<string> edge;

bool findCycle(int node, int p, vector<bool>& isVisited, vector<int>& parity)
{
    isVisited[node] = true;
    parity[node] = p;

    bool result = false;
    rep(i, edge[node].size())
    {
        if (edge[node][i] == '1') {
            if (isVisited[i]) {
                if (parity[i] == p) {
                    return true;
                }
            } else {
                result = result || findCycle(i, 1 - p, isVisited, parity);
            }
        }
    }
    return result;
}

int main()
{
    int n;
    cin >> n;
    edge.resize(n);
    rep(i, n)
    {
        cin >> edge[i];
    }

    vector<bool> isVisited(n, false);
    vector<int> parity(n);
    if (findCycle(0, 0, isVisited, parity)) {
        cout << -1 << endl;
        return 0;
    }

    vector<vector<int>> dist(n, vector<int>(n, n + 1));
    rep(i, n)
    {
        dist[i][i] = 0;
    }
    rep(i, n) rep(j, n)
    {
        if (edge[i][j] == '1') {
            dist[i][j] = 1;
        }
    }

    rep(k, n) rep(i, n) rep(j, n)
    {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
    }

    int result = 0;
    rep(i, n)
    {
        rep(j, n)
        {
            result = max(result, dist[i][j]);
            //cout << dist[i][j] << " ";
        }
        //cout << endl;
    }
    cout << result + 1 << endl;

    return 0;
}

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

namespace AtCoder.Abc
{
    //https://atcoder.jp/contests/abc175/tasks/abc175_a
    public class QuestionA
    {
        public static void Main(string[] args)
        {

            long n = long.Parse(Console.ReadLine());
            Console.WriteLine(n * n);
            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 27464
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define abdelrahman010 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;
const int N = 2e5 + 5;
int n , a[15];
int x[15][15];
int y[15][15];
int main() {
    abdelrahman010
    cin >> n;
    for(int i = 0;i < n;i++) {
        cin >> a[i];
        for(int j = 0;j < a[i];j++)
            cin >> x[i][j] >> y[i][j] , x[i][j]--;
    }
    int ans = 0;
    for(int i = 1;i < (1 << n);i++) {
        bool yes = true;
        for(int j = 0;j < n;j++)
            if((1 << j) & i)
                for(int k = 0;k < a[j];k++) {
                    bool p = (1 << x[j][k]) & i;
                    if(p ^ y[j][k])
                        yes = false;
                }
        if(yes)
            ans = max(ans , __builtin_popcount(i));
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
	
	public static void main(String[] args) throws IOException {
		
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		
		ArrayList<Boolean> ans = new ArrayList<Boolean>();
		int j = 0;
		
		int cnt = Integer.parseInt(br.readLine());
		for (int i = 0; i < cnt; i++) {
			StringTokenizer st = new StringTokenizer(br.readLine()," ");
			int[] nums = new int[3];
			while (st.hasMoreTokens())
				nums[j++] = Integer.parseInt(st.nextToken());
			Arrays.sort(nums);
			ans.add(nums[0] * nums[0] + nums[1] * nums[1] == nums[2] * nums[2]);
			j = 0;
		}
		
		for (boolean a : ans)
			System.out.println(a ? "YES" : "NO");
	}
	
}

Measured memory_bytes: 9844
s = int(input())


def f(n):
    return n // 2 if n % 2 == 0 else 3 * n + 1


i = 1
A = {s}
while True:
    s = f(s)
    i += 1
    if (s in A):
        break
    A.add(s)
print(i)


Measured memory_bytes: 2940
#include <stdio.h>

int main(void)
{
        char b;
        scanf("%c", &b);

        char ans;
        switch(b) {
        case 'A':
                ans = 'T';
                break;
        case 'T':
                ans = 'A';
                break;
        case 'C':
                ans = 'G';
                break;
        case 'G':
                ans = 'C';
                break;
        }

        printf("%c\n", ans);
        return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>
#include <iomanip>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

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

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

    vector<vector<char>> res(100,vector<char>(100,'a'));

    ll cta=0,ctb=0;
    ll idx;
    for(int i=0;i<50;i++){
        for(int j=0;j<100;j++){
            if(i%2==0 && j%2==0){
                if(cta<A-1) {
                    res[i][j]='.';
                    cta++;
                }
                else res[i][j]='#';
            }
            else res[i][j]='#';
        }
        if(cta>=A-1){
            idx=i+1;
            break;
        }
    }
    
    for(int i=0;i<100;i++) {
        res[idx][i]='#';
        res[idx+1][i]='.';
    }
    idx+=2;

    for(int i=idx;i<100;i++){
        for(int j=0;j<100;j++){
            if(i%2==0 && j%2==0){
                if(ctb<B-1) {
                    res[i][j]='#';
                    ctb++;
                }
                else res[i][j]='.';
            }
            else res[i][j]='.';
        }
    }
    cout << 100 << " " << 100 << endl;
    for(int i=0;i<100;i++){
        for(int j=0;j<100;j++){
            cout << res[i][j];
        }
        cout << endl;
    }
    

    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 7)
from functools import lru_cache

N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10 ** 9

@lru_cache(None)
def dfs(cur, a, b, c):
    if cur == N:
        return abs(a - A) + abs(b - B) + abs(c - C) if min(a, b, c) > 0 else INF

    # (10 if _ else 0): 最初の1本目は合成魔法の必要がない
    ret0 = dfs(cur + 1, a, b, c)
    ret1 = dfs(cur + 1, a + l[cur], b, c) + (10 if a else 0)
    ret2 = dfs(cur + 1, a, b + l[cur], c) + (10 if b else 0)
    ret3 = dfs(cur + 1, a, b, c + l[cur]) + (10 if c else 0)

    return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))

Measured memory_bytes: 26360
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<map>

using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(a) (a).begin(),(a).end()
 
int main(){
    int n;
    cin >> n;

    vector<string> w;
    bool flag = false;
    char tail = '?';
    rep(i, n){
        string in;
        cin >> in;
        auto itr = w.begin();
        itr = find(ALL(w), in);
        if(itr != w.end())flag = true;
        if(in[0] != tail && tail != '?')flag = true;
        tail = in[in.size()-1];
        w.push_back(in);
    }

    if(flag)cout << "No";
    else cout << "Yes";

}

Measured memory_bytes: 256
from fractions import gcd
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
a = list(map(int,input().split()))
cnt = 0
while(True):
  flg = 0
  for i in range(n):
    if a[i]%2 == 0:
      if flg == 0:
        flg = 1
    if flg and a[i]%2:
      print(0)
      exit()
  if flg:
    a = [i//2 for i in a]
  else:
    break
  cnt += 1
lcm = a[0]
for i in range(n-1):
  lcm=a[i+1]*lcm//gcd(a[i+1],lcm)
  if lcm>m:
    print(0)
    exit()
print((m//(lcm*2**(cnt-1))+1)//2)

Measured memory_bytes: 16272
def main():
    N = int(input())
    t = list(map(int, input().split()))
    v = list(map(int, input().split()))

    ans = editorial(N, t, v)
    print(ans)
    # time: sum(t) seconds
    # t_n: v_n m/s 以内
    # a: +- 1 m/s^2
    # => ???
    # answer: max dist

    # 現時点の制限速度MAXで走ると距離は伸びるが
    # 次のスタート時点の制限速度を考慮しないとルール違反となる
    # 最初と最後は速度0
    # 次と比較しても次々にて速度Overする可能性がある…


def editorial(N, ts, vs):
    maxv = []
    for v, t in zip(vs, ts):
        maxv.extend([v] * 2 * t)

    # 入力例3
    # [0]-----------[12]-------------[26]-[28]
    # 0,6-----------6,2 -------------2,7 -7,0
    # 0,6-----------6,2 -------------2,7,7,7
    # 6,6---------6,2,2 -----------2,7,7,7,0
    # ↓
    # 6,6--------- 6,2,2 -----------2,7,7
    # 6 ---------- 2,2 -----------2,7,7,x
    # 前から0ベース
    # 後から0ベースでの比較
    maxv = [0] + [min(v1, v2) for v1, v2 in zip(maxv, maxv[1:])]
    maxv.append(0)

    max_t = len(maxv)
    bef_v = 0
    for i in range(max_t):
        bef_v = maxv[i] = min(maxv[i], bef_v + 0.5)
    aft_v = -0.5
    for i in range(max_t)[::-1]:
        aft_v = maxv[i] = min(maxv[i], aft_v + 0.5)

    ans = 0
    for v1, v2 in zip(maxv, maxv[1:]):
        ans += (v1 + v2) * 0.5 / 2

    return ans


def fix_maxv(maxv, max_t):
    """
    0123456789 -> t
      2--23--3 -> v

      のように見えるけど実際は違う

    """
    maxv = maxv[:]
    tmp = [None] * 3
    tmp[0] = maxv[:]
    bef_v = 0
    for i in range(max_t):
        bef_v = maxv[i] = min(maxv[i], bef_v + 0.5)

    # lastが 0.5にならず、0m/s になるように調整
    tmp[1] = maxv[:]
    aft_v = -0.5
    for i in range(max_t)[::-1]:
        aft_v = maxv[i] = min(maxv[i], aft_v + 0.5)
    tmp[2] = maxv[:]
    for i in range(max_t):
        print(*([0.5 + i/2] + [tmp[j][i] for j in range(3)]), sep="\t")

    return maxv


def editorial_WA(N, ts, vs):
    # サンプル4より、0.5刻みで考える必要あり
    maxv = []
    for v, t in zip(vs, ts):
        maxv.extend([v] * 2 * t)
    default_maxv = [v + 0.05 for v in maxv]

    max_t = sum(ts) * 2
    maxv = fix_maxv(maxv, max_t)

    import os
    # atcoder uname
    # posix.uname_result(sysname='Linux', nodename='imojudge-all', release='3.13.0-108-generic',
    #                    version='#155-Ubuntu SMP Wed Jan 11 16:58:52 UTC 2017',
    #                    machine='x86_64')
    local = "Darwin" in str(os.uname())
    if local:
        import matplotlib
        # matplotlib.use("Qt4Agg")
        matplotlib.use("TkAgg")
        import matplotlib.pyplot as plt
        real_ts = [i / 2 for i in range(1, len(maxv) + 1)]
        plt.plot(real_ts, maxv, color="red")
        plt.plot(real_ts, default_maxv, color="blue")
        plt.show()
        # plt.show(block=False)
        # plt.pause(.01)

    ans = 0
    # lastを0m/s に調整するために + [0]
    # しかし合計0.5 秒余計, この調整をやめることでlastが0.5m/s のまま
    # for t, (v1, v2) in enumerate(zip([0] + maxv, maxv + [0]), 1):
    for t, (v1, v2) in enumerate(zip([0] + maxv, maxv), 1):
        # 台形面積
        trapezoid = (v1 + v2) * 0.5 / 2
        ans += trapezoid
        if local:
            print(t / 2, v1, v2, trapezoid, ans, sep="\t")

    return ans


if __name__ == '__main__':
    main()


Measured memory_bytes: 4268
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;

int a[N]={}, p;
int main(){
	ios_base::sync_with_stdio(false), cin.tie(0);
	int n;
	cin >> n;
	for(int i=1 ; i<=n ; ++i)
		cin >> a[i], p += abs(a[i] - a[i-1]);
	p += abs(a[n]);
	for(int i=1 ; i<=n ; ++i){
		cout << p - abs(a[i] - a[i-1]) - abs(a[i+1] - a[i]) + abs(a[i+1] - a[i-1]) << '\n';
	}
}

Measured memory_bytes: 3984
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int m; cin >> m;
  string s; cin >> s;
  int n = s.length(); int ans = 0;
  for(int i = 0; i <= n-3; ++i)
  {
    ans += (s.substr(i, 3) == "ABC");
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 3592
#include <iostream>
int main(){
	std::string S,T,U;
  	int A,B;
  	std::cin>>S >>T;
  	std::cin>>A >>B;
  	std::cin>>U;
  	if (U==S){
      std::cout<<A-1<<" "<<B;
    }
  	else{
      std::cout<<A<<" "<<B-1;
    }
  return 0;
}
  	

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int n;
string s[100005];

int main(void)
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> s[i];
	
	int ans = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 0; j+2 < s[i].size(); j++){
			if(s[i].substr(j, 3) == "AOR") ans++;
		}
	}
	
	int Ocnt = 0, _A = 0, _AO = 0, R_ = 0, OR_ = 0, R_A = 0, OR_A = 0, R_AO = 0, OR_AO = 0;
	for(int i = 1; i <= n; i++){
		int l = s[i].size();
		if(s[i] == "O") Ocnt++;
		if(s[i].substr(l-1, 1) == "A")_A++;
		if(l >= 2 && s[i].substr(l-2, 2) == "AO") _AO++;
		if(s[i].substr(0, 1) == "R") R_++;
		if(l >= 2 && s[i].substr(0, 2) == "OR") OR_++;
		if(l >= 2 && s[i].substr(0, 1) == "R" && s[i].substr(l-1, 1) == "A") R_A++;
		if(l >= 3 && s[i].substr(0, 2) == "OR" && s[i].substr(l-1, 1) == "A") OR_A++;
		if(l >= 3 && s[i].substr(0, 1) == "R" && s[i].substr(l-2, 2) == "AO") R_AO++;
		if(l >= 4 && s[i].substr(0, 2) == "OR" && s[i].substr(l-2, 2) == "AO") OR_AO++;
	}
	int gomi = _A+_AO+R_+OR_ - (R_A+OR_A+R_AO+OR_AO) + Ocnt;
	gomi = n - gomi;
	
	int mx = 0;
	for(int i = 0; i <= min(Ocnt, _A); i++){
		int tmp1 = min(_A-i, OR_);
		if(tmp1 && OR_A == _A && OR_A == OR_ && i == 0) tmp1--;
		
		int tmp2 = min(_AO+i, R_);
		if(tmp2 && R_AO == _AO && R_AO == R_ && i == 0) tmp2--;
		
		mx = max(mx, tmp1+tmp2);
		//cout << tmp1 << " " << tmp2 << endl;
	}
	if(mx && mx == n-(Ocnt+gomi)) mx--;
	ans += mx;
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 9928
<?php
fscanf(STDIN, "%d %d %d %d", $N, $M, $X, $Y);
$xx = explode(" ", trim(fgets(STDIN)));
$yy = explode(" ", trim(fgets(STDIN)));
$xx[] = $X;
$yy[] = $Y;

$a = max($xx);
$b = min($yy);

if ($a < $b) {
    echo "No War";
} else {
    echo "War";
}

Measured memory_bytes: 4728