akhauriyash/Code-Regression huggingface dataset:
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (H, W, N): (usize, usize, usize) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };
    let (s_r, s_c): (usize, usize) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };
    let S: Vec<char> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().chars().collect()
    };
    let T: Vec<char> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().chars().collect()
    };

    // Nステップ目から1ステップ目まで順に駒が落ちる範囲を更新すればよい
    let (l, r) = (0..N).rev()
        .fold((0, W + 1), |(l, r), i| {
            let x = if S[i] != 'L' && l == 0 { 0 }
                else if S[i] == 'L' && l == 0 { 1 }
                else if S[i] != 'L' && T[i] == 'R' && 0 < l && l < r - 1 { l - 1 }
                else if (S[i] == 'L' && T[i] == 'R' && l > 0) ||
                        (S[i] != 'L' && T[i] != 'R') ||
                        (S[i] != 'L' && l == r - 1) { l }
                else { l + 1 };
            let y = if S[i] != 'R' && r == W + 1 { W + 1 }
                else if S[i] == 'R' && r == W + 1 { W }
                else if S[i] != 'R' && T[i] == 'L' && l + 1 < r && r < W + 1 { r + 1 }
                else if (S[i] == 'R' && T[i] == 'L' && r < W + 1) ||
                        (S[i] != 'R' && T[i] != 'L') ||
                        (S[i] != 'R' && r == l + 1) { r }
                else { r - 1 };
            (x, y)
        });
    let (u, d) = (0..N).rev()
        .fold((0, H + 1), |(u, d), i| {
            let x = if S[i] != 'U' && u == 0 { 0 }
                else if S[i] == 'U' && u == 0 { 1 }
                else if S[i] != 'U' && T[i] == 'D' && 0 < u && u < d - 1 { u - 1 }
                else if (S[i] == 'U' && T[i] == 'D' && u > 0) ||
                        (S[i] != 'U' && T[i] != 'D') ||
                        (S[i] != 'U' && u == d - 1) { u }
                else { u + 1 };
            let y = if S[i] != 'D' && d == H + 1 { H + 1 }
                else if S[i] == 'D' && d == H + 1 { H }
                else if S[i] != 'D' && T[i] == 'U' && u + 1 < d && d < H + 1 { d + 1 }
                else if (S[i] == 'D' && T[i] == 'U' && r < W + 1) ||
                        (S[i] != 'D' && T[i] != 'U') ||
                        (S[i] != 'D' && d == u + 1) { d }
                else { d - 1 };
            (x, y)
        });
    let ans = if l < s_c && s_c < r && u < s_r && s_r < d { "YES" } else { "NO" };

    println!("{}", ans);
}


Measured memory_bytes: 6396
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>

using namespace std;

int main(){

    int n;
    cin>>n;

    vector<string> s;

    for(int i=0;i<n;i++){
        string a;
        cin>>a;
        s.push_back(a);
    }

    sort(s.begin(),s.end());

    vector<pair<int,string>> p;

    int count=0;

    for(int i=0;i<n-1;i++){
        if(s[i]==s[i+1]){
            count++;
        }
        else{
            p.push_back(make_pair(count, s[i]));
            count=0;
        }
    }

    p.push_back(make_pair(count,s[n-1]));
    
    sort(p.begin(),p.end(),greater<pair<int,string>>());

    vector<string> c;
    c.push_back(p[0].second);

    for(int i=0;i<n-1;i++){
        if(p[0].first==p[i+1].first){
            c.push_back(p[i+1].second);
        }
        else{
            break;
        }
    }

    sort(c.begin(),c.end());

    for(int i=0;i<c.size();i++){
        cout<<c[i]<<endl;
    }
   
    return 0;
}


Measured memory_bytes: 21868
#pragma GCC optimize("Ofast")  
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long 
#define endl "\n"
#define all(x) (x).begin(),(x).end()
const int MOD = 1e9+7;
const int mxN = 2e5+3;

void solve(){
	int d, t, s;
	cin >> d >> t >> s;
	int dist = s * t;
	if(dist >= d)cout << "Yes\n";
	else cout << "No\n";
}

int32_t main(){
	IO;
	
	int nT = 1;
	//cin >> nT;
	for(int i = 1; i <= nT; ++i)
		solve();
	return 0;
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

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

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
  llong H, A;
  cin >> H >> A;

  cout << ceil(1.0*H/A) << endl;

  return 0;
}

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

int main() {
    int a1, a2, a3;
    cin >> a1 >> a2 >> a3;

    if(a1+a2+a3>=22) cout << "bust" << endl;
    else cout << "win" << endl; 
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<functional>
using namespace std;
int n, s[100], dp[100000];
int main() {
	dp[0] = 1; cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		for (int j = 90000; j >= 0; j--) {
			if (dp[j] == 1)dp[j + s[i]] = 1;
		}
	}
	int maxn = 0;
	for (int i = 0; i <= 90000; i++) { if (i % 10 != 0 && dp[i] == 1)maxn = max(maxn, i); }
	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s,t;
	cin>>s>>t;
	int n=s.size();
	int m=t.size();
	int dp[n+1][m+1];
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			dp[i][j]=0;
		}
	}
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			if(i==0||j==0){
				dp[i][j]=0;
				continue;
			}
			if(s[i-1]==t[j-1]){
				dp[i][j]=dp[i-1][j-1]+1;
				//ans[dp[i][j]-1]=s[i-1];
			}
			else{
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
			//cout<<dp[i][j]<<" ";
		}
		// /cout<<endl;
	}
	int index=dp[n][m];
	char ans[index+1];
	ans[index]='\0';
	index--;
	int i=n,j=m;
	while(i>0&&j>0){
		if(s[i-1]==t[j-1]){
			ans[index]=s[i-1];
			i--;
			j--;
			index--;
		}
		else if(dp[i][j]==dp[i][j-1]){
			j--;
		}
		else
			i--;
	}
	cout<<ans<<endl;
}

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

signed main(void)
{
	ll n, k, sum;
	cin >> n >> k;
	vector<ll> p(n);
	rep(i, n) cin >> p[i];
	sort(p.begin(), p.end());
	sum = 0;
	rep(i, k) sum += p[i];
	cout << sum << endl;
	return 0;
}


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

int main() {
	long N; cin >> N;
	
	long ans = 0;
	
	for( long i = 1; i*i <= N; i++ ){
		if( N % i == 0 && i < N/i - 1 )ans += N/i-1L;
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

const long long MOD = 1000000007;

void solve(long long N, std::vector<long long> a, std::vector<long long> b){
    vector<pair<int,int>> c;
    for(auto t: a) {
        c.push_back(make_pair(t, -1LL));
    }
    for(auto t: b) {
        c.push_back(make_pair(t, 1LL));
    }
    sort(ALL(c));

    int q = 0;
    int res = 1;
    for(int i = 0; i < c.size(); ++i) {
        if (q * c[i].second >= 0) {
            q += c[i].second;
        } else {
            res = (res * abs(q)) % MOD;
            q += c[i].second;
        }
    }
    cout << res << endl;
}

signed main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    std::vector<long long> b(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&b[i]);
    }
    solve(N, std::move(a), std::move(b));
    return 0;
}

Measured memory_bytes: 7920
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

int A, B, K;

int main() {
    cin >> A >> B >> K;

    for (int i =0; i < K; i++){
        B += A/2;
        A = A/2;
        
        i++;
        if (i >= K) break;
        
        A += B/2;
        B = B/2;
    }

    cout << A << endl << B << endl;
    return 0;
}

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

// using namespace std;

// #define lp(i,n) for(int i = 0; i <n;i++)
// #define all(x) (x).begin(),(x).end()
// #define pb push_back
// #define MP make_pair
// #define SZ(v) ((int)((v).size()))
// typedef long long ll;

// const ll MOD = 1e9 + 7;
// const int OO = (int)1e6;
// const int N = (int)1e7;

// void init(){
//     ios_base::sync_with_stdio(0);
//     cin.tie(0);
//     cout.tie(0);
// }
// int a[N];
// int acc[N];
// int main() {
// 	#   ifdef LOCAL_PROJECT
//         freopen("in.txt", "r", stdin);
//     #   endif
//     int k,n;
//     // scanf("%d %d",&k,&n);
//     // vector<ll>v;
//     // for(int i=0;i<n;i++){
//     //     scanf("%d",a+i);
//     // }
//     // ll rev_sum =0,ans=1e19;
//     // for(int i=n-2;i>=0;i--){
//     //     acc[i]=acc[i+1]+(a[i+1]-a[i]);
//     //     // cout<<acc[i]<<" "<<i<<endl;
//     // }
//     // for(int i=0;i<n;i++){
//     //     ll dist = acc[i]+rev_sum;
//     //     ans=min(ans,dist);
//     //     if(!i){
//     //         rev_sum+=(a[0]+k)-a[n-1];
//     //     }else {
//     //         rev_sum+=(a[i]-a[i-1]);
//     //     }
//     // }
//     // cout<<ans;
    
//     return 0;
// }
#include <bits/stdc++.h>

using namespace std;

#define lp(i,n) for(int i = 0; i <n;i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define SZ(v) ((int)((v).size()))
typedef long long ll;

const ll MOD = 1e9 + 7;
const int OO = (int)1e6;
const int N = (int)1e7;

void init(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int a[N];
int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
    int k,n;
    scanf("%d %d",&k,&n);
    vector<ll>v;
    for(int i=0;i<n;i++){
        scanf("%d",a+i);
    }
    for(int i=0;i<n-1;i++){
        v.push_back(abs(a[i]-a[i+1]));
    }
    // if(a[0]==0){
    //     v.push_back(abs(k-a[n-1]));
    // }else{
    //     v.push_back(abs(a[0]-a[n-1]));
    // }
    v.push_back(abs(a[0]+k-a[n-1]));
    sort(all(v));
    int idx = 0;
    ll sum =0;
    while(idx<n-1){
        sum+=1ll*v[idx++];
        
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 3188
#include<stdio.h>
int main()
{
    long long h,t,j,result;
    int i,x;
    while(scanf("%lld",&h)!=EOF)
    {
        x=1;t=h;//printf("%d\n",t);
        while(t>1)
        {
            t=t/2;
            x++;
        }
        j=1;result=0;
        for(i=0;i<x;i++)
        {
            result+=j;
            j=j*2;
        }

        printf("%lld\n",result);
    }
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;
int main(){
int a[3];
for(int i=0;i<4;i++)
cin>>a[i];
int b=a[0]+a[1];
int c=a[2]+a[3];
if(b>c)cout<<"Left";
if(b==c)cout<<"Balanced" ;
if(c>b)cout<<"Right";
return 0;
}

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

using ll = long long;

int main() {
    ll x;
    cin >> x;

    ll ans = (x / 11) * 2;
    if (x % 11 > 6) ans += 2;
    else if (0 < x % 11) ans++;

    cout << ans << endl;

    return 0;
}


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

namespace D_MSOL2020
{
    class MainClass
    {

        static int[] s, a;

        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            a = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);

            int n = s[0];

            var dp = new long[n + 1];

            dp[0] = 1000;

            for (int i = 1; i <= n; i++)
            {
                dp[i] = dp[i - 1];
                for (int j = 1; j <= i; j++)
                {
                    var stock = dp[j] / a[j - 1];
                    var val = a[i - 1] * stock;
                    val += dp[j] % a[j - 1];
                    dp[i] = Max(dp[i], val);
                }
            }
            WriteLine(dp[n]);



        }

        public static int LowerBound<T>(T[] a, T v)
        {
            return LowerBound(a, v, Comparer<T>.Default);
        }

        public static int LowerBound<T>(T[] a, T v, Comparer<T> cmp)
        {
            var l = 0;
            var r = a.Length - 1;
            while (l <= r)
            {
                var mid = l + (r - l) / 2;
                var res = cmp.Compare(a[mid], v);
                if (res == -1) l = mid + 1;
                else r = mid - 1;
            }
            return l;
        }
        public static int UpperBound<T>(T[] a, T v)
        {
            return UpperBound(a, v, Comparer<T>.Default);
        }

        public static int UpperBound<T>(T[] a, T v, Comparer<T> cmp)
        {
            var l = 0;
            var r = a.Length - 1;
            while (l <= r)
            {
                var mid = l + (r - l) / 2;
                var res = cmp.Compare(a[mid], v);
                if (res <= 0) l = mid + 1;
                else r = mid - 1;
            }
            return l;
        }
    }
}


Measured memory_bytes: 28024
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin>>s>>t;
  for(int i=0;i<s.size();i++){
    if(s[i]!=t[i]){
      char c=s[i];
      for(int j=0;j<s.size();j++){
        if(j<i){
          if(t[i]==s[j]){
            cout<<"No"<<endl;
            return 0;
          }
        }
        if(s[j]==c){
          s[j]=t[i];
        }else if(s[j]==t[i]){
          s[j]=c;
        }
      }
    }
  }
  cout<<(s==t?"Yes":"No");
}


Measured memory_bytes: 776
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int n;
    cin>>n;
    int c[4]={};int num=0;
    for(int i=0;i<n;i++){
        char a;cin>>a;
        if(a=='P'&&c[0]==0){c[0]++;num++;}
        else if(a=='W'&&c[1]==0){c[1]++;num++;}
        else if(a=='G'&&c[2]==0){c[2]++;num++;}
        else if(a=='Y'&&c[3]==0){c[3]++;num++;}
    }
    if(num==3)cout<<"Three"<<endl;
    else cout<<"Four"<<endl;
}


Measured memory_bytes: 256
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    s,w=map(int, readline().rstrip().split())
    if w>=s:
        print("unsafe")
    else:
        print("safe")
    #arr=list(map(int, readline().rstrip().split()))
    #n=int(readline())
    #ss=readline().rstrip()
    #yn(1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Measured memory_bytes: 16156
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int H = sc.nextInt();
            int W = sc.nextInt();
            if (H == 0 && W == 0) {
                break;
            } else {
                for (int i = 1; i <= H; ++i) {
                    for (int j = 1; j <= W; ++j) {
                        if (i == 1 || i == H) {
                            System.out.print("#");
                        } else if (j == 1 || j == W) {
                            System.out.print("#");
                        } else {
                            System.out.print(".");
                        }
                    }
                    System.out.print("\n");
                }
                System.out.print("\n");
            }
        }
    }
}


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

void solve()
{
    ll n,sum=0;
    cin>>n;

    for(int i=1;i<=n;i++)
    {
    if(i%15==0)
        continue;
    else if(i%3==0 || i%5==0)
    continue;
    else
        sum+=i;
    }
    cout<<sum;

}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    solve();
    return 0;
}


Measured memory_bytes: 3564
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 #include<deque>
 #include<functional>
 #include<utility>
 
 using namespace std;
 
 char arr[8][8];
 int dx[4]={1,0,-1,0};
 int dy[4]={0,-1,0,1};
 
 void dfs(int x,int y)
 {
   arr[x][y]='0';
   for(int step=1;step<=3;step++)
   {
     for(int i=0;i<4;i++)
     {
       if((x+step*dx[i]>=0)&&(x+step*dx[i]<8)&&(y+step*dy[i]>=0)&&(y+step*dy[i]<8))
       {
         int nx=x+step*dx[i];
         int ny=y+step*dy[i];
         if(arr[nx][ny]=='1')
         { 
           dfs(nx,ny);
           //cout<<nx<<" "<<ny<<endl;
         }                                                                    
       }        
     }        
   }     
   return;
 }
 
 int main()
 {
   int n;
   int count=1;
   cin>>n;
   while(n--)
   {
     string s;
     getline(cin,s);
     for(int i=0;i<8;i++)
     {
       cin>>s;
       for(int j=0;j<8;j++)
       {
         arr[i][j]=s[j];          
       }        
     }            
     int x,y;
     cin>>x>>y;
     dfs(y-1,x-1);
     cout<<"Data "<<count<<":"<<endl;
     for(int i=0;i<8;i++) 
     {
       for(int j=0;j<8;j++)
       {
         cout<<arr[i][j];        
       }        
       cout<<endl;
     }
     count++;
   }
   //while(1); 
   return 0;
 }

 
  

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <functional>
#include <utility>
#include <unordered_map>
#include <map>

#define INF 2147483647
#define INF_LL 9223372036854775807
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int N, M, R;
vector<int> visit;
vector<vector<int> > cost;
int ans = INF;
bool used[9] = { 0 };
void dfs(int c, int las, int dist) {
	if (c == R+1) {
		ans = min(ans, dist);
		return;
	}
	for (int i = 1; i < R+1; i++) {
		if (!used[i]) {
			used[i] = true;
			if (las == -1)dfs(c + 1, i, 0);
			else dfs(c + 1, i, dist + cost[visit[las]][visit[i]]);
			used[i] = false;
		}
	}
}
int main() {
	cin >> N >> M >> R;
	visit = vector<int>(R+1, 0);
	for (int i = 1; i < R+1; i++) cin >> visit[i];
	cost = vector<vector<int> >(N+1, vector<int>(N+1, INF/3));
	for (int i = 1; i < N+1; i++)cost[i][i] = 0;
	for (int i = 1; i < M+1; i++) {
		int A, B, C;
		cin >> A >> B >> C;
		if (cost[A][B] > C)cost[A][B] = cost[B][A] = C;
	}
	for (int k = 0; k < N+1; k++)
		for (int i = 0; i < N+1; i++)
			for (int j = 0; j < N+1; j++) cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
	dfs(1, -1, 0);
	cout << ans << endl;
	return 0;
}

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

namespace AtCoder.Abc
{
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var D = int.Parse(Console.ReadLine());
            var c = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            var s = new List<List<int>>();
            for (int i = 0; i < D; i++)
            {
                s.Add(Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList());
            }

            int[] last = new int[26];
            int res = 0;
            for (int i = 0; i < D; i++)
            {
                //var t = int.Parse(Console.ReadLine());
                int mx = 0;
                int mp = 0;
                for (int j = 0; j < 26; j++)
                {
                    var dif = GetDiff(s, c, last, i, j);
                    if (mx < dif)
                    {
                        mx = dif;
                        mp = j;
                    }
                }
                res += mx;
                last[mp] = i + 1;
                Console.WriteLine(mp+1);
            }

            Console.Out.Flush();
        }

        public static int GetDiff(List<List<int>> s, int[] c, int[] last, int day, int pat)
        {
            int av = s[day][pat];
            int sv = 0;
            for (int i = 0; i < 26; i++)
            {
                if (i == pat) continue;
                sv += (((day + 1) - last[i]) * c[i]);
            }
            return av - sv;
        }
    }
}


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

int main()
{
  int N,M;
  cin >> N >> M;
  int A = 0,B = 0,C = 0;
  int max = 0;
  int m = 0;
  for(int i = 0; i < M; i++){
      cin >> A >> B;
      if(A < N){
          C = B - N;
          if(C > max){
              max = C;
          }
        m += C;
      }
  }
  int o = m - max;
  cout << o << endl;
  return 0;
      
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) { a = b; return 1; }
  return 0; }
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) { a = b; return 1; }
  return 0; }

int main(void){
  double a,b,x; cin >> a >> b >> x;
  if(x >= b*a*a/2){
    cout << fixed << setprecision(10);
    cout << atan(2*(a*a*b-x)/(a*a*a))*180/3.141592653589 << endl;
  }
  else{
    cout << fixed << setprecision(10);
    cout << atan((b*b*a)/(2*x))*180/3.141592653589 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
def gcd(a,b):#最大公約数を返す。Euclid
    if a<b:
        a,b=b,a
    c=a%b
    if c==0:
        return b
    return gcd(b,c)
A,B,C,D=map(int,input().split())
if A%C==0:
    #nc=int(B/C)-int(A/C)+1
    nc=B//C-A//C+1
else:
    #nc=int(B/C)-int(A/C)
    nc=B//C-A//C
if A%D==0:
    #nd=int(B/C)-int(A/C)+1
    #nd=int(B/D)-int(A/D)+1
    nd=B//D-A//D+1
else:
    #nd=int(B/D)-int(A/D)
    nd=B//D-A//D
cd=int(C*D/gcd(C,D))
if A%cd==0:
    #ncd=int(B/cd)-int(A/cd)+1
    ncd=B//cd-A//cd+1
else:
    #ncd=int(B/cd)-int(A/cd)
    ncd=B//cd-A//cd
#print("nc,nd,ncd",nc,nd,ncd)
print(B-A+1-nc-nd+ncd)


Measured memory_bytes: 3064
#include <iostream>
#include <array>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <utility>

#include <atcoder/convolution>

using namespace std;
using namespace atcoder;
#define rep(i,l,r) for(int i = l; i < r; ++i)

int main() {
    int n, m;
    cin >> n >> m;

    vector<long long> a(n), b(m);
    rep(i, 0, n) cin >> a[i];
    rep(i, 0, m) cin >> b[i];

    auto c = convolution(a, b);

    for(auto e : c) cout << e << ' ';
    cout << endl;
}


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

int main() {
	int n;
	int ans = 0;
	int temp = 0;
	cin >> n;
	int *a = new int [n];

	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (temp <= a[i]) {
			temp = a[i];
			ans++;
		}
	}
	cout << ans << endl;
}

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

    n_min = 0
    n_max = N-1

    print(n_min)
    tmp_min = input()
    if tmp_min == 'Vacant':
        exit()

    print(n_max)
    tmp_max = input()
    if tmp_max == 'Vacant':
        exit()

    while True:
        n_mid = (n_min + n_max) // 2
        print(n_mid)
        tmp_mid = input()
        if tmp_mid == 'Vacant':
            exit()
        if (n_mid - n_min) % 2 == 0:
            if tmp_min == tmp_mid:
                n_min = n_mid
                tmp_min = tmp_mid
            else:
                n_max = n_mid
                tmp_max = tmp_mid
        else:
            if tmp_min == tmp_mid:
                n_max = n_mid
                tmp_max = tmp_mid
            else:
                n_min = n_mid
                tmp_min = tmp_mid


if __name__ == "__main__":
    main()


Measured memory_bytes: 3660
import java.util.Scanner;

public class Main {
    public static void debug(String str) {
        System.out.println(str);
    }

    public static void main(String[] args) {

        int A, B;

        try (Scanner sc = new Scanner(System.in)) {
            A = sc.nextInt();
            B = sc.nextInt();

        }

        if (A < B * 2) {
            System.out.println(0);

        } else {
            System.out.println(A - B * 2);
        }
    }

}


Measured memory_bytes: 23764
def make_set(x, disjoint):
    disjoint[x] = x

def find_set(x, disjoint):
    if x not in disjoint.keys():
        make_set(x, disjoint)
    if x != disjoint[x]:
        disjoint[x] = find_set(disjoint[x], disjoint)
    return disjoint[x]

def link(x, y, disjoint):
    disjoint[y] = x

def unite(x, y, disjoint):
    link(find_set(x, disjoint), find_set(y, disjoint), disjoint)

def same(x, y, disjoint):
    if find_set(x, disjoint) == find_set(y, disjoint):
        return 1
    return 0

n, q = list(map(int, input().split()))
com_list = list()
x_list = list()
y_list = list()

for _ in range(q):
    com, x, y = list(map(int, input().split()))
    com_list.append(com)
    x_list.append(x)
    y_list.append(y)

disjoint = dict()

for i in range(q):
    com = com_list[i]
    x = x_list[i]
    y = y_list[i]

    if com == 0:
        unite(x, y, disjoint)
    else:
        print(same(x, y, disjoint))

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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main(){
    ll n;
    cin >> n;
    ll ans = 0;
    for(ll i = 1; i <= n; i++){
        if(i%3!=0&&i%5!=0){
            ans += i;
        }
    }
    cout << ans << endl;
    return 0;
}  


Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
typedef long long ll;
int main(){
    string N;
    cin >> N;
    cout << "ABC"+N << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using pLL = std::pair<long long, long long>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b;
	cin >> a>> b;
	if(!(a%b)) cout << 0 << endl;
	else cout << 1 << endl;
	return 0;
}

Measured memory_bytes: 256
// template {{{

#include <bits/stdc++.h>

// #define int long long

#define GET_MACRO(a, b, c, d, NAME, ...) NAME
#define REP2(i, n) REP3(i, 0, n)
#define REP3(i, a, b) REP4(i, a, b, 1)
#define REP4(i, a, b, s) for (int i = (a); i < (int)(b); i += s)
#define RREP2(i, n) RREP(i, 0, n)
#define RREP3(i, a, b) for (int i = (b) - 1; i >= (int)(a); i--)

#define rep(...) GET_MACRO(__VA_ARGS__, REP4, REP3, REP2)(__VA_ARGS__)
#define rrep(...) GET_MACRO(__VA_ARGS__, RREP3, RREP2)(__VA_ARGS__)
#define eb emplace_back
#define ef emplace_front
#define pb pop_back
#define pf pop_front
#define all(c) std::begin(c), std::end(c)
#define mp std::make_pair
#define mt std::make_tuple
#define fi first
#define se second
#define popcnt __builtin_popcountll

using uint = unsigned;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = std::vector<int>;
using vvi = std::vector<vi>;

template<typename T>
using maxpq = std::priority_queue<T, std::vector<T>, std::less<T>>;

template<typename T>
using minpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 10;
const ll LLINF = 1e18 + 10;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
const int dx8[] = {-1, -1, 0, 1, 1, 1, 0, -1};
const int dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
inline T sq(T x){ return x * x; }

template<typename T, typename U>
inline bool chmax(T &x, U y){ if (x >= y) return false; x = y; return true; }

template<typename T, typename U>
inline bool chmin(T &x, U y){ if (x <= y) return false; x = y; return true; }

template<typename T>
inline void sort(T &c){ std::sort(std::begin(c), std::end(c)); }

template<typename T>
inline void reverse(T &c){ std::reverse(std::begin(c), std::end(c)); }

template<typename T>
inline void unique(T &c){ std::sort(std::begin(c), std::end(c)); c.erase(std::unique(all(c)), std::end(c)); }

using namespace std;

// }}}

int main()
{
	string s;
	cin >> s;
	int res = 0;
	rep(i, 0, s.size()){
		string sa(s, 0, i);
		string sb(s, i, s.size() - i);
		ll a = sa.size() ? stoi(sa) : 0;
		ll b = stoi(sb);
		if (sb.size() > 1 && sb[0] == '0') continue;
		if ((a + b) & 1) continue;
		ll x = (a + b) / 2;
		ll y = b - x;
		if (x >= 0 && y >= 0) res++;
	}
	cout << res << endl;
}

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

int main(){
  int n;
  cin >> n;
  vector<vector<int>> data(9, vector<int>(9));
  string ans = "No";
  rep(i,9){
    rep(j,9){
      int a;
      a = (i+1) * (j+1);
      data[i][j] = a;
    }
  }
  rep(i,9){
    rep(j,9){
      if( n == data[i][j] ) ans = "Yes";
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

int n, r, c, cnt;
int dest[110000];

void ng(){
    cout <<  -1 << endl;
    exit(0);
}


int main(){
    cin >> n;
    fill(dest, dest + n, -1);
    for(int i = 0;i < n;i++){
        cin >> r >> c;r--,c--;
        if(dest[r] != -1)ng();
        dest[r] = c;
    }
    for(int i = 0;i < n;i++){
        if(dest[i] == -1)ng();
        while(dest[i] != i){
            swap(dest[dest[i]], dest[i]);
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 3508
H, W, N = map(int, input().split())
sr, sc = map(int, input().split())
S = input()
T = input()

l = sc
r = W -sc + 1
u = sr
d = H - sr + 1

s = [0] * 4
ans = 'YES'
for i in range(N):
    if S[i] == 'L':
        l -= 1
        if r == W:
            r -= 1
    elif S[i] == 'R':
        r -= 1
        if l == W:
            l -= 1
    elif S[i] == 'U':
        u -= 1
        if d == H:
            d -= 1
    elif S[i] == 'D':
        d -= 1
        if u == H:
            u -= 1

    if l*r*u*d <= 0:
        ans ='NO'
        break

    if T[i] == 'L' and r < W:
        r += 1
    elif T[i] == 'R' and l < W:
        l += 1
    elif T[i] == 'U' and d < H:
        d += 1
    elif T[i] == 'D' and u < H:
        u += 1
print(ans)

Measured memory_bytes: 45216
use std::io::{stdin, BufRead};
fn main() {
    let stdin = stdin();
    let stdinlock = stdin.lock();
    let mut input = stdinlock.lines();
    let n: usize = input
        .next()
        .expect("read")
        .expect("n")
        .parse()
        .expect("parse");
    let s = input.next().expect("line").expect("s");
    let r = input.next().expect("line").expect("s");
    println!("{}", solve(n, &s, &r,));
}

fn solve(n: usize, s: &str, r: &str) -> usize {
    for drops in 0..n {
        if s[drops..] == r[..n - drops] {
            return n + drops;
        }
    }
    n * 2
    // n * 2
    //     - s.chars()
    //         .zip(r.chars().rev())
    //         .take_while(|(a, b)| a == b)
    //         .count()
}


Measured memory_bytes: 2076
#include <bits/stdc++.h>
#define MAXN 1010

using namespace std;

int p[MAXN];
long long v[MAXN], dp[110][100010];

long long res(int i, int n, int w){
	if(i == n) return 0;
	if(dp[i][w] != -1) return dp[i][w];
	long long n_pega = res(i+1, n, w), pega = 0;
	if(w >= p[i]){
		// cout << w << endl;
		pega = v[i] + res(i+1, n, w-p[i]);
	}
	return dp[i][w] = max(n_pega, pega);
}

int main(){
	int n, w;
	memset(dp, -1, sizeof(dp));
	cin >> n >> w;
	for(int i = 0;i < n;++i){
		cin >> p[i] >> v[i];
	}
	cout << res(0, n, w) << endl;
}

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

int main() {
	
	int a[14];
	
	for(int i=0;i<14;i=i+2){
		cin >> a[i] >> a[i+1] ;
		cout << a[i]-a[i+1] << endl;
		
	}
	
	return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define int int64_t
#define pcnt __builtin_popcount
#define pb push_back
#define ALL(x) (x).begin(),(x).end()
#define vec vector<int>
#define mat vector<vector<int>> //mat データ名(縦,vec(横));
int INF = 1000000000000000001; //10^18+1
int MOD = 1000000007; //10^9+7
//cout << fixed << setprecision(15); (小数点以下表示)

signed main () {
  int N,M,ans,a,b;
  cin >> N >> M;
  ans=N;
  vec H(N),A(M),B(M),good(N,1);
  for(int i=0;i<N;i++)cin >> H.at(i);
  for(int i=0;i<M;i++)cin >> A.at(i) >> B.at(i);
  for(int i=0;i<M;i++){
    a=A.at(i)-1;
    b=B.at(i)-1;
    if(H.at(a)>=H.at(b)&&good.at(b)==1){
      good.at(b)=0;
      ans--;
    }
    if(H.at(a)<=H.at(b)&&good.at(a)==1){
      good.at(a)=0;
      ans--;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 6360
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
int main() {
    int s, w; cin >> s >> w;
    if(s <= w) cout << "unsafe" << endl;
    else cout << "safe" << endl;
}

Measured memory_bytes: 3652
from sys import stdin
import sys
sys.setrecursionlimit(10000)
import functools
from functools import lru_cache

#from math import gcd

@lru_cache(maxsize=1000000)
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

def gcdn(nums):
    return functools.reduce(gcd, nums)

@lru_cache(maxsize=1000000)
def gcd3(a,b,c):
   return gcd(gcd(a,b),c)

n = int(stdin.readline().rstrip())

sum = 0
for i in range(n):
    sum += (i+1)
    for j in range(i+1,n):
        sum += 6*gcd(i+1,j+1)
        for k in range(j+1,n):
            #a,b,c = sorted((i+1,j+1,k+1))
            a,b,c = (i+1,j+1,k+1)
            sum += 6*gcdn((a,b,c))

print(sum)


Measured memory_bytes: 80240
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Arrays;
import java.util.Comparator;

public class Main {

  public static void main(String[] args) {

    int[] cookingTime = new int[5];
    int[][] diff = new int[5][2];
    try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
      for (int i = 0; i < 5; i++) {

        BigDecimal tmp = new BigDecimal(br.readLine());
        cookingTime[i] = tmp.intValue();

        tmp = tmp.setScale(-1, RoundingMode.UP);
        diff[i][0] = tmp.intValue() - cookingTime[i];
        diff[i][1] = i;
      }
    } catch (IOException e) {
      e.printStackTrace();
      System.exit(1);
    }

    Comparator comparator = new Comparator() {
      @Override
      public int compare(Object o1, Object o2) {
        final int index = 0;

        int[] numA = (int[]) o1;
        int[] numB = (int[]) o2;
        return (Integer.compare(numA[index], numB[index]));
      }
    };

    Arrays.sort(diff, comparator);

    int sum = 0;
    for (int i = 0; i < diff.length; i++) {
      final int idx = diff[i][1];

      if (i < diff.length - 1) {
        BigDecimal tmp = new BigDecimal(cookingTime[idx]).setScale(-1, RoundingMode.UP);
        sum += tmp.intValue();
      } else {
        sum += cookingTime[idx];
      }
    }
    System.out.print(sum);

  }
}


Measured memory_bytes: 23636
// AOJ ALDS1_10_C: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_C

package main

import (
	"fmt"
)

func main() {
	var dataNum int
	var s1, s2 string

	fmt.Scanf("%d", &dataNum)

	for i := 0; i < dataNum; i++ {
		fmt.Scanf("%s", &s1)
		fmt.Scanf("%s", &s2)

		lcs := make([][]int, len(s1)+1)
		for j := 0; j < len(s1)+1; j++ {
			lcs[j] = make([]int, len(s2)+1)
		}

		for m, vs1 := range s1 {
			for n, vs2 := range s2 {
				if vs1 == vs2 {
					lcs[m+1][n+1] = lcs[m][n] + 1
				} else if lcs[m+1][n] > lcs[m][n+1] {
					lcs[m+1][n+1] = lcs[m+1][n]
				} else {
					lcs[m+1][n+1] = lcs[m][n+1]
				}
			}
		}

		// Answer
		fmt.Println(lcs[len(s1)][len(s2)])
	}
}


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

int main(){
  int r, d, first;
  cin >> r >> d >> first;
  vector<long long int> x(11);
  x.at(0) = first;
  rep(i, 10){
    x[i+1] = r*x[i] - d;
    cout << x[i+1] << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) 
{
  int a, b;
  scanf("%d %d", &a, &b); // 不要像谭浩强那本书一样, %d中间加逗号, 因为题目给出的样例输入中, 是以空格作为分隔的
  printf("%d %d\n", a * b, 2 * (a + b)); // 最后记得换行, 不然会出现格式错误
  return 0; // 这个是可有可无的
}


Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int D;
  cin >> D;
  if(D==25) cout << "Christmas" << endl;
  else if (D==24) cout << "Christmas Eve"<< endl;
  else if (D==23) cout << "Christmas Eve Eve"<< endl;
  else if (D==22) cout << "Christmas Eve Eve Eve"<< endl;
  
  return 0;
    

}


Measured memory_bytes: 256
/*ITP1_3_C.c*/
#include<stdio.h>
int main(void){
   int a[3000],b[3000],i,j;
   for(i=1;i>=1;i++){
      scanf("%d %d",&a[i],&b[i]);
      if(a[i]==0 && b[i]==0){
         break;
      }
   }
   for(j=2;j<=i;j++){
      if(a[j-1]<b[j-1]){
         printf("%d %d\n",a[j-1],b[j-1]);
      }
      else{
         printf("%d %d\n",b[j-1],a[j-1]);
      }
   }
   return 0;
}

Measured memory_bytes: 1744
//g++  7.4.0

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
    string s; cin>>s;
    ll N = s.length();
    ll sum = 0;
    
    for(ll i=0;i<N;++i)
        sum += (s[i] - '0');
    
    if(sum%9 == 0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1e9;
const int MOD = 1e9+7;

void print() { cout << endl; }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head << ((sizeof...(tail)!=0)?" ":""); print(forward<Tail>(tail)...); }
template <class T> void print(vector<T> &vec) { for (auto& a : vec) { cout << a << ((&a!=&vec.back())?" ":""); } cout << endl; }
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec); } }

int dp[1010][1010];

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

    int n; cin >> n;
    rep(_, n) {
        string s, t; cin >> s >> t;
        memset(dp, 0, sizeof(dp));
        int n = s.length(), m = t.length();
        rep(i, n) rep(j, m) {
            char a = s[i], b = t[j];
            if (a==b) dp[i+1][j+1] = dp[i][j]+1;
            else dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
        }

        cout << dp[n][m] << endl;
    }
}


Measured memory_bytes: 7204
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int h,w;
vs a;

int main(){
	cin>>h>>w;
	a=vs(h);
	for(int i=0;i<h;i++) cin>>a[i];
	bool flag=1;
	for(int i=0;i<h;i++) for(int j=0;j<w;j++) if(a[i][j]=='#'){
		bool B=0;
		for(int k=0;k<4;k++){
			int x=i+dx[k],y=j+dy[k];
			if(x>=0&&x<h&&y>=0&&y<w&&a[x][y]=='#') B=1;
		}
		flag&=B;
	}
	cout<<(flag?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(void){
    int n;
    ll t;
    cin>>n>>t;
    vector<ll> v(n);
    unordered_map<ll, ll> mp;
    rep(i, n) {
        cin>>v[i];
        mp[v[i]]++;
    }
    vector<ll> vmax(n);
    vector<ll>div(n);
    vmax[n-1] = 0;
    div[n-1] = -v[n-1];
    ll maxdiv = div[n-1];
    for(int i = n-2;i>=0;i--){
        vmax[i] = max(vmax[i+1], v[i+1]);
        div[i] = vmax[i]-v[i];
        maxdiv=max(div[i], maxdiv);
    }
    vector<bool> use(1e9+5, false);
    ll ans = 0;
    rep(i, n){
        if(div[i] == maxdiv){
            if(use[v[i]] == false)  {
                ans += min(mp[v[i]], mp[vmax[i]]);
                use[v[i]] = true;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 128804
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    string s ;
    cin>>s;
    if (s[s.size()-1]=='s'){
        s+="es";
        cout<<s<<endl;
    }
    else {s+="s";
        cout<<s<<endl;
        
    }
    return 0;
}


Measured memory_bytes: 3600
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()

    count = 0
    for i, c in enumerate(S):
        if i % 2 == int(c):
            count += 1

    print(min(count, len(S) - count))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9232
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

class Program
{
    static void Main()
    {
        var sc = new Scanner();

        var ring = sc.String();
        int n = sc.Int();
        sc.StringArray(n)
            .Select(x => x + x)
            .Where(x => x.Contains(ring))
            .Count()
            .Print();

        Console.ReadKey();
    }
}

static class Extensions
{
    public static IEnumerable<T> Output<T>(this IEnumerable<T> source)
    {
        foreach (var item in source)
        {
            Console.WriteLine(item);
        }
        return source;
    }

    public static T Print<T>(this T obj)
    {
        Console.WriteLine(obj);
        return obj;
    }
}

public class Scanner
{
    public Scanner()
    {
        byte[] inputBuffer = new byte[1024];
        System.IO.Stream inputStream = Console.OpenStandardInput(inputBuffer.Length);
        Console.SetIn(new System.IO.StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length));
    }
    string[] buffer = new string[0];
    int index = 0;
    public char[] SplitChars { get; set; }
    public string String()
    {
        if (index < buffer.Length) return buffer[index++];
        string line = "";
        while (line == "") line = Console.ReadLine();
        if (line == null) return null;
        buffer = line.Split(SplitChars, StringSplitOptions.RemoveEmptyEntries);
        index = 0;
        return buffer[index++];
    }
    public string[] StringArray(int count) { return NextArray(count, x => x); }
    public void Skip(int count) { for (int i = 0; i < count; i++) String(); }
    public T Next<T>(Func<string, T> parser) { return parser(String()); }
    public T[] NextArray<T>(int count, Func<string, T> parser)
    {
        var arr = new T[count];
        for (int i = 0; i < count; i++) arr[i] = Next(parser);
        return arr;
    }
    public int Int() { return Next(int.Parse); }
    public int[] IntArray(int count) { return NextArray(count, int.Parse); }
    public double Double() { return Next(double.Parse); }
    public double[] DoubleArray(int count) { return NextArray(count, double.Parse); }
}

Measured memory_bytes: 10112
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int[] arr = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = sc.nextInt();
			}
			Arrays.sort(arr);

			int total = 0;
			boolean flg = false;
			for (int i : arr) {
				total += i;
				if (i % 10 != 0) {
					flg = true;
				}
			}
			if (total % 10 != 0) {
				System.out.println(total);
				return;
			}
			if (!flg) {
				System.out.println(0);
				return;
			}

			ArrayList<Integer> list = new ArrayList<Integer>(arr.length);
			for (int i : arr) {
				list.add(i);
			}

			System.out.println(check(total, list));
		}
	}

	private static int check(int base, ArrayList<Integer> list) {
		for (int i : list) {
			int tmp = base - i;
			if (tmp % 10 != 0) {
				return tmp;
			}
		}
		int result = 0;
		for (int i = 0; i < list.size(); i++) {
			ArrayList<Integer> list2 = (ArrayList<Integer>)list.clone();
			list2.remove(i);
			int tmp = check(base - list.get(i), list2);
			if (result < tmp) {
				result = tmp;
			}
		}

		return result;
	}
}

Measured memory_bytes: 22996
#include <stdio.h>

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

  int max = a[0], min = a[0];
  for(int i = 1; i < N; i++){
    if(max < a[i]) max = a[i];
    if(min > a[i]) min = a[i];
  }
  printf("%d\n", max - min);
  return 0;
}
  
  
  


Measured memory_bytes: 128
#include<stdio.h>
//#include <utility>
void score_sum(int n,int m,int score[]){
	int L[1005][55];
	for(int i=0;i<m;++i)
		for(int j=0;j<n;++j){
			scanf("%d",&L[i][j]);
			score[j]+=L[i][j];}
}
int bub(int L[],int len){
	int max=-1;
	for(int i=0;i<len;++i)
		if(L[i]>max) max=L[i];
	return max;}
int main(){
	int n,m;
	int score[1005];
	while(1){
		memset(score,0,sizeof(score));
		scanf("%d%d",&n,&m);
		if(n&&m) {
			score_sum(n,m,score);
			printf("%d\n",bub(score,n));}
		else break;}
	return 0;
}


Measured memory_bytes: 2112
program example
	implicit none
    
    integer(16) A,B,N
    
    read(*,*) N,A,B
    
    if(mod(B-A,2)==0) then
    
    	write(*,*)  (B-A)/2
            
    else
 		write(*,*) min(N-B,A-1)+1+((B-A-1)/2)
    end if

end program example

Measured memory_bytes: 512