akhauriyash/Code-Regression huggingface dataset:
S = list(input())

# 回文判定
def kaibun(s) :
  for i in range(len(s)//2) :
    if s[i] != s[-(i+1)] :
      return False
      break

  return True

# 条件
S1 = S[0 : len(S)//2]
S2 = S[(len(S)+3-1)//2 : len(S)]

if kaibun(S) & kaibun(S1) & kaibun(S2) :
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using i128 = boost::multiprecision::int128_t;
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using VVV = vector<VV>;
using VVVll = vector<VVll>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline int sz(T &x) { return x.size(); }
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int fLog2(const int x) { return 31-__builtin_clz(x); } // floor(log2(x))
inline int fLog2(const ll x) { return 63-__builtin_clzll(x); }
inline int cLog2(const int x) { return (x == 1) ? 0 : 32-__builtin_clz(x-1); } // ceil(log2(x))
inline int cLog2(const ll x) { return (x == 1) ? 0 : 64-__builtin_clzll(x-1); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
// const int MOD  = int(1e9)+7;
// const int MOD  = 998244353;


int main() {
  ll n; cin >> n;
  vector<string> rf = {
    "AC", "WA", "TLE", "RE"
  };

  V cnt(4);
  rep(i, n) {
    string s; cin >> s;
    rep(j, 4) if (s == rf[j]) ++cnt[j];
  }

  rep(j, 4) {
    cout << rf[j] << " x " << cnt[j] << '\n';
  }
  return 0;
}


Measured memory_bytes: 3652
#include <cstdio>
#include <cstring>
#include <set>

using namespace std;

char str[16];
char com[9];
set<long long> keys;

int getChar(char ch)
{
    if (ch == 'A') return 1;
    else if (ch == 'C') return 2;
    else if (ch == 'G') return 3;
    else if (ch == 'T') return 4;
    return 0;
}

long long getKey(char str[])
{
    long long sum = 0, p = 1;
    for (int i = 0; i < strlen(str); i++)
    {
        sum += p * (getChar(str[i]));
        p *= 5;
    }
    return sum;
}

bool find(char str[])
{
    return keys.find(getKey(str)) != keys.end();
}

void insert(char str[])
{
    keys.insert(getKey(str));
}

int main()
{
    int n;
    scanf("%d", &n);

    for (int i = 0; i < n; i++)
    {
        scanf("%s %s", com, str);

        if (com[0] == 'i')
            insert(str);
        else if (find(str))
            printf("yes\n");
        else
            printf("no\n");
    }

    return 0;
}

Measured memory_bytes: 13936
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	ll p[a];
	ll q[b];
	ll r[c];
	for(ll i=0;i<a;i++)
		cin>>p[i];
	for(ll i=0;i<b;i++)
		cin>>q[i];
	for(ll i=0;i<c;i++)
		cin>>r[i];
	sort(p,p+a,greater<ll>());
	sort(q,q+b,greater<ll>());
	vector<ll>final;
	for(ll i=0;i<x;i++)
		final.push_back(p[i]);
	for(ll i=0;i<y;i++)
		final.push_back(q[i]);
	for(ll i=0;i<c;i++)
		final.push_back(r[i]);
	sort(final.begin(),final.end(),greater<ll>());
	ll ans=0;
	for(ll i=0;i<(x+y);i++)
		ans+=final[i];
	cout<<ans;	
}


Measured memory_bytes: 8816
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <string>
#include <stack>
 
using namespace std;
 
#define f(i,a,b) for(int i=a;i<b;i++)
#define fll(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(ll int i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define vvi vector<vector<int>>
#define ss second
#define ff first
#define ll long long
#define lld long double
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pq priority_queue< int >
#define pqll priority_queue< ll >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define INF 1000000000
#define NINF -1000000000
 
ll maxll(ll a , ll b ){
    return a > b ? a : b;
}
 
ll minll(ll a , ll b){
    return a > b ? b : a;
}

// bool check(ll z){
//     ll temp = k;
//     // cout << z << endl;
//     f(i , 0 , n){
//         ll sub = (ll)z * a[i];
//         if (sub > b[i])
//         temp -= (sub -b[i]);
//         if (temp < 0){
//             return 0;
//         }
//     }
//         // cout << z << endl;
//     sol = z;
//         return 1;
// }


// To count Number of ones in a binary number
// int count_one(int x){
//     x = (x & (0x55555555)) + ((x >> 1) & (0x55555555));
//     x = (x & (0x33333333)) + ((x >> 2) & (0x33333333));
//     x = (x & (0x0f0f0f0f)) + ((x >> 4) & (0x0f0f0f0f));
//     x = (x & (0x00ff00ff)) + ((x >> 8) & (0x00ff00ff));
//     x = (x & (0x0000ffff)) + ((x >> 16) & (0x0000ffff));
//     // cout << x << endl;
//     return x;
// }


void solve(){
    int n;
    cin >> n;
    // vi a(3 , 0);
    vi dp(3,0);
    f( i , 0 , n){
        vi new_dp(3,0);
        vi c (3);
        for (int j = 0 ; j  < 3 ; j++){
            cin >> c[j];
        }
        for ( int k =0 ; k < 3 ; k++){
            for (int j = 0 ; j < 3 ; j++){
                if ( j != k){
                    new_dp[j] = max(new_dp[j] , dp[k] + c[j]);
                    // cout << new_dp[j] << " " ;
                }
            }
        }
        // cout << endl;
        dp = new_dp;
    }
    // cout << dp[0] << " " << dp[1] << " "<< dp[2];
    cout << max({dp[0] , dp[1] , dp[2]}) << endl;

	return ;
    
}

 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);
 
 
    // int t;
    // cin >> t;
    int t = 1;
    
    while(t--){
        
        solve();
    }
}

Measured memory_bytes: 3644
#----------------------------------------------------------
P = 10**9 + 7
N = 700000 #使う最大値+1以上にする、値に注意3*10^5とかにしとくと安心
inv = [0] + [1] # 1/x
finv = [1] + [1] # 1/x!
fac = [1] + [1] # x!
for i in range(2,N):
  inv += [inv[P % i] * (P - int(P / i)) % P]
  fac += [(fac[i-1] * i) % P]
  finv += [(finv[i-1] * inv[i]) % P]

def comb(a, b):
    if a<b:
        return -1 # error
    return (fac[a] * ((finv[b] * finv[a-b]) % P)) %P
#----------------------------------------------------------
x, y = map(int, input().split())
if (2*y-x)%3!=0 or (2*x - y)%3!=0:
    print(0)
    exit(0)
A = (2*y-x)//3
B = (2*x-y)//3
if A<0 or B<0:
    print(0)
    exit(0)
print(comb(A+B, A))


Measured memory_bytes: 86416
#include <iostream>

using namespace std;

int main()
{
    int R;
    cin >> R;
    if(R<1200)
    {
        cout << "ABC";
    }
    else if(R<2800)
    {
        cout << "ARC";
    }
    else
    {
        cout <<"AGC";
    }
    return 0;
}



Measured memory_bytes: 256
import itertools

N,M=map(int,input().split())
sw=[list(map(int,input().split())) for _ in range(M)]
p=[int(x) for x in input().split()]
ans=0

for i in itertools.product([0,1],repeat=N):
    onof=True
    #print(i)
    for j in range(M):
        counter=0
        #print(j)
        #print()
        for k in sw[j][1:]:
            counter+=i[k-1]
            #print(k)
        #print()
        
        if counter%2!=p[j]:
            onof=False
            break
    if onof:
        ans+=1
print(ans)

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

int main(){
    string S; cin >> S;
    if(S=="SUN") cout << 7;
    if(S=="MON") cout << 6;
    if(S=="TUE") cout << 5;
    if(S=="WED") cout << 4;
    if(S=="THU") cout << 3;
    if(S=="FRI") cout << 2;
    if(S=="SAT") cout << 1;
    
}

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

using namespace std;

int main()
{
    int a;
    cin>>a;
    string b;
    cin>>b;
    if(a>=b.length())
    {
        cout<<b<<endl;
    }
    else
    {
        for(int i=0; i<a; i++)
        {
            cout<<b[i];
        }
        cout<<"..."<<endl;
    }
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vii         vector<pair<ll int, ll int>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
//#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
#define N  1000000007 
#define MAXN   200005
int main()
{
ios_base::sync_with_stdio(false);
 cin.tie(0);
 cout.tie(0);
ll int n,k;
cin>>n>>k;
vi a(n);
rep(i,0,n)
cin>>a[i];
ll int dp[n+1];
rep(i,0,n+1)
dp[i]=0;
dp[2]=abs(a[1]-a[0]);
rep(i,3,n+1)
{
dp[i]=dp[i-1]+abs(a[i-1]-a[i-2]);
rep(j,2,k+1)
{if(i-j>=1)
dp[i]=min(dp[i],dp[i-j]+abs(a[i-1]-a[i-j-1]));}
}
cout<<dp[n];
}


Measured memory_bytes: 1792
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

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

	N, A, B := nextInt(), nextInt(), nextInt()
	if A > B {
		fmt.Println(0)
	} else if N == 1 {
		if A == B {
			fmt.Println(1)
		} else {
			fmt.Println(0)
		}
	} else {
		fmt.Println((N-2)*(B-A) + 1)
	}

}


Measured memory_bytes: 640
n = int(input())
t,a = map(int,input().split())

l=[t-j*0.006 for j in map(int,input().split())]
x = 0

for i in range(len(l)):
    if abs(l[i] - a) <= abs(l[x] - a):
        x = i

print(x+1)

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

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

  if((A==B && B!=C) || (A==C && A!=B) || (B==C && A!=B))  cout << "Yes" << endl;
  else  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include<math.h>
#include<bitset>
#include<iomanip>
using namespace std;

int main() {
	int N, M; cin >> N >> M;
	double ans = 0, t = 1900 * M+(N-M)*100;
	double p = pow(0.5, M);
	for (int i = 1; i < 1000; i++)ans += p * pow((1 - p), i-1)*i*t;
	cout << ans << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<stack>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
 
int main()
{
    stack<int> S1;
    stack< pair<int,int> > S2;
    char ch;
    int sum=0;
    for(int i=0;cin>>ch;i++)
    {
        if(ch=='\\') S1.push(i);
        else if(ch=='/' && S1.size()>0)
        {
            int j=S1.top();S1.pop();
            sum +=i-j;
            int a=i-j;
            while(S2.size()>0 && S2.top().first>j)
            {
                a+=S2.top().second;S2.pop();
            }
            S2.push(make_pair(j,a));
        }
    }
 
    vector<int> ans;
    while(S2.size()>0){
        ans.push_back(S2.top().second);
        S2.pop();
    }
    reverse(ans.begin(),ans.end());
    cout<<sum<<endl;
    cout<<ans.size();
    for(int i=0;i<ans.size();i++)
    {
        cout<<" ";
        cout<<ans[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3204
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int a[] = new int[n];
        for (int i = 0; i < k; i++) {
            int d = sc.nextInt();
            for (int j = 0; j < d; j++) {
                a[sc.nextInt() - 1]++;
            }
        }
        int ans = 0;

        for (int i = 0; i < n; i++) {
            if (a[i] == 0) {
                ans++;
            }
        }

        System.out.println(ans);
        sc.close();
    }
}

Measured memory_bytes: 46144
#include <stdio.h>

int main(void)
{
	int W,H,x,y,r;
	
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	
	if(x+r<=W && y+r<=H && x-r>=0 && y-r>=0) printf("Yes\n");
	else printf("No\n");
	
	return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
  int a,b,c,d,ans;
  cin >> a >> b >> c >> d;

  ans =  min(b,d)-max(a,c);

  if ( ans >= 0 ) cout << ans <<"\n";
  else cout << "0\n";
}


Measured memory_bytes: 888
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    while(1){
        int num;
        cin>>num;
        if(num==0)break;
        int numnum[4];
        int ans=0;
        while(1){
            if(num==6174){
                cout<<ans<<endl;
                break;
            }
            numnum[0]=num%10000/1000;
            numnum[1]=num%1000/100;
            numnum[2]=num%100/10;
            numnum[3]=num%10/1;
            if(numnum[0]==numnum[1]&&numnum[0]==numnum[2]&&numnum[0]==numnum[3]){
                puts("NA");
                break;
            }
            int nummax[4];
            int nummin[4];
            for(int i=0;i<4;i++){
                nummax[i]=numnum[i];
                nummin[i]=numnum[i];
            }
            sort(nummax,nummax+4);
            sort(nummin,nummin+4);
            swap(nummax[0],nummax[3]);swap(nummax[1],nummax[2]);
            int mx=nummax[0]*1000+nummax[1]*100+nummax[2]*10+nummax[3]*1;
            int mn=nummin[0]*1000+nummin[1]*100+nummin[2]*10+nummin[3]*1;
            //printf("[%d][%d]\n",mx,mn);
            num=mx-mn;
            ans++;
        }
    }
    return 0;
}

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

using namespace std;

int main(){
  int W,H,N;
  
  cin >> W >> H >> N;
  int S=W*H;
  int x0=0,y0=0;
  int x1=W,y1=H;
  for(int i=0;i<N;i++){
    int x,y,a;
    cin >> x >> y >> a;
    switch(a){
      case 1:
        if(x>x0)x0=x;
        break;
      case 2:
        if(x<x1)x1=x;
        break;
      case 3:
        if(y>y0)y0=y;
        break;
      case 4:
        if(y<y1)y1=y;
        break;
    }
  }
  if(x1<x0||y1<y0)cout << 0;
  else
    cout << (x1-x0)*(y1-y0);
}


Measured memory_bytes: 256
N, M = map(int, input().split())

H_list = list(map(int, input().split()))
route = {}

# 経路作成
for i in range(M):
    A, B = map(int, input().split())

    if A in route:
        route[A].append(B)
    else:
        route[A] = [B]

    if B in route:
        route[B].append(A)
    else:
        route[B] = [A]


def route_check(height, i):

    # チェック対象の高さの方が高い
    if height > H_list[i]:
        return True

    # 移動先の展望台のほうが高い
    elif height <= H_list[i]:
        return False


check = []

for h in range(1, N + 1):
    if h in route:
        if all([route_check(H_list[h - 1], i - 1) for i in route[h]]):
            check.append(h)
    else:
        check.append(h)

print(len(check))


Measured memory_bytes: 33612
N,K=map(int,input().split())
A=sorted(map(int,input().split()))

M=10**9+7

t,b=A[K-1]-A[N-K],1
for i in range(1,N-K+1):
  b=(b*(K-1+i)*pow(i,M-2,M))%M
  t=(t+b*(A[K-1+i]-A[N-K-i]))%M

print(t)


Measured memory_bytes: 14040
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep1(i, n) for(int i=1; i<(int)(n); i++)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> wi;

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

  int n;
  cin >> n;
  vi v(n), c(n);
  rep(i ,n)cin >> v[i];
  rep(i, n)cin >> c[i];

  int ans=0;
  rep(i, n)if(v[i]>c[i])ans+=v[i]-c[i];

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3604
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#pragma region Macros
#define FOR(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) FOR(i, 0, n)

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

template <class T> string join(const T &v, const string delim = ",")
{
    if (v.empty())
        return "";

    ostringstream res;
    res << v[0];
    for (int i = 1; i < v.size(); i++)
    {
        res << delim << v[i];
    }
    return res.str();
}

#pragma endregion Macros

int main()
{
    int ans;
    rep(i, 5) {
        int x;
        cin >> x;
        if(x==0){
            ans = i + 1;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3532
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main() {
  LL n, m;
  cin >> n >> m;
  vector<pair<LL, LL>> a(n);
  rep(i, n) {
    cin >> a[i].first >> a[i].second;
  }

  sort(all(a));
  priority_queue<LL> pq;
  LL ans = 0, x = 0;
  for (int i = m - 1; i >= 0; i --) {
    while (x < n) {
      if (i + a[x].first <= m) {
        pq.push(a[x].second);
        x ++;
      } else {
        break;
      }
    }
    if (!pq.empty()) {
      ans += pq.top();
      pq.pop();
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 2936
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


### 木の読み込み tree

# サイズが大きいとdefaultdictが早い(for文を書かなくて済む)
from collections import defaultdict
n = int(input())
ns = [[] for _ in range(n)]
for _ in range(n-1):
    u,v = map(int, input().split())
    u -= 1
    v -= 1
    ns[u].append(v)
    ns[v].append(u)
    
### BFS 幅優先探索

def bfs(start):
    from collections import deque
    q = deque([start])
    seen = [None] * n
    seen[start] = 0
    while q:
        u = q.pop()
        d = seen[u]
        for v in ns[u]:
            if seen[v] is None:
                seen[v] = d + 1
                q.appendleft(v)
    return seen
d1 = bfs(0)
d2 = bfs(n-1)
v = sum(d1[i]<=d2[i] for i in range(n))
v2 = n-v
if v>v2:
    print("Fennec")
else:
    print("Snuke")

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

int main() {
    int A, B, X;
    cin >> A >> B >> X;
    if (A <= X && X <= A + B) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
// lcmとかはg++ -std=c++17 default.cppみたいなかんじで
//vector<vector<ll>> piyo(tate,vector<ll> (yoko));

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1000000000
#define ll long long
#define ln cout<<endl;
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
ll target;

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

    ll maxi=0,f=0,mini=INF,sum=0;
    string str,str2;
    ll h,w;
    ll n,x,m;
    ll a,b,d,c;
    multiset<int> s;
    cin>>n;
    vector<ll> v(n);
    rep(i,n) cin>>v[i];
    vector<ll> z(n);
    for(ll i=1;i<n;i++){
        if(v[i-1]<v[i]) z[i]=0;
        else z[i]=z[i-1]+1;
    }
    cout<<*max_element(z.begin(),z.end());
    return 0;
}


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

#define int long long
#define forn(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int mod;
vector<vector<int>> g;
vector<int> dp;
vector<bool> used;
vector<int> ans;

void dfs1(int v) {
    used[v] = true;
    dp[v] = 1;
    for (int to: g[v]) {
        if (!used[to]) {
            dfs1(to);
            dp[v] *= dp[to] + 1;
            dp[v] %= mod;
        }
    }
}

void dfs2(int v, int cur) {
    ans[v] = dp[v] * cur % mod;
    used[v] = true;
    vector<int> sons;
    for (int to: g[v]) {
        if (!used[to]) {
            sons.push_back(to);
        }
    }
    vector<int> suf(sons.size() + 1, 1), pref(sons.size() + 1, 1);
    forn (i, sons.size()) {
        pref[i + 1] = pref[i] * (dp[sons[i]] + 1) % mod;
    }
    for (int i = sons.size() - 1; i >= 0; i--) {
        suf[i] = suf[i + 1] * (dp[sons[i]] + 1) % mod;
    }
    forn (i, sons.size()) {
        dfs2(sons[i], (cur * pref[i] % mod * suf[i + 1] % mod + 1) % mod);
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n >> mod;
    g.resize(n);
    dp.resize(n);
    ans.resize(n);
    forn (i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    used.assign(n, false);
    dfs1(0);
    used.assign(n, false);
    dfs2(0, 1);
    for (int i = 0; i < n; i++) {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 23980
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
    def height(self, x):
        return self.rank[x]

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)


def BFS(K,edges,N):
  roots=[ [] for i in range(N)]
  for a,b,c in edges:
    roots[a-1]+=[(b-1,c)]
    roots[b-1]+=[(a-1,c)]
  dist=[-1]*N
  stack=[]
  stack.append(K)
  dist[K]=0
  while stack:
    label=stack.pop(-1)
    for i,c in roots[label]:
      if dist[i]==-1:
        dist[i]=dist[label]+c
        stack+=[i]
  return dist

N = int(input())
edges=[]
for i in range(N-1):
  edges+=[list(map(int,input().split()))]

distance = BFS(0, edges, N)


ans = []
for i in range(N):
    if distance[i] % 2 == 0:
        ans.append(0)
    else:
        ans.append(1)

for c in ans:
    print(c)


Measured memory_bytes: 87640
#include <iostream>
#include <cassert>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <map>
#include <queue>
#include <sstream>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define mp(a,b) make_pair(a,b)
#define SZ(a) ((int)(a).size())
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
#define pb(a) push_back(a)
#define F first
#define S second
typedef pair<int,int> PI;

int n,m,c,s,g;

vector<PI> gr[20][100];

int gcost[100][100];

int pi[100];

int qi[100];
int ri[100];

int ctable[30000];

int sol(int comp){
  rep(i,pi[comp]-1) cin >> qi[i];
  rep(i,pi[comp]) cin >> ri[i];

  int ridx=0;
  for(int i=1;i<30000;++i){
    if(ridx < pi[comp]-1 && qi[ridx]<i)
      ++ridx;
    ctable[i] = ctable[i-1] + ri[ridx];
  }
  
  int ttt[n][n];
  rep(i,n) rep(j,n) ttt[i][j] = 1<<28;

  rep(i,n)FOR(it,gr[comp][i])
    ttt[i][it->F]=min(ttt[i][it->F],it->S);
  
  rep(k,n)rep(i,n)rep(j,n)
  ttt[i][j] = min(ttt[i][j],ttt[i][k]+ttt[k][j]);

  rep(i,n)rep(j,n)
    if(ttt[i][j]<(1<<28))
      gcost[i][j]=min(gcost[i][j],ctable[ttt[i][j]]);
  
}

void solve(){
  --s,--g;
  rep(i,20)rep(j,100) gr[i][j].clear();

  rep(i,m){
    int x,y,d,c;
    cin >> x >> y >> d >> c;
    --c,--x,--y;
    gr[c][x].pb(mp(y,d));
    gr[c][y].pb(mp(x,d));
  }

  rep(i,n)rep(j,n) gcost[i][j] = 1<<28;
  rep(i,c) cin >> pi[i];
  
  rep(i,c) sol(i);

  rep(k,n)rep(i,n)rep(j,n)
    gcost[i][j] = min(gcost[i][j],gcost[i][k]+gcost[k][j]);
  
  
  if(gcost[s][g]==(1<<28)) cout << -1 << endl;
  else cout << gcost[s][g] << endl;
}

int main(){
  while(cin >> n>>m>>c>>s>>g && n) solve();
}

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

    int main() {
        int h,w,i,j;
        char input[100][100];
        cin >> h >> w;
        for(int j=0;j<h;j++){
            for(int i=0;i<w;i++){
                cin >> input[i][j];
            }
        }
        for(j=0;j<h;j++){
            if(j==0){
                for(int k=0;k<w+2;k++)
                    cout << '#';
                cout << endl;
            }
            for(i=0;i<w;i++){
                if(i==0){
                    cout << '#' << input[i][j];
                }else{
                    cout << input[i][j];
                }
            }
            cout << '#' << endl;
            if(j==h-1){
                for(int k=0;k<w+2;k++)
                    cout << '#';
                cout << endl;
            }
        }
        }

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

int main(){
    while(1){
        int H,W;
        cin >> H >> W;
        if (H==0) break;
        
        else {
            for (int i=0;i<H;i++){
                for (int j=0;j<W;j++){
                    if ((i+j)%2 == 0) cout << "#";
                    else if ((i+j)%2 == 1) cout <<".";
                }
                cout << endl;
            }
            cout << endl;
        }
    }
    return 0;
}


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

int n, mx, mn = INT_MAX;
vector<int> a;
bool check() {
	if(mx == mn) return mx <= n/2 || mx == n-1;
	int cntmx = 0, cntmn = 0;
	for(int i = 0; i < n; i++) {
		cntmx += a[i] == mx;
		cntmn += a[i] == mn;
	}
	int mx_groups = cntmx >> 1;
	return mx_groups+cntmn >= mx && !(cntmx && mx-cntmn <= 0);
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for(int i = 0, x; i < n; i++) {
		cin >> x;
		mx = max(x, mx);
		mn = min(x, mn);
		a.push_back(x);
	}
	if(mx-mn > 1) cout << "No", exit(0);
	else cout << (check() ? "Yes" : "No");
}


Measured memory_bytes: 892
#define _CRT_SECURE_NO_WARNINGS
#define M_PI 3.14159265358979
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include<iomanip>
#include<vector>
#include<cmath>
#include <algorithm>

using namespace std;


int main()
{
	string str,reverse;
	cin >> str;

	for (int i = str.length()-1; i >-1; i--){
		reverse += str[i];
	}
	cout << reverse << endl;


	return 0;
}

Measured memory_bytes: 1176
def partition(A,p,r):
    x = A[r]
    i = p-1
    for j in range(r):
        if A[j] <= x:
            A[i], A[j] = A[j], A[i]
            i += 1
    A[i], A[r] = A[r], A[i]
    return i


n = int(input())
A = list(map(int, input().split()))

p = 1
r = len(A)-1
par = partition(A,p,r)
for i in range(n):
    if i<par or par<i<n-1:
        print(A[i],end=' ')
    elif i==par:
        print('[',end='')
        print(A[i],end='')
        print(']',end=' ')
    else:
        print(A[i])


Measured memory_bytes: 16388
import java.util.*;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int A  = keyboard.nextInt();
		int B  = keyboard.nextInt();
		
		int ans = -1;
		
		for(int i = 1; i<1500; i++) {
			if(Math.floor(i*0.08) == A && Math.floor(i*0.10) == B) {
				ans = i;
				break;
			} 
		}
				
		System.out.print(ans);
		keyboard.close();	
	}
}

Measured memory_bytes: 35752
# n<=3 より 1000までだから　全探索でOK
n, m = map(int, input().split())

# [[1, 7], [3, 2], [1, 7]]
sc = [list(map(int, input().split())) for i in range(m)]


def isValid(num):
    sn = str(num)
    # そもそも桁数が合っているか
    if len(sn) != n:
        return False
    for s, c in sc:
        # numの桁の数字と入力された数字の桁数が合っているか
        if sn[s-1] != str(c):
            return False
    return True

# 全探索
for i in range(1000):
    # 1番小さいものを見つけたら抜ける
    if isValid(i):
        print(i)
        exit()

# 見つからなければ-1出力
print(-1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  vi A(n);
  map<ll,ll>MP;
  for(auto &a:A){cin>>a;MP[a]++;}
  vi num;
  vi num2;
  for(auto a:MP){
    num.pb(a.S);
    num2.pb(a.F);
  }
  if(num.size()>3){
    cout<<"No"<<endl;
  }else if(num.size()==3){
    if(num[0]==num[1]&&num[1]==num[2]){
      if((num2[0]^num2[1]^num2[2])==0)
	cout<<"Yes"<<endl;
      else cout<<"No"<<endl;
    }else cout<<"No"<<endl;
  }else if(num.size()==2){
    if(num[0] == 2*num[1]){
      if(num2[1] == 0)cout<<"Yes"<<endl;
      else cout<<"No"<<endl;
    }else if(2*num[0] == num[1]){
      if(num2[0] == 0)cout<<"Yes"<<endl;
      else cout<<"No"<<endl;
    }else cout<<"No"<<endl;
  }else if(num.size()==1){
    if(num2[0]==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }else cout<<"No"<<endl;
  return 0;
}


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

#define INF (1LL << 31 - 1)
#define MOD int(1e9+7)
#define repi(i,j,n) for(int i = (j); i < (n); ++i)
#define rep(i,n) repi(i,0,n)
#define fi first
#define se second

inline void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int sx, sy, tx, ty;
string u = "U", d = "D", l = "L", r = "R";

int main() {
    cin >> sx >> sy >> tx >> ty;

    rep(i, tx - sx) {
        cout << r;
    }
    rep(i, ty - sy) {
        cout << u;
    }
    rep(i, tx - sx) {
        cout << l;
    }
    rep(i, ty - sy) {
        cout << d;
    }
    cout << d;
    rep(i, tx - sx + 1) {
        cout << r;
    }
    rep(i, ty - sy + 1) {
        cout << u;
    }
    cout << l;
    cout << u;
    rep(i, tx - sx + 1) {
        cout << l;
    }
    rep(i, ty - sy + 1) {
        cout << d;
    }
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<ll>())
#define prvsort(v) sort(v.begin(), v.end(), greater<pair<ll, ll>>())
#define ll long long
#define ld long double
#define fixset(val) fixed << setprecision(10) << val 
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define mod 1000000007
#define vfind(v, target) find(v.begin(), v.end(), target)
#define notFound(v, target) (vfind(v, target) == v.end())

using namespace std;

int main()
{
  ll X, Y; cin >> X >> Y;
  if (Y % 2 == 0 && Y >= 2 * X && Y <= 4 * X) {
  	cout << "Yes" << endl;
  } else {
  	cout << "No" << endl;
  }
}

Measured memory_bytes: 3632
#include <stdio.h>

int main()
{
	int S;

	scanf("%d", &S);

	int cnt = 4;
	int before = -1;
	bool bad = false;

	while (cnt--)
	{
		if (before == S % 10)
		{
			bad = true;
			break;
		}
		else
		{
			before = S % 10;
		}
		S /= 10;
	}

	if (bad) printf("Bad\n");
	else printf("Good\n");

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <bitset>

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

signed main() {

	std::string s;
	int x, y;
	std::cin >> s >> x >> y;
	s += 'T';

	std::vector<int> vx, vy;
	bool flag = true;
	bool first = true;
	int sum = 0;
	REP(i, s.size()) {
		if (s[i] == 'T') {
			if (first) {
				x -= sum;
			}
			else {
				if (sum) (flag ? vx : vy).emplace_back(sum);
			}
			sum = 0;
			flag = !flag;
			first = false;
		}
		else {
			++sum;
		}
	}

	REP(i, vx.size()) {
		x += vx[i];
		vx[i] *= 2;
	}
	REP(i, vy.size()) {
		y += vy[i];
		vy[i] *= 2;
	}

	auto subsetSum = [&](std::vector<int> a, int b) -> bool {
		if (b < 0) return false;
		if (b == 0) return true;
		if (a.empty()) return false;

		std::bitset<20004> bit;
		bit.set(0);

		REP(i, a.size()) {
			bit = bit | (bit << a[i]);
		}

		return bit[b];
	};

	std::cout << (subsetSum(vx, x) && subsetSum(vy, y) ? "Yes" : "No") << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
using namespace std;
pair<int, int>a[114514]; int n, m, ans = 1, cnt;
signed main() {
	cin >> n >> m;
	rep(i, m)cin >> a[i].first >> a[i].second;
	sort(a, a + m);
	cnt = a[0].second;
	for (int i = 1; i < m; i++) {
		if (a[i - 1].first == a[i].first)continue;
		if (cnt > a[i].second)cnt = a[i].second;
		if (cnt <= a[i].first) {
			ans++;
			cnt = a[i].second;
		}
	}
	cout << ans << endl;
	getchar(); getchar(); return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int llint
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define PI 3.1415926535897
#define EPS (1e-10)
#define INF INT_MAX
#define INFLL LLONG_MAX
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using MCI = std::map<char, int>;
using VPII = std::vector<PII>;
using namespace std;


int N, P;
MII fact;


void makeFact(){
	int n = P;
	repif(i, 2, i*i <= n)
		while(n%i == 0) n/=i, fact[i]++;
	if(n != 1) fact[n]++;
}


int solve(){
	int ans = 1;
	for(PII p : fact)
		rep(i, 0, p.second/N) ans *= p.first;
	return ans;
}


signed main(){
	cin >> N >> P;

	makeFact();

	cout << solve() << endl;

	return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kishan Sairam Adapa
 */

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define ll long long int
#define MOD ((int)(1e9) + 7)

using namespace std;

class BSomeSums {
public:
    void solve(istream& cin, ostream& cout) {
        int n, a, b;
        cin >> n >> a >> b;
        ll cnt=0;
        for(int i=1; i<=n; i++) {
            string d = to_string(i);
            int sum = 0;
            for(auto k: d) {
                sum += k - '0';
            }
            if(sum >= a && sum <=b) cnt+=i;
        }
        cout << cnt << '\n';
    }
};


int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    BSomeSums solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


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

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353 
#define MEM_SIZE 101010
#define DEBUG_OUT true

#define ALL(x) (x).begin(), (x).end()


template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solve(void)
{
  int n,k;cin>>n>>k;
  vector<int> a (n,0);
  vector<int> b (n,0);
  for (int i = 0; i < n; i++)
  {
    cin>>a[i]>>b[i];
  }
  int res = 0;
  for (int i = 0; i < n; i++)
  {
    bool ok = true;
    for (int j = 0; j <= 40; j++)
    {
      if(a[i]&(1LL<<j) and  !(k&(1LL<<j)))
      {
        ok = false;
      }
    }
    if(ok)res += b[i];
    
  }
  // DEBUG(res);

  for (int i = 40; i >= 0; i--) 
  {
    if(k & (1LL<<i))
    {
      int sum = 0;
      int t = k;
      t ^= (1LL<<i);
      for (int j = 0; j < i; j++)
      {
        t |= (1LL<<j);
      }
      // 0111111 0011111 00011111 0000111の全探索　始めてみた(´・ω・｀)
      for (int j = 0; j < n; j++)
      {
        bool ok = true;
        for (int kk = 0; kk <= 40; kk++)
        {
          if(a[j]&(1LL<<kk) && !(t&(1LL<<kk)))
          {
            ok = false;
          }
        }
        if(ok) sum += b[j];
        
      }
      // DEBUG(t,sum);
      chmax(res,sum);
      
      

    }
  }
  cout<<res<<endl;
  
  
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  // std::ios::sync_with_stdio(false);
  // std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 4824
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> P;

int main(void) {
  int N, M;
  cin >> N >> M;
  vector<P> stu(N);
  vector<P> check(M);
  for (int i = 0; i < N; i++) {
    long long a, b;
    cin >> a >> b;
    stu[i] = P(a, b);
  }
  for (int i = 0; i < M; i++) {
    long long c, d;
    cin >> c >> d;
    check[i] = P(c, d);
  }

  for (int i = 0; i < N; i++) {
    long long man = abs(check[0].first - stu[i].first) +
                    abs(check[0].second - stu[i].second);
    P ans = P(1, man);
    for (int j = 1; j < M; j++) {
      long long man = abs(check[j].first - stu[i].first) +
                      abs(check[j].second - stu[i].second);
      if (man < ans.second) {
        ans = P(j + 1, man);
      }
    }
    cout << ans.first << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <set>
#include <utility>
using namespace std;
#define foreach(i,n) for (int i = 0; i < n; ++i)
int dx[4] = { 0, 0, -1, 1 };
int dy[4] = { -1, 1, 0, 0 };
typedef set<int> seti;

#define MAX_H 20
#define MAX_W 20
#define EMPTY 0
#define BARRIER 1
#define START 2
#define GOAL 3
#define FAIL 100

int W, H;
bool barriers[MAX_H * MAX_W];
int goal;
int at(int w, int h) { return W * h + w; }
bool on_board(int x, int y) { return (0 <= x) && (x < W) && (0 <= y) && (y < H); }
bool barriered(const seti & broken, int x, int y) {
    int ix = at(x,y);
    return barriers[ix] && (broken.find(ix) == broken.end());
}
int solve(const seti & broken, int x, int y, int cnt) {
    int mcnt = FAIL;
    foreach (d,4) {
        if ((not on_board(x+dx[d], y+dy[d])) || barriered(broken, x+dx[d], y+dy[d])) { continue; }
        int nx = x, ny = y;
        while (true) {
            nx += dx[d]; ny += dy[d];
            if (not on_board(nx,ny)) break;
            if (barriered(broken,nx,ny)) {
                if (cnt == 10) break;
                seti nbroken = broken; nbroken.insert(at(nx,ny));
                mcnt = min(mcnt, solve(nbroken, nx-dx[d], ny-dy[d], cnt+1));
                break;
            }
            if (at(nx,ny) == goal) { return cnt; }
        }
    }
    return mcnt;
}

int main() {
    while (true) {
        cin >> W >> H; if (W * H == 0) break;
        int x, y;
        foreach (h,H) foreach (w,W) {
            int t; cin >> t;
            if (t == START) { x = w; y = h; t = EMPTY; }
            if (t == GOAL) { goal = at(w,h); t = EMPTY; }
            barriers[at(w,h)] = t == BARRIER;
        }
        int cnt = solve(seti(),x,y,1);
        cout << (cnt != FAIL ? cnt : -1) << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector < long long > vll;
typedef pair < long long, long long > pll;
typedef pair < int, int > pii;
typedef vector < int > vii;

#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,a,n) for(int i = a; i < n; i++)
#define INF (1e9 + 7)
#define pb push_back




int main(){

    int n,k;
    cin>>n>>k;
    vector<int> ar(n),dp(n);
    for(int i=0;i<n;i++){
        cin>>ar[i];
        dp[i]=INF;
    }
    dp[0]=0;
    for(int i=0;i<n;i++){
        for(int j=1;j<=k;j++){
            if(i+j<n) dp[i+j]=min(dp[i+j],dp[i]+abs(ar[i+j]-ar[i]));
        }
    }

    cout<<dp[n-1];

return 0;

}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
  // 入力
  int K;
  cin >> K;

  int suuretu[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

  cout << suuretu[K-1] << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}


int main(){
    int N; cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    //累積gcd
    vector<ll> right(N+1),left(N+1);
    rep(i,N) left[i+1] = GCD(left[i],A[i]);
    for(int i = N; i > 0; i--) right[i-1] = GCD(right[i],A[i-1]);

    ll ans = 0;
    rep(i,N){
        ll l = left[i];
        ll r = right[i+1];
        ans = max(ans,GCD(l,r));
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int N, K;
    cin >> N >> K;

    vector<int> total(N);
    REP(i, K) {
        int d;
        cin >> d;
        REP(j, d) {
            int tmp;
            cin >> tmp;
            total[tmp-1]++;
        }
    }

    int ans = 0;
    REP(i, N) if(total[i] == 0) ans++;

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3632
//
// Created by yamunaku on 2019/10/15.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

struct ku{
    ll l;
    ll r;
};

int main(){
    ll n;
    ll m;
    cin >> n >> m;
    vector<ku> a(n);
    map<ll,int> mp;
    rep(i,n){
        cin >> a[i].l >> a[i].r;
        mp[a[i].l]=0;
        mp[a[i].r]=0;
    }
    int sz = 0;
    for(auto &p: mp) p.second=sz++;
    sort(all(a),[](ku &l, ku &r){
        return l.l < r.l;
    });
    priority_queue<ll> q;
    ll now = 0;
    int idx = 0;
    ll ans = 0;
    while(now<m){
        while(idx<n){
            if(a[idx].l>now) break;
            q.push(a[idx].r);
            idx++;
        }
        ans++;
        now = q.top();
    }
    cout << ans << " ";
    vi v(sz);
    rep(i,n){
        v[mp[a[i].l]]++;
        v[mp[a[i].r]]--;
    }
    ll ans2 = n-v[0]+1;
    repl(i,1,sz-1){
        v[i]+=v[i-1];
        ans2=max(ans2,n-v[i]+1);
    }
    cout << ans2 << endl;
    return 0;
}



Measured memory_bytes: 33024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String[] hw = scanner.nextLine().split(" ");
		int height = Integer.parseInt(hw[0]);
		int width = Integer.parseInt(hw[1]);
		char[][] cellSts = new char[height + 2][width + 2];

		for (int wIdx = 1; wIdx <= width; wIdx++) cellSts[0][wIdx] = cellSts[height + 1][wIdx] = '.';
		for (int hIdx = 1; hIdx <= height; hIdx++) cellSts[hIdx] = ('.' + scanner.nextLine() + '.').toCharArray();

		boolean isPaintable = true;
LOOP:	for (int hIdx = 1; hIdx <= height; hIdx++) {
			for (int wIdx = 1; wIdx <= width; wIdx++) {
				if (cellSts[hIdx][wIdx]     == '#' &&
					cellSts[hIdx - 1][wIdx] == '.' &&
					cellSts[hIdx][wIdx - 1] == '.' &&
					cellSts[hIdx + 1][wIdx] == '.' &&
					cellSts[hIdx][wIdx + 1] == '.') {
					isPaintable = false;
					break LOOP;
				}
			}
		}

		if (isPaintable) System.out.println("Yes");
		else System.out.println("No");
	}
}


Measured memory_bytes: 24016