akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

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=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

//1からNまでの総和s
int main(){
    ll N,ans;
    cin >> N;
    ans = N * (N -1) / 2;

    cout << ans << endl;
    
}

Measured memory_bytes: 3596
#include<stdio.h>
#include<string.h>

int main(){

	char s[30],t[25];
	scanf("%s",&s);
	scanf("%s",&t);
	//gets(s);
//gets(t);
	int length=strlen(s);
	int count=0;
	for(int i=0;i<length;i++){

		if(s[i] == t[i])
		{
			count++;
		}
	}
	if(length==count)
	printf("Yes\n");
	else
		printf("No\n");

 return 0;
}


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

int main() {
  string S; cin >> S;
  map<char, int> D;
  for (int i = 0; i < S.size(); i++) {
    if (D.count(S.at(i))) D[S.at(i)]++;
    else D[S.at(i)] = 1;
  }
  if ((D.count('N') && !D.count('S')) || (D.count('S') && !D.count('N'))) {
    cout << "No" << endl;
    return 0;
  }
  if ((D.count('W') && !D.count('E')) || (D.count('E') && !D.count('W'))) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include <stdbool.h>
#define N 8
#define FREE -1
#define NOT_FREE 1

int row[N];
int col[N];
int dpos[2*N-1];
int dneg[2*N-1];
bool x[N][N];

void initial(){
  int i,j;
  for(i=0; i < N; i++){
    row[i] = FREE;
    col[i] = FREE;
    //printf("%d %d\n",row[i],col[i]);
  }
  for(j=0; j < 2*N-1; j++){
    dpos[j] = FREE;
    dneg[j] = FREE;
    //printf("%d %d\n",dpos[j],dneg[j]);
  }
}

void printBoard(){
  int i,j;
  for(i=0; i < N; i++){
    for(j=0; j < N; j++){
      if(x[i][j]){
	if(row[i] != j) return;
      }
    }
  }
  for(i=0; i < N; i++){
    for(j=0; j < N; j++){
      printf("%s",(row[i] == j) ? "Q" : ".");
    }
    printf("\n");
  }
}

void recursive(int i){
  int j;
    
  if( i == N){
    printBoard();
    return;
  }

  for(j=0; j < N; j++){
    if( NOT_FREE == col[j] || NOT_FREE == dpos[i + j] || NOT_FREE == dneg[i-j+N-1]) continue;
    row[i] = j;
    col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_FREE;
    recursive(i+1);
    row[i] = col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;
  }
  
}

int main(){
  int i,j;
  int k,r,c;
  
  initial();

  for(i=0; i < N; i++){
    for(j=0; j < N; j++){
      x[i][j] = false;
    }
  }

  scanf("%d",&k);
  for(i=0; i < k; i++){
    scanf("%d%d",&r,&c);
    x[r][c] = true;
  }

  recursive(0);

  return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int i,a,b;
    int n;
    int k=0;
    string s;
    int u, v, w;
    cin >>a>>b;
    int ans=0;
    //for (i=0;i<n;i++){
    //    ans[i]=0;
//    }
 //   for (i=0;i<n;i++){
  //      std::cin >> u>>v>>w;
//        if (w%2==0)ans[v-1]=ans[u-1];
 //       else if(ans[u-1]==0)ans[v-1]=1;
  //      else ans[v-1]=0;
//    }
 //   for(i=0;i<n;i++)
 if (a>=13) ans=b;
 else if(a>5)ans=b/2;
    std::cout << ans << std::endl;
   
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+10;
int sum[maxn];
int n,val[maxn],stk[maxn],t;
void update(int x,int v){for(;x<=n;x+=x&-x)sum[x]+=v;}
int query(int x){int ret=0;for(;x>=1;x-=x&-x)ret+=sum[x];return ret;}
long long calc(int *a,int m)
{
	memset(sum,0,sizeof(sum));
	long long ans=0;
	for(int i=1;i<=m;i++)
	{
		ans+=query(n)-query(a[i]);
		update(a[i],1);
	}
	return ans;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&val[i]);
	for(int i=1;i<=n;i++)if((val[i]&1)!=(i&1)){printf("No\n");return 0;}
	long long all=calc(val,n);
	if(all%3){printf("No\n");return 0;}
	long long t1,t2;
	t=0;for(int i=1;i<=n;i++)if(i&1)stk[++t]=val[i];
	t1=calc(stk,t);
	t=0;for(int i=1;i<=n;i++)if(i%2==0)stk[++t]=val[i];
	t2=calc(stk,t);
	if(all/3==t1+t2)printf("Yes\n");
	else printf("No\n");
	return 0;
} 

Measured memory_bytes: 3200
import java.util.Scanner

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args: Array[String]) {
    val result = solve(new Scanner(System.in))
    if (result.length > 0) println(result)
  }

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val n = sc.nextInt
    val v1 = new mutable.HashMap[Int, Int]()
    val v2 = new mutable.HashMap[Int, Int]()
    for (i <- 0 until n / 2) {
      val k1 = sc.nextInt
      v1(k1) = v1.getOrElse(k1, 0) + 1
      val k2 = sc.nextInt
      v2(k2) = v2.getOrElse(k2, 0) + 1
    }

    val l1 = v1.toList.sortBy(_._2).reverse.take(2)
    val l2 = v2.toList.sortBy(_._2).reverse.take(2)
    if (l1(0)._1 == l2(0)._1) {
      if (l1.length > 1) {
        val m1 = n - l1(0)._2 - l2(1)._2
        val m2 = n - l1(1)._2 - l2(0)._2
        List(m1, m2).min.toString
      } else (n / 2).toString
    } else {
      (n - l1(0)._2 - l2(0)._2).toString
    }
  }
}


Measured memory_bytes: 54844
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const ll mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    ll x, y;
    cin >> x >> y;
    ll res = 1;
    while((x *= 2) <= y)   ++res;
    cout << res << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
diff = []
if sum(A) < sum(B):
    print(-1)
    exit()
for i in range(N):
    diff.append(A[i] - B[i])

diff = sorted(diff)
i, j = 0, N - 1
num = 0
tmp = 0
while i < N and diff[i] < 0:
    while tmp < abs(diff[i]):
        tmp += diff[j]
        j -= 1
        num += 1
    tmp += diff[i]
    i += 1

print(num + i)

Measured memory_bytes: 18620
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <climits>

using namespace std;

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

	int r;
	cin >> r;
	
	cout << 3 * r * r << endl;

}

Measured memory_bytes: 256
from itertools import *
n=int(input())
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))
a=0
b=0
cnt=0
for i in permutations(range(1,n+1)):
  cnt+=1
  if p==i:
    a=cnt
  if q==i:
    b=cnt
print(abs(a-b))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  char a, b;
  cin >> a >> b;

  if (a == 'H' && b == 'H'){
    cout << 'H' << endl;
  }else if (a == 'H' && b == 'D'){
    cout << 'D' << endl;
  }else if (a == 'D' && b == 'H'){
    cout << 'D' << endl;
  }else if (a == 'D' && b == 'D'){
    cout << 'H' << endl;
  }
}


Measured memory_bytes: 3556
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#define inf 10e8
#define rep(i,n) for(long i=0;i<n;i++)
using namespace std;



int main(){
    int n;
    cin >> n;
    int x[n+10];
    for(int i=1;i<=n;i++) cin >> x[i];
    int ans=1000000;
    for (int i=1;i<=100;i++){//座標全探索
        int ans1=0;
        for (int j=1;j<=n;j++){//人間の体力
            int tairyoku=(x[j]-i)*(x[j]-i);
            ans1+=tairyoku;
        }
        ans=min(ans1,ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
from collections import deque
k = int(input())
l = [int(x) for x in range(1,10)]
lnln = deque(l)
Lnln = []
# print(lnln)
n = 10**5
for i in range(n):
    x = lnln.popleft()
    Lnln.append(x)
    a = x % 10
    
    if a!=0:
        lnln.append(x*10 + (a-1))
        
    lnln.append(x*10 + a)
        
    if a!=9:
        lnln.append(x*10 + (a+1))
        
print(Lnln[k-1])

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

int main(){

int N,K;
cin >> N >> K;

string S;
cin >> S;



for(int i=0; i<N; i++){

	char c=S.at(i);
	if(i+1 == K){

	  c = c-('A'-'a');

	}
	cout<<c;
}


return 0;
}

Measured memory_bytes: 888
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
sort_A = sorted(A)
sort_F = sorted(F,reverse=True)

def check(x):
    cnt = 0
    for i in range(N):
        tmp = x // sort_F[i]
        cnt += max(0, sort_A[i] - tmp)
    return cnt <= K



def main():
    ok = 10 ** 13
    ng = -1

    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if check(mid):
            ok = mid
        else:
            ng = mid

    print(ok) 

if __name__ == "__main__":
    main()

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n+1);
  vector<int> b(n);
  rep(i,n+1) cin >> a[i];
  rep(i,n) cin >> b[i];
  ll beat;
  ll total = 0;
  rep(i,n) {
    beat = min(a[i], b[i]);
    a[i] -= beat;
    b[i] -= beat;
    total += beat;
    beat = min(a[i+1], b[i]);
    a[i+1] -= beat;
    total += beat;
  }
  cout << total << endl;
  
  return 0;
}

Measured memory_bytes: 1152
function main(arg) {
  var [A, B, C, D] = arg[0].split(' ').map(v => v - 0);
  
  while (A > 0 || C > 0) {
  	C -= B;
    if(C <= 0){
      console.log('Yes')
      break;
    }
    A -= D;
    if(A <= 0) {
      console.log('No')
      break;
    }
  }
}

main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split('\n'));


Measured memory_bytes: 29640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
const int maxn=(int)1e6+5;
int cnt[4];
double dp[305][305][305];
int n;
double dfs(int i,int j,int k){
   
    if(i==0&&j==0&&k==0)return 0;
    if(dp[i][j][k]>-0.5)return dp[i][j][k];
     //debug(i),debug(j),debug(k);
    double tmp=1.*n/(i+j+k);
    double ret =0;
    if(i)ret+=tmp*i/n*(dfs(i-1,j,k)+tmp);
    if(j)ret+=tmp*j/n*(dfs(i+1,j-1,k)+tmp);
    if(k)ret+=tmp*k/n*(dfs(i,j+1,k-1)+tmp);
    //debug(i),debug(j),debug(k),debug(ret);
    return dp[i][j][k]=ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    
    cin>>n;
    rep(i,1,n){int x;cin>>x;cnt[x]++;}
    rep(i,0,n)rep(j,0,n)rep(k,0,n)dp[i][j][k]=-1;
    
    printf("%.20lf",dfs(cnt[1],cnt[2],cnt[3]));
    //cout<<dfs(cnt[1],cnt[2],cnt[3])<<endl;
}
/* 
n堆寿司(1<=a<=3)，每次等概率选一堆吃一个。吃完的期望次数？
dp[#1个寿司][#2][#3]:该状态的答案 #0=n-rest;
dp[i][j][k]=i/n*(dp[i-1][j][k]+1)+j/n*(dp[i][j-1][k]+1)+k/n*(dp[i][j][k-1]+1)+(n-i-j-k)/n*(dp[i][j][k]);
"转移不能有环"->整理递归式
有问题：
dp[i][j][k] 
选到1：i/n*(dp[i-1][j][k]+1）
选到2：j/n*(dp[i+1][j-1][k]+1)
选到3：k/n*(dp[i][j+1][k-1]+1)
选到0：(n-i-j-k)/n*(dp[i][j][k])
3
1 1 1

1
3

 */

Measured memory_bytes: 219392
#include <stdio.h>
#include <stdlib.h>

int main(){
    char S[100000];
    int i, a[26], len;

    for(i=0; i<26; i++)
        a[i] = 0;

    scanf("%s", S);

    len = strlen(S);

    for(i=0; i<len; i++){
        a[S[i]-'a']++;
    }

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

    printf("None\n");

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        long a = scan.nextLong(), b = scan.nextLong(), x = scan.nextLong();

        int f = 0;
        if (a%x == 0) {
            f = 1;
        }

        System.out.println(b/x - a/x + f);
    }
}


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

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

    int N;
    cin >> N;

    vector<vector<ll>> a(3, vector<ll>(N, 0));
    rep(i,N) rep(j,3) cin >> a[j][i];

    vector<vector<ll>> dp(3, vector<ll>(N, 0));
    rep(i,3) dp[i][0] = a[i][0];

    for (int i = 1; i < N; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (j == k) continue;
                dp[j][i] = max(dp[j][i], dp[k][i-1] + a[j][i]);
            }
        }
    }

    cout << max(dp[0][N-1], max(dp[1][N-1], dp[2][N-1])) << endl;

    return 0;
}


Measured memory_bytes: 5752
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e9+7
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}
int main(){
  
  ll N;
  cin>>N;
  
  vector<ll>a(N);
  vector<ll>R(N);
  vector<ll>L(N);
  
  rep(i,N){
    cin>>a[i];
  }
  
  ll sum=0;
  rep(i,N){
    sum+=a[i];
    R[i]=sum;
  }
  
  sum=0;
  for(ll i=N-1;i>=0;i--){
    sum+=a[i];
  L[i]=sum;
  }
  
  ll min=abs(R[0]-L[1]);
    
    for(ll i=1;i<N-1;i++){
      ll ans=abs(R[i]-L[i+1]);
      
      if(min>ans){
        min=ans;
      }
    }
  
  cout<<min<<endl;
}

    

Measured memory_bytes: 4992
#include<cstdio>
long long a, b, c;
int Solve() {
	long long k = c - a - b;
	if (k <= 0) return 0;
	return k * k > 4 * a * b;
}
int main() {
	scanf("%lld%lld%lld", &a, &b, &c);
	puts(Solve() ? "Yes" : "No");
}


Measured memory_bytes: 128
//日野茜★担当
//的場梨沙★担当
//結城晴★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stdio.h>

using namespace std;

int main(void) {
    int K;
    cin>>K;

    for(int i=0;i<K;i++){
        cout<<"ACL";
    }

    


}

Measured memory_bytes: 3636
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;
 
int main(void){
  int N,ans=1;
  cin >> N;
  int P[N];
  rep(i,N) cin >> P[i];
  int place[N];
  rep(i,N) place[P[i]-1]=i;
  int stay=1;
  rep(i,N-1){
    if(place[i]<place[i+1]) stay++;
    else stay=1;
    ans=max(ans,stay);
  }
  cout << N-ans << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<random>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include <queue>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney, tree, chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun

#define REP(i,a,b) for(int i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")


ll modpow(ll a, ll n, ll mod) {
	ll ans = 1;
	ll tmp = a % mod;
	while (n > 0) {
		if ((n & 1) == 1) ans = ans * tmp % mod;
		tmp = tmp * tmp % mod;
		n >>= 1;
	}
	return ans;
}

ll mod = 1000000007;
int main() {
	int N;
	cin >> N;
	vector<ll> C(N+1);
	ll sum = 0;
	REP(i, 1, N+1) {
		cin >> C[i];
	}
	sort(next(C.begin()), C.end(), greater<ll>());
	REP(i, 1, N + 1) {
		sum = (sum + C[i] * (i + 1)) % mod;
	}
	sum = sum * modpow(2, 2 * N - 2, mod) % mod;
	PRI(sum);
	return 0;
}




Measured memory_bytes: 4844
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, n;
  int a=100000000;
  int x=0;
  cin >> N;
  n=N;
  for (int i = 9; i > 0; i--) {
    x += n/a;
    n -= (n/a)*a;
    a /=10;
  }
  if (N%x==0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#pragma warning(disable:4996)
int n, m, r, x[100000], y[100000];
vector<int>dp[11000];
int main() {
	while (true) {
		cin >> n >> m >> r; if (n == 0)break;
		for (int i = 0; i < 11000; i++)dp[i].clear();
		for (int i = 0; i < n; i++)cin >> x[i] >> y[i];
		for (int i = 0; i < m; i++) {
			int AA, BB; cin >> AA >> BB;
			dp[AA].push_back(BB);
		}
		for (int i = 0; i < 11000; i++)sort(dp[i].begin(), dp[i].end());
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			for (int j = -r * 4; j <= r * 4; j++) {
				int J = x[i] + j; if (J < 0)continue;
				int L = sqrt(r*r*16 - j*j);
				int P1 = y[i] - L, Q1 = y[i] + L;
				int pos1 = lower_bound(dp[J].begin(), dp[J].end(), P1) - dp[J].begin();
				int pos2 = lower_bound(dp[J].begin(), dp[J].end(), Q1 + 1) - dp[J].begin();
				cnt += pos2 - pos1;
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 5500
MAX = 10**8
h, n = gets.chomp.split(" ").map(&:to_i)
dp = Array.new(2*(10**4),MAX)
dp[0] = 0
n.times do |i|
  a,b = gets.chomp.split(" ").map(&:to_i)
  h.times do |j|
    hp = j + a < h ? j + a : h
    dp[hp] = dp[j] + b < dp[hp] ? dp[j] + b  : dp[hp]
  end
end
p dp[h]


Measured memory_bytes: 1916
#include<stdio.h>
#include<math.h>
int main(){
  int a,b,x,y;
  int temp,tempa,tempb;
  while(scanf("%d %d",&a,&b)!=EOF){
    tempa=fmax(a,b);
    tempb=fmin(a,b);
    while(tempb!=0){
      temp=tempa%tempb;
      tempa=tempb;
      tempb=temp;
    }
    x=tempa;
    y=a/x*b;
    printf("%d %d\n",x,y);
  }
  return(0);
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,m,sum=0;
    cin>>n>>m;
    vector<int> a(m,0);
    for(int i=0;i<n;i++){
        int j,k;
        cin>>k;
        while(k--){
            cin>>j;
            a.at(j-1)++;
        }
    }
    for(int i=0;i<m;i++){
        if(a.at(i)==n) sum++;
    }
    cout<<sum<<"\n";
}

Measured memory_bytes: 256
#!/usr/bin/env python3

s = str(input())

mod = 10**9+7
dp = [[0]*4 for i in range(len(s)+1)]
dp[0][0] = 1
for i in range(1, len(s)+1):
    for j in range(4):
        if s[i-1] == "?":
            dp[i][j] = (dp[i-1][j]*3) % mod
        else:
            dp[i][j] = (dp[i-1][j]) % mod

    if s[i-1] == "A":
        dp[i][1] += (dp[i-1][0]) % mod
    elif s[i-1] == "B":
        dp[i][2] += (dp[i-1][1]) % mod
    elif s[i-1] == "C":
        dp[i][3] += (dp[i-1][2]) % mod
    else:
        dp[i][1] += (dp[i-1][0]) % mod
        dp[i][2] += (dp[i-1][1]) % mod
        dp[i][3] += (dp[i-1][2]) % mod

# print(dp)
print(dp[-1][-1] % mod)


Measured memory_bytes: 31896
#include<stdio.h>
#include<string.h>
#include <ctype.h>

int main(){
  int i, cnt = 0;
  char W[11], T[1001];
  scanf("%s", W);

  while(1)
  {
	  scanf("%s", T);
	  if (!strcmp(T, "END_OF_TEXT")) break;

	  for (i = 0; T[i] != 0; i++) {
	  	T[i] = tolower(T[i]);
	  }

	  if(!strcmp(T, W)) cnt++;

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

  return 0;
}



Measured memory_bytes: 2036
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P) 
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



string fi[10];

int main() {
	for (int i = 0; i < 8; ++i) cin >> fi[i];

    cout << 90 << endl;
	for (int i = 0; i < 8; ++i) {
		for (int j = 0; j < 8; ++j) cout << fi[7-j][i];
		cout << endl;
	}
	
	cout << 180 << endl;
	for (int i = 0; i < 8; ++i) {
		for (int j = 0; j < 8; ++j) cout << fi[7-i][7-j];
		cout << endl;
	}

	cout << 270 << endl;
	for (int i = 0; i < 8; ++i) {
		for (int j = 0; j < 8; ++j) cout << fi[j][7-i];
		cout << endl;
	}
    
    return 0;
}


Measured memory_bytes: 1184
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt();
		int b=scan.nextInt();
		int max=0;
		int min=1145141919;
		for(int i=0;i<b;i++) {
			int x=scan.nextInt();
			int y=scan.nextInt();
			max=x>max?x:max;
			min=y<min?y:min;
		}
		System.out.println((min-max+1)<=0?0:(min-max+1));
	}
}


Measured memory_bytes: 63676
import copy


def partition(a, p, r):
    x = int(a[r][1])
    i = p - 1
    for j in range(p, r):
        if int(a[j][1]) <= x:
            i += 1
            a[i], a[j] = a[j], a[i]
    a[i + 1], a[r] = a[r], a[i + 1]
    return i + 1


def quickSort(a, p, r):
    if p < r:
        q = partition(a, p, r)
        quickSort(a, p, q - 1)
        quickSort(a, q + 1, r)


n = int(input())
s = []
for i in range(n):
    s.append(input().split())

l = copy.deepcopy(s)
l.sort(key=lambda x: x[1])

quickSort(s, 0, n - 1)

print("Stable" if s == l else "Not stable")
for v in s:
    print(" ".join(v))


Measured memory_bytes: 49856
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i >= 1; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> p;


int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	string ans = "No";
	if (abs(a - c) <= d || (abs(a - b) <= d&&abs(b - c) <= d)) {
		ans = "Yes";
	}
	cout << ans << endl;
	return 0;
}

//Ctrl+Aを使わない

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int ll
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int w[20][20];
signed main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, d, cnt = 0;
	cin>>n>>d;
	for(int i = 0; i < n; i++)
		for(int j = 0; j < d; j++)
			cin>>w[i][j];
	for(int i = 0; i < n; i++)
		for(int j = i+1; j < n; j++)
		{
			int dist = 0;
			for(int k = 0; k < d; k++) dist += (w[i][k]-w[j][k])*(w[i][k]-w[j][k]);
			if (sqrt(dist) == (int)sqrt(dist)) cnt++;
		}
	cout<<cnt<<endl;
	return ~~(0-0);
}

Measured memory_bytes: 256
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::vec::Vec;
use std::{vec, cmp, num};


struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {cin: cin}
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

// create Vec<char> from String
#[allow(dead_code)]
fn to_chars(s: String) -> vec::Vec<char> {
    let mut cs = s.chars();
    let mut res = vec::Vec::new();
    while let Some(c) = cs.next() {
        res.push(c);
    }
    res
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let n: i32 = sc.read();
    if n % 10 == 9 || n / 10 == 9 {
        println!("Yes");
    } else {
        println!("No");
    }
}

Measured memory_bytes: 4352
n,k=list(map(int,input().split()))
r,s,p=list(map(int,input().split()))
t=list(input())
t.append
# a 4+3i でいう４
# b          3
a=n%k
b=n//k

ans=[]
#1   1個前同じで一個前使ってる
flg=0
for i in range(k):
  if i<=a-1:
    flg=0
    for j in range(b):
      if flg==1:
        flg=0
      else:
        if t[i+k*j]==t[i+k*j+k]:
          flg=1
          ans.append(t[i+k*j])
        else:
          ans.append(t[i+k*j])
    if flg==0:
      ans.append(t[i+b*k])
  else:
    flg=0
    for j in range(b-1):
      if flg==1:
        flg=0
      else:
        if t[i+k*j]==t[i+k*j+k]:
          flg=1
          ans.append(t[i+k*j])
        else:
          ans.append(t[i+k*j])
    if flg==0:
      ans.append(t[i+(b-1)*k])

      
from collections import Counter
zisyo=Counter(ans)
print(zisyo["r"]*p+zisyo["s"]*r+zisyo["p"]*s)

   
        
   

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

using ll=long long;

const int MAX = 2200000;
const long long MOD = 1000000007;
long long INF = 90000000001000;


int main() {
int n;cin >> n;
string s;
s = to_string(n);
if (s[0]=='7'||s[1]=='7'||s[2]=='7')
{
   cout << "Yes" << endl;

}
else cout << "No" << endl;

return 0;
}




Measured memory_bytes: 3680
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
vector<int> graf[200005];
int n, m;
int vertex[200005];
int rez = 0;
int find(int x)
{
    int final = 0;
    if(vertex[x])
    {
        final = vertex[x];
        return final;
    }
        int maxCycle = 0;
        for(auto i = graf[x].begin(); i != graf[x].end(); i++)
        {
            if(find(*i) > maxCycle)
                maxCycle = find(*i);
        }
        (vertex[x]  = maxCycle +1);
           return vertex[x];

}
void read()
{
    cin >> n >> m;
    for(int i = 0; i < m; i++)
    {
        int a = 0;
        int b = 0;
        cin >> a >> b;
        graf[a].push_back(b);
    }
}
void solve()
{
    for(int i = 1; i <= n; i++)
    {
        if(rez < find(i))
            rez = find(i);
    }
    rez--;
    cout << rez;
}
int main()
{

    read();
    solve();

}

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

int main() {
  queue<ll>  Lunluns;
  int counter = 0, k;
  ll ans = 0;
  cin >> k;
  for (ll i = 1; i < 10; i++)
  {
    Lunluns.push(i);
  }
  while (true) 
  {
    ans = Lunluns.front();
    Lunluns.pop();
    if (ans % 10 != 0)  Lunluns.push(10 * ans + ans % 10 - 1);
    Lunluns.push(10 * ans + ans % 10);
    if (ans % 10 != 9)  Lunluns.push(10 * ans + ans % 10 + 1);
    counter++;
    if (counter == k)  break;
  }
  cout << ans;
  return 0;
  
}

Measured memory_bytes: 1792
#include <stdio.h>
int min(int a,int b)
{
	if(a<b)
		return a;
	return b;
}
int mod(int a,int b)
{
	if(a>b)
		return a-b;
	return b-a;
}
int main(void)
{
	int n;
	scanf("%d",&n);
	int a[n];
	int ans[n];
	for (int i = 0; i < n; ++i)
	{
		scanf("%d",&a[i]);
	}

	ans[0]=0;
	ans[1]=mod(a[0],a[1]);
	for (int i = 2; i < n; ++i)
	{
		ans[i]=min(ans[i-1]+mod(a[i-1],a[i]),ans[i-2]+mod(a[i-2],a[i]));
	}
	printf("%d\n",ans[n-1] );
}

Measured memory_bytes: 896
//! Framework <https://github.com/vain0x/procon>

#![allow(non_snake_case)]
#![allow(unused_imports)]

use std::collections::*;

pub struct Scan(Box<dyn Iterator<Item = &'static str>>); // '

impl Scan {
    fn new() -> Self {
        let mut buf = String::new();
        let read_line = move || {
            std::io::stdin().read_line(&mut buf).unwrap();
            Box::leak(buf.split_off(0).into_boxed_str()).split_whitespace()
        };
        Scan(Box::new(std::iter::repeat_with(read_line).flatten()))
    }

    pub fn word<T: std::str::FromStr>(&mut self) -> T {
        self.0.next().unwrap().parse().ok().unwrap()
    }

    pub fn list<T: std::str::FromStr>(&mut self, len: usize) -> Vec<T> {
        std::iter::repeat_with(|| self.word()).take(len).collect()
    }
}

const P: i64 = 998244353;

pub fn pow(x: i64, n: i64) -> i64 {
    let (mut x, mut y, mut n) = (x % P, 1_i64, n);
    while n > 0 {
        if n % 2 != 0 {
            y = (y * x) % P;
            n -= 1;
        }

        x = (x * x) % P;
        n /= 2;
    }
    y
}

fn main() {
    let mut scan = Scan::new();

    let N = scan.word::<usize>();
    let M = scan.word::<usize>();
    let K = scan.word::<usize>();

    let mut fact = vec![0; N + 1];
    fact[0] = 1;
    fact[1] = 1;
    for i in 2..fact.len() {
        fact[i] = i as i64 * fact[i - 1] % P;
    }

    let mut fact_inv = vec![0; N + 1];
    fact_inv[N] = pow(fact[N], P - 2);
    for i in (1..fact_inv.len()).rev() {
        fact_inv[i - 1] = i as i64 * fact_inv[i] % P;
    }

    let mut x = 0;

    for k in 0..=K {
        let mut y = fact[N - 1];
        y *= fact_inv[N - 1 - k];
        y %= P;
        y *= fact_inv[k];
        y %= P;
        y *= pow((M - 1) as i64, (N - 1 - k) as i64);
        y %= P;

        x += y;
        x %= P;
    }

    x *= M as i64;
    x %= P;

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


Measured memory_bytes: 5108
using System;

class GreatestCommonDivisor
{
    int x;
    int y;
    public GreatestCommonDivisor()
    {
        string[] s = Console.ReadLine().Split(' ');
        x = int.Parse(s[0]);
        y = int.Parse(s[1]);
    }
    public void Calc()
    {
        int min,maxGCD=0;
        min = x >= y ? y : x;  
        for(int i =1;i<=min;i++)
        {
            if(x % i == 0 && y % i == 0)
            {
                maxGCD = i;
            }
        }
        Console.WriteLine(maxGCD);
    }
}
class Program
{
    static void Main()
    {
        GreatestCommonDivisor ob = new GreatestCommonDivisor();
        ob.Calc();
    }
}

Measured memory_bytes: 9240
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using vb = vector<bool>;
using boolGraph = vector<vb>;
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main() {
  int N; cin >> N;
  Graph G(2, vi(N));
  rep(i,2) rep(j,N) cin >> G[i][j];

  int sum = G[0][0] + accumulate(all(G[1]), 0);
  int ans = sum;

  rep(i,N-1) {
    sum += G[0][i+1] - G[1][i];
    ans = max(ans, sum);
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	#endif

	string str;
	cin >> str;
	if(str == string(str.size(), str[0])) cout << "No\n";
	else cout << "Yes\n";
}



Measured memory_bytes: 256
#include <stdio.h>
 
int a[100][100], n;
 
void djk(){
  int minv, d[100], c[100], i, k, u;
 
  for(i = 0; i < n; i++){
    d[i] = 1000000;
    c[i] = 0;
  }
 
  d[0] = 0;
  c[0] = 1;
  while(1){
    minv = 1000000;
    u = -1;
    for(i = 0; i < n; i++){
      if(minv > d[i] && c[i] != 2){
    u = i;
    minv = d[i];
      }
    }
    if(u == -1) break;
    c[u] = 2;
    for(k = 0; k < n; k++){
      if(c[k] != 2 && a[u][k] != 1000000){
    if(d[k] > d[u] + a[u][k]){
      d[k] = d[u] + a[u][k];
      c[k] = 1;
    }
      }
    }
  }
  for(i = 0; i < n; i++){
    printf("%d ", i);
    if(d[i] != 1000000) printf("%d\n", d[i]);
  }
}
 
 
int main(){
  int i, j, u, k, v, c;
 
  scanf("%d", &n);
 
  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      a[i][j] = 1000000;
    }
  }
   
  for(i = 0; i < n; i++){
    scanf("%d %d", &u, &k);
    for(j = 0; j < k; j++){
      scanf("%d %d", &v, &c);
      a[u][v] = c;
    }
  }
 
    djk();
 
  return 0;
}



Measured memory_bytes: 2032
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n);
	std::vector<int> a(n - 1), b(n - 1);
	std::vector<std::vector<int>> g(n);
	for(int i = 0; i < n - 1; i++) {
		scanf("%d%d", &a[i], &b[i]);
		a[i]--; b[i]--;

		g[a[i]].push_back(i);
		g[b[i]].push_back(i);
	}

	// solve
	// calc K
	int K = 0;
	for(int i = 0; i < n; i++) K = std::max(K, (int)g[i].size());

	std::vector<int> ans(n - 1);
	auto solve = [&](auto && solve, int v, int p, int d) -> void {
		int cnt = 1;
		for(auto id: g[v]) {
			int to = a[id] ^ b[id] ^ v;
			if(to == p) continue;
			
			ans[id] = (d + cnt++) % K;
			solve(solve, to, v, ans[id]);
		}
	};
	solve(solve, 0, -1, 0);
	
	printf("%d\n", K);
	for(auto v: ans) printf("%d\n", v + 1);
	return 0;
}


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

bool check(string s ) {
  if ( s[0] != 'A' )return false;
  int cnt = 0;
  for ( int i = 2; i < s.length()-1; i++ ) {
    if ( s[i] == 'C' )cnt++;
  }
  if( cnt != 1 ) return false;
  int upper = 0;
  for ( int i = 0; i < s.length(); i++ ) {
    if ( s[i] >= 'A' && s[i] <= 'Z' ) upper++;
  }

  if ( upper != 2 ) return false;
  return true;
}

int main() {
  string s; cin >> s;
  
  if ( check(s)) cout << "AC" << endl;
  else cout << "WA" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdbool.h>

bool is_three(int n)
{
    return (n % 3 == 0);
}

bool include_three(int n)
{
    if (n % 10 == 3)
    {
        return true;
    }
    while (n)
    {
        n /= 10;
        if (n % 10 == 3)
        {
            return true;
        }
    }
    return false;
}

void call(int n) //nまでの3の倍数と3を含む数を返す
{
    for (int i = 1; i <= n; i++)
    {
        if (is_three(i) || include_three(i))
        {
            printf(" %d", i);
        }
    }
}

int main(void)
{
    int n;
    scanf("%d", &n);
    call(n);
    printf("\n");

    return 0;
}


Measured memory_bytes: 2032
#include<iostream>
#include<algorithm>
#include <vector>
#include<cmath>
#include<iomanip>
#include<queue>
using namespace std;
typedef long long int lont;
int main() {
	int N;
	cin >> N;
	vector<int>veca(N+1);
	vector<int>vecb(N+1);
	vector<int>vecc(N - 1);
	for (int ia = 0; ia < N; ia++) {
		cin >> veca.at(ia);
	}
	for (int ib = 0; ib < N; ib++) {
		cin >> vecb.at(ib);
	}
	for (int ic = 0; ic < N - 1; ic++) {
		cin >> vecc.at(ic);
	}
	int ans = 0;
	for (int id = 0; id < N; id++) {
		ans += vecb.at(veca.at(id)-1);
		if (veca.at(id) + 1 == veca.at(id + 1)) {
			ans+=vecc.at(veca.at(id)-1);
		}
	}
	cout << ans << endl;
}



	


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n,i,max,j,s,c;
    int a[10005];
    scanf("%d",&n);
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    max=a[0];
    for(i=1; i<n; i++)
    {
        if(a[i]>max)
        {
            max=a[i];
        }
    }
    s=max/2;
    c=0;
    for(i=0; i<n; i++)
    {
        if(a[i]==max)
        {
            c++;
        }
    }

    if(c==n)
    {
        for(i=1; i<n; i++)
        {
            s=s+a[i];
        }
        printf("%d\n",s);
    }


    else
    {
        for(i=0; i<n; i++)
        {
            if(a[i]==max)
                continue;
            else
            {
                s=s+a[i];
            }
        }
        printf("%d\n",s);
    }


    return 0;
}


Measured memory_bytes: 128
N,A,B,K = map(int,input().split())
if A<B: A,B = B,A
MOD = 998244353

def mul(a,b):
    return (a*b) % MOD

def pow(a,n): # a^n
    ret = 1
    mag = a
    while n > 0:
        if n & 1:
            ret = mul(ret, mag)
        mag = mul(mag, mag)
        n >>= 1
    return ret

def inv(a):
    return pow(a, MOD-2)

fac = [1]
fac_inv = [1]
for n in range (1,N+10):
    f = mul(fac[n-1], n)
    fac.append(f)
    fac_inv.append(inv(f))

mem = [0] * (N+1)
def ncr(n,r):
    if mem[r] > 0:
        return mem[r]
    else:
        ret = mul(mul(fac[n], fac_inv[n-r]), fac_inv[r])
        mem[r] = ret
        return ret

ans = 0
for a in range(N+1):
    if a*A > K: break
    rem = K-a*A
    if rem%B: continue
    b = rem//B
    if b > N: continue
    ans += mul(ncr(N,a), ncr(N,b))
print(ans % MOD)


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

int main() {
  //editorial AC
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  for (int i = m / n; 0 < i; i--) {
    if (m % i == 0) {
      cout << i << '\n';
      break;
    }
  }
}


Measured memory_bytes: 256
while True:
    n = input()
    if n == 0: break
    a = [ input() for i in xrange(n) ]
    m = -100000
    for i in xrange(n):
        s = 0
        for j in xrange(i, n):
            s += a[j]
            m = max(m, s)
    print m

Measured memory_bytes: 6540
import math

# 定義
minutes = [int(input()) for i in range(5)]
m = [math.ceil(minutes[k] / 10) * 10 for k in range(5)]

# 最後に注文するやつを決める
last = min((minutes[l] - 1) % 10 for l in range(5))
last += 1

#　出力
print(m[0] + m[1] + m[2] + m[3] + m[4] + last - 10)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,m;
  cin>>n>>m;
  ll x = 1;
  vecll b(n);
  REP(i,n) {
    ll a;
    cin>>a;
    a /= 2;
    x = lcm(x, a);
    if (x > m) {
      cout<<0<<endl;
      return 0;
    }
    b[i] = a;
  }
  REP(i,n) {
    if ((x / b[i]) % 2 == 0) {
      cout<<0<<endl;
      return 0;
    }
  }
  ll div = m / x;
  cout<<(div+1)/2<<endl;
  return 0;
}


Measured memory_bytes: 1024
x, y = map(int, input().split())

ans = 0

if (x == 1):
    ans += 300000

if (y == 1):
    ans += 300000

    
if (x == 2):
    ans += 200000
    
if (y == 2):
    ans += 200000
    
if (x == 3):
    ans += 100000
    
if (y == 3):
    ans += 100000
    
if (x == 1)and(y==1):
    ans +=  400000 

    
print(ans)

Measured memory_bytes: 3064
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	//予備
	n := iScan()
	x := iScan()
	t := iScan()
	a := n % x
	if a == 0 {
		fmt.Println(n / x * t)
	} else {
		fmt.Println((n/x + 1) * t)
	}
}

Measured memory_bytes: 1772
N, T = list(map(int, input().split()))
A = list(map(int, input().split()))
count = 0
for i in range(N-1):
    if A[i + 1] - A[i] > T:
        count = count + T
    else:
        count = count + A[i + 1] - A[i]
print(count + T)


Measured memory_bytes: 25200
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <map>
#include <limits>
using namespace std;
typedef long long ll;

float inf = std::numeric_limits<float>::infinity();
ll mod = 1e9+7;

/* 二次元配列の宣言
  vector<vector<int>> tb;
  tb.resize(H);
  for (size_t i = 0; i < H; i++) {
    tb[i].resize(W);
  }
*/
/*
  A.resize(N);
  for (int i = 0; i < N; i++) {scanf("%d",&A[i]);}
*/

int max(int &a,int &b){if(a>b){return a;}else{return b;}}
int min(int &a,int &b){if(a>b){return b;}else{return a;}}

int ar_max(vector<int> &v){
  int max_val = v[0];
  for (size_t i = 1; i < v.size(); i++) {
    if (v[i]>max_val){max_val=v[i];}
  }
  return max_val;
}

int ar_min(vector<int> &v){
  int min_val = v[0];
  for (size_t i = 1; i < v.size(); i++) {
    if (v[i]<min_val){min_val=v[i];}
  }
  return min_val;
}


int main(void) {
  int N,ans=0,num=0;
  string S;
  cin >> N >> S;
  for (int i = 0; i < N; i++) {
    if (S[i]=='I') {num ++;}else{num --;}
    ans = max(ans,num);
  }
  cout << ans << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <deque>

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

constexpr int INF = 1 << 30;

const std::vector<std::pair<int, int>>
    dxys{{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

void solve() {
    int h, w, sx, sy, gx, gy;
    std::cin >> h >> w >>
        sx >> sy >> gx >> gy;
    --sx, --sy, --gx, --gy;

    std::vector<std::string> ss(h);
    for (auto& s : ss) std::cin >> s;

    auto dist = vec(h, vec(w, INF));
    dist[sx][sy] = 0;
    std::deque<std::tuple<int, int, int>> que;
    que.emplace_back(dist[sx][sy], sx, sy);

    while (!que.empty()) {
        auto [d, x, y] = que.front();
        que.pop_front();
        if (d > dist[x][y]) continue;

        for (auto [dx, dy] : dxys) {
            auto nx = x + dx,
                 ny = y + dy;

            if (nx < 0 || h <= nx ||
                ny < 0 || w <= ny ||
                ss[nx][ny] == '#' ||
                dist[nx][ny] <= dist[x][y]) continue;

            dist[nx][ny] = dist[x][y];
            que.emplace_front(dist[nx][ny], nx, ny);
        }

        for (int dx = -2; dx <= 2; ++dx) {
            for (int dy = -2; dy <= 2; ++dy) {
                auto nx = x + dx,
                     ny = y + dy;

                if (nx < 0 || h <= nx ||
                    ny < 0 || w <= ny ||
                    ss[nx][ny] == '#' ||
                    dist[nx][ny] <= dist[x][y] + 1) continue;

                dist[nx][ny] = dist[x][y] + 1;
                que.emplace_back(dist[nx][ny], nx, ny);
            }
        }
    }

    auto ans = dist[gx][gy];
    std::cout << (ans == INF ? -1 : ans) << "\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 8740
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
  for(;;) {
    int d, w;
    cin >> d >> w;
    if(d == 0 && w == 0) break;
    vector<vector<int>> es;
    for(int i = 0; i < d; i++) {
      vector<int> v;
      for(int j = 0; j < w; j++) {
        int c;
        cin >> c;
        v.push_back(c);
      }
      es.push_back(move(v));
    }
    auto f = [&es](int i, int j, int k, int l){
      int mn = es[i][j];
      for(int ii = i; ii <= k; ii++) {
        if(mn > es[ii][j]) mn = es[ii][j];
        if(mn > es[ii][l]) mn = es[ii][l];
      }
      for(int jj = j; jj <= l; jj++) {
        if(mn > es[i][jj]) mn = es[i][jj];
        if(mn > es[k][jj]) mn = es[k][jj];
      }
      int sum = 0;
      for(int ii = i + 1; ii < k; ii++) {
        for(int jj = j + 1; jj < l; jj++) {
          if(es[ii][jj] >= mn) return -1;
          sum += mn - es[ii][jj];
        }
      }
      return sum;
    };
    int mx = 0;
    for(int i = 0; i < d; i++) {
      for(int j = 0; j < w; j++) {
        for(int k = i + 2; k < d; k++) {
          for(int l = j + 2; l < w; l++) {
            int s = f(i, j, k, l);
            if(s < 0) continue;
            if(s > mx) mx = s;
          }
        }
      }
    }
    cout << mx << endl;
  }
  return 0;
}

Measured memory_bytes: 3056