akhauriyash/Code-Regression huggingface dataset:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]

N = I()
abc = LIR(N-1)
Q, K = LI()
xy = LIR(Q)


K = K

utov = [[] for i in range(N+1)]
for a, b, c in abc:
    utov[a].append((b,c))
    utov[b].append((a,c))

bfs_map = [-1]*(N+1)

q = deque()
q.append(K)
bfs_map[K] = 0

while q:
    u = q.popleft()
    for v, cost in utov[u]:
        if (bfs_map[v] == -1) or (bfs_map[v] > bfs_map[u]+cost):
            bfs_map[v] = bfs_map[u] + cost
            q.append(v)


for x, y in xy:
    print(bfs_map[x]+bfs_map[y])


Measured memory_bytes: 81936
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include<string.h>
#include<math.h>
#include<stack>
#include<map>
#include<vector>
using namespace std;
const int maxn=400010;

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        if((n&1)==0)
            printf("%d\n",n);
        else
            printf("%d\n",n*2);
    }
    return 0;
}


Measured memory_bytes: 256
/******************************************************************************

                            Online Java Compiler.
                Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/

import java.io.*;
import java.util.*;
public class Main
{
    
    
    
    public static int func(ArrayList <Integer>ls[], int j,int dp[])
    {
        int temp=0;
        int ans=0;
        
        if(ls[j]==null)
        {
            return 0;
        }
         
        if( dp[j]!=0)
        {
            return dp[j];
        }
       
        
        else {
            for(int k =0;k<ls[j].size();k++)
            {
            
            
            temp= 1+ func(ls,ls[j].get(k),dp);
            
           // dp[ls[j].get(k)]=temp;
            ans=Math.max(temp,ans);
            
            }
        }
       // vis[j]=1;
        return dp[j]=ans;
        
        
    }
    
    
	public static void main(String[] args) throws Exception {
	//	System.out.println("Hello World");
		
		int N,M;
		BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
	String s=br.readLine();
	String ss[]=s.split(" ");
	N=Integer.parseInt(ss[0]);
	M=Integer.parseInt(ss[1]);
	int x=0,y=0;
	int ans=0;

	int dp[]=new int [N+1];
	//Arrays.fill(dp,0);
	//int dp[][]=new int[N+1][N+1];
	ArrayList<Integer>ls[]=new ArrayList[N+1];
	for(int i=0;i<M;i++)
	{
	    s=br.readLine();
	    ss=s.split(" ");
	 x=Integer.parseInt(ss[0]);
	y=Integer.parseInt(ss[1]);
	 if(ls[x]==null)
	 {
	     ls[x]=new ArrayList();
	 }
	    ls[x].add(y);
	    
	}
	for(int i=1;i<=N;i++)
	{
	 if(dp[i]!=0)
	 {
	     ans=Math.max(ans,dp[i]);
	     continue;
	 }
	 if(ls[i]!=null)
	 {
	     //vis[i]=1;
	     for(int j=0;j<ls[i].size();j++)
	     {
	      int temp =1+func(ls,ls[i].get(j),dp);
	      dp[i]=Math.max(dp[i],temp);
	      
	     }
	      ans=Math.max(ans,dp[i]);
	 }
	   
	}
	System.out.println(ans);
   
	}
}


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

int main() {
  string s;
  cin >> s;

  int n = s.size();
  string t = s;
  reverse(t.begin(), t.end());
  string t1 = s.substr(0, (n - 1) / 2);
  string t2 = t1;
  reverse(t2.begin(), t2.end());
  string t3 = s.substr((n + 3) / 2 - 1, n);
  string t4 = t3;
  reverse(t4.begin(), t4.end());
  bool yes = s == t && t1 == t2 && t3 == t4;

  if (yes)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;
using plli=pair<ll,int>;
using vplli=vector<pair<ll,int>>;
using pllll=pair<ll,ll>;
using vpllll=vector<pair<ll,ll>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    int N;cin>>N;
    vi a(N);
    rep(i,0,N)cin>>a[i];
    int v=a[0];
    vi pros,idx;
    rep(i,1,N){
        if(v>a[i]){
            idx.push_back(i);
            pros.push_back(0);
            v=a[i];
        }
        else if(v<a[i]){
            idx.push_back(i);
            pros.push_back(1);
            v=a[i];
        }
    }
    ll num=0,money=1000;
    rep(i,0,pros.size()){
        if(pros[i]==0)continue;
        else{
            //cout<<idx[i]<<" ";
            num+=money/a[idx[i]-1];
            money=money%a[idx[i]-1];
            //cout<<num<<" "<<money;
            money+=num*a[idx[i]];
            //cout<<" "<<money<<endl;
            num=0;
        }
    }
    cout<<money<<endl;
    return 0;
}




Measured memory_bytes: 3624
#include<iostream>
#include<cmath>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<cstdlib>
#include<queue>
#include<list>
#include<cctype>
const int INF=1e9;
using namespace std;

int main(){
    int n, m;
    cin>>n>>m;
    cout<<(n-1)*(m-1)<<endl;
}


Measured memory_bytes: 256
h,w=map(int,input().split())
a=[]
for i in range(h):
    arr=list(str(input()))
    if "#" in arr:a.append(arr)
for i in range(w):
    if all ([a[j][i]=="." for j in range(len(a))]):
        for k in range(len(a)):
            a[k][i]=""
for i in a:
    print("".join(i))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define lp3(i,a,b) for(int i=a;i<b;i++)
#define lp2(i,n) for(int i=0;i<n;i++)
#define ll long long
#define W 1000000007
using namespace std;

int main(){
	string j = "War";
	int n,m,x,y;
	cin>>n>>m>>x>>y;
	int xp[n],yp[m];
	lp2(i,n)cin>>xp[i];
	lp2(i,m)cin>>yp[i];
	lp3(i,x+1,y){
		int a = 0,b = 0;
		lp2(k,n){
			if(xp[k]<i){
				a++;
			}
		}
		lp2(k,m){
			if(yp[k]>=i){
				b++;
			}
		}
		if(a==n&&b==m){
			j="No War";
			break;
		}
	}
		cout<<j<<endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int,int>;
using vi = std::vector<int>;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    int n; cin >> n;
    ll k; cin >> k;
    vector<ll> a(n), f(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> f[i];
    sort(all(a));
    reverse(all(a));
    sort(all(f));

    if(accumulate(all(a),0LL) <= k){
        cout << 0 << endl;
        return 0;
    }

    ll l,r;
    l = 0; // NG
    r = 1e12+10; // OK

    while(r-l>1){
        ll m = (l+r)/2;

        ll cost = 0;
        rep(i,n){
            ll target = m / f[i];
            cost += max(0LL, a[i]-target);
        }
        if(cost <= k){
            r = m;
        }else{
            l = m;
        }
    }
    cout << r << endl;
}


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

using namespace std;
using ll = long long;
using ld = long double;

void solve() {
  int n, l;
  cin >> n >> l;
  int sum, mi = abs(l);

  for (int i = 1; i <= n; i++) {
    sum += l + i - 1;
    if (abs(mi) > abs(l + i - 1)) {
      mi = l + i - 1;
    }
  }

  cout << sum - mi << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();
  return 0;
}


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

namespace ConsoleApp8
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split().Select(int.Parse).ToArray();

            int a = line[0];
            int b = line[1];

            if (a == b)
            {
                Console.WriteLine( string.Join("", Enumerable.Repeat(a.ToString(), a)));
            }
            else if(a > b)
            {
                Console.WriteLine(string.Join("", Enumerable.Repeat(b.ToString(), a)));
            }
            else
            {
                Console.WriteLine(string.Join("", Enumerable.Repeat(a.ToString(), b)));
            }
        }
    }
}


Measured memory_bytes: 13396
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()

#define int long long

void dout() { cerr << '\n'; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << " " << H;
    dout(T...);
}

#ifdef LOCAL
    #define dbg(...) cerr << #__VA_ARGS__, dout(__VA_ARGS__)
#else
    #define dbg(...) ;
#endif

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;

int n;

int get(int k) {
    int x = n;
    while (x % k == 0) {
        x /= k;
    }
    return (x % k == 1);
}

signed main() {
    ios_base::sync_with_stdio(false), cin.tie(NULL);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif

    cin >> n;
    int s = sqrt(n);
    while (s * s < n) {
        s++;
    }
    while (s * s > n) {
        s--;
    }
    int ans = 0;
    for (int i = 1; i <= s; i++) {
        if (n % i == 0) {
            if (i > 1) {
                ans += get(i);
            }
            if (i * i != n) {
                ans += get(n / i);
            }
        }
    }
    n--;
    s = sqrt(n);
    while (s * s < n) {
        s++;
    }
    while (s * s > n) {
        s--;
    }
    for (int i = 1; i <= s; i++) {
        if (n % i == 0) {
            if (i > 1) {
                ans++;
            }
            if (i * i != n) {
                ans++;
            }
        }
    }
    cout << ans;
}


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

int main(int argc, char *argv[])
{
    int i;
    int N, n, max, sum1, sum2;
    scanf("%d", &N);
    int p[N];
    for (i = 0; i < N; i++)
    {
        scanf("%d", &n);
        p[i] = n;
    }
    sum1 = 0;
    sum2 = 0;
    max = 0;
    for (i = 0; i < N; i++)
    {
        sum1 += p[i];
        if (p[i] > max)
        {
            max = p[i];
        }
    }
    sum2 = sum1 - max + max / 2;

    printf("%d\n", sum2);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    bool flag=true;
    for(int i=0;i<n;i++){
        cin>>a.at(i);
        if(a.at(i)%2!=0)flag=false;
    }
int count=0;
while(flag){
    count++;
    for(int i=0;i<n;i++){
        a.at(i)/=2;
        if(a.at(i)%2!=0){
            flag=false;
            break;
        }
    }
}
cout<<count<<endl;
}

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

using namespace std;

typedef long long ll;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    if (k == 0) {
        cout << ll(n) * n;
        return 0;
    }
    for (ll i = 1; i <= n; ++i) {
        ll z = n - n % i;
        ans += max(i - k, 0LL) * z / i;
        ll r = n % i;
        ans += max(0LL, r - k + 1);
    }
    cout << ans;
    return 0;
}

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

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<bool> num(8);
  int ans, cnt=0;
  bool flag=false;
  for(int i=0;i<n;i++){
    int a;
    cin >> a;
    if(a<=399){num[0]=true;}
    else if(a<=799){num[1]=true;}
    else if(a<=1199){num[2]=true;}
    else if(a<=1599){num[3]=true;}
    else if(a<=1999){num[4]=true;}
    else if(a<=2399){num[5]=true;}
    else if(a<=2799){num[6]=true;}
    else if(a<=3199){num[7]=true;}
    else{cnt++;}
  }
  for(int i=0;i<num.size();i++){
    if(num[i]==true){ans++;flag=true;}
  }
  if(flag==true){
    cout << ans << " " << ans+cnt << endl;
  }else{
    cout << 1 << " " << cnt << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;
 
#define endl '\n'
#define loop(i, m, n) for (lli i = m; i < n; i++)
#define loope(i, m, n) for (lli i = m; i <= n; i++)
#define epool(i, m, n) for (lli i = m; i >= n; i--)
#define maxe *max_element
#define mine *min_element
#define mod 1000000007
#define mod2 998244353
#define vt vector<lli>
#define fi first
#define se second
#define pb push_back
#define umap unordered_map
#define mmap multimap
#define MP make_pair
#define empf emplace_front
#define empb emplace_back
#define ret(x) return cout << x << endl, 0;
#define all(v) v.begin(),v.end()

#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
using namespace std;
 
lli gcd(lli a, lli b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
 
lli lcm(lli a, lli b){
    return (a * b) / gcd(a, b);
}
 
lli modi( lli n, lli m=mod ){ 
    n%=m;
    n+=m;
    n%=m;
    return n;
}

lli mpow(lli base, lli exp){
    base %= mod;
    lli result = 1;
    while (exp > 0){
        if (exp & 1)
            result = ((lli)result * base) % mod;
        base = ((lli)base * base) % mod;
        exp >>= 1;
    }
    return result;
}

const lli MIN=-1*1e18;
const lli INF=1e18+999999999999999999;
const lli N=2e5+5;
const ldb pi=4*atan(1);

string sortString(string &str){
    lli i = 0, j = 0, k = 0;
    lli charCount[26] = {0};
    loop(i, 0, str.length())
        charCount[str[i] - 'a']++;
    loop(i, 0, 26){
        loop(j, 0, charCount[i]){
            str[k++] = char('a' + i);
        }
    }
    return str;
}

int32_t main(){
    fast_io
    lli i = 0,j = 0;
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //cout << fixed << setprecision(22);

    lli a,b,c,d;
    cin >> a >> b >> c >> d;

    lli ans=0;
    ans+=min(a,d);
    d=d-a;
    if(d>0){
        d=d-b;
        if(d>0){
            ans+=(-1)*min(c,d);
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 3652
import sys
import numpy as np


def main():
    N, Q = map(int, sys.stdin.readline().rstrip().split())

    H = np.array([0] * (N - 1))
    W = np.array([0] * (N - 1))

    black = (N - 2)**2  # 初期状態の黒枚数

    Hmin = N - 1
    Wmin = N - 1

    for i in range(Q):
        n, x = map(int, sys.stdin.readline().rstrip().split())
        if n == 1:  # ↓ で挟む
            if x - 1 <= Wmin:
                W[x - 1:Wmin] = Hmin - 1
                Wmin = x - 1
            # print("***", W[x - 1], Wmin, Hmin)
            black -= W[x - 1]
        else:
            if x - 1 <= Hmin:
                H[x - 1:Hmin] = Wmin - 1
                Hmin = x - 1
            # print("***", H[x - 1], Wmin, Hmin)
            black -= H[x - 1]

    print(black)


main()


Measured memory_bytes: 31204
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int a[1000010];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)	scanf("%d",&a[i]);
	double ans=0;
	for(int i=1;i<=n;i++)
		ans+=1.0/a[i];
	ans=1.0/ans;
	printf("%.7lf\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <tuple>
#include <random>
#include <unordered_map>
#include <unordered_set>
using namespace std ;

int main() {
    string s;
    int ans=0, cur=0, mod=1;
    cin >> s; 
    vector<int> counter(2019) ; 
    counter.assign(2019, 0) ;
    counter[0]=1;
    
    for (auto c=s.rbegin(); c!=s.rend(); c++) {
        int i=*c-'0' ;
        int j=(i*mod+cur)%2019 ;
        ans += counter[j] ;
        counter[j]++;
        mod=(mod*10)%2019;
        cur=j;
    }
    cout << ans ;
}


Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int n;
    cin >> n;
    vector<ll>l(n);
    rep(i,n)cin >> l[i];
    sort(all(l));
    int ans = 0;
    for(int i = 0;i < n;i++){
        for(int j = i+1;j < n;j++){
            for(int k = j+1;k < n;k++){
                if(l[i] + l[j] > l[k] && l[i]!=l[j] && l[j] != l[k])ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		String s = new String();
		if(a<b) {
			s="<";
		}else if(a>b){
			s=">";
		}else {
			s="==";
		}
		System.out.println("a "+s+" b");
	}
}

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

int mid(int a,int b,int c){
  return a+b+c-max(max(a,b),c)-min(min(a,b),c);
}

int main(){
     int N;
     cin >> N;
     vector<int> A(N);
     vector<int> B(N);
     for(int i = 0;i < N;i++){
         cin >> A.at(i);
         B.at(i) = A.at(i);
     }
     sort(B.begin(),B.end());
     reverse(B.begin(), B.end());

     int count = 0; 
     int M = B.at(0);
     int m = 0;
     for(int k = 0;k < N;k++){
         if(B.at(k) == M){
             count++;
         }
     }
    if(count > 1){
        for(int l = 0;l < N;l++){
        cout << M << endl;
        }
    }
    if(count == 1){
        for(int p = 0;p < N;p++){
            if(A.at(p) != M){
                cout << M << endl;
            }
            if(A.at(p) == M){
                cout << B.at(1) << endl;
            }
        }

    }
  
} 

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

int main() {
    string A;
    cin >> A;
  int count;
  for(int i=0;i<3;i++){
   if(A.at(i)=='o'){
       count++;
     }
    }
    int price = count*100+700;
    cout << price << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

const int N = 1e6 + 10;
int dp[N];

int main() {
  int s;
  scanf("%d", &s);
  memset(dp, 255, sizeof(dp));
  int k = 0;
  dp[s] = 0;
  int ret = -1;
  for (++k; ; ++k) {
    if (s % 2 == 0) {
      s /= 2;
    } else {
      s = s * 3 + 1;
    }
    if (dp[s] >= 0) {
      ret = k;
      break;
    }
    dp[s] = k;
  }
  printf("%d\n", ret + 1);
  return 0;
}


Measured memory_bytes: 4096
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    A, B, C, D = map(int, input().split())
    print(max(0, min(B, D) - max(A, C)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3948
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define SZ(x) ((ll)(x).size())
typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}


int main(){
    ll n,m;
    cin >> n >> m;
    ll res = 0;
    if(n*2>=m){
        res = m/2;
    }else{
        ll k = (m-2*n)/4;
        chmax(res,min(n+k,(m-2*k)/2));
        chmax(res,min(n+k+1,(m-2*(k+1))/2));
        chmax(res,min(n+k-1,(m-2*(k-1))/2));
    }
    put(res);
    return 0;
}


Measured memory_bytes: 256
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;

 
int main(void) {
    long long n;
	cin >> n;
	
	long long ans = 100000000000000;
  
	for(long long  i = 1; i * i <= n; ++i) {
      
      if(n%i==0){
        
        if(i+n/i-2<ans){
          
          ans = i+n/i-2;
        }
      }
					
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string S[55];
int chk(int H,int W){
    if(S[H][W] == '#'){
        return 1;
    }else{
        return 0;
    }
}
char change(int num){
    if(num == 0) return '0';
    else if(num == 1) return '1';
    else if(num == 2) return '2';
    else if(num == 3) return '3';
    else if(num == 4) return '4';
    else if(num == 5) return '5';
    else if(num == 6) return '6';
    else if(num == 7) return '7';
    else if(num == 8) return '8';
    else if(num == 9) return '9';
}
int main(){
    int H, W;

    string ans[55];


    cin >> H;
    cin >> W;
    for(int i = 1; i <= H ;i++){
        cin >> S[i];
    }
    for(int i = 1; i <= H ;i++){
        //S[0][i] = '.';
        //S[H+1][i] = '.';
        S[i] = '.' + S[i] +'.';
        ans[i] = "..................................................";
    }
    for(int i = 0; i <= W + 1;i++){
        S[0] += '.';
        S[H+1] += '.';
    }
    /* for(int i = 0; i <= H + 1;i++){
        cout <<S[i]<<"\n";
    }*/

    for(int i = 1; i <= H ;i++){
        for(int k = 1; k <= W;k++){
            if(S[i][k] == '.'){
                ans[i][k] = change(chk(i-1,k-1) + chk(i-1,k) + chk(i-1,k+1) + chk(i,k-1) +chk(i,k+1) + chk(i+1,k) + chk(i+1,k-1) + chk(i+1,k+1));
            }else{
                ans[i][k]  = '#'; 
            }
        }
    }

    for(int i = 1; i <= H;i++){
        for(int k = 1; k <= W;k++){
            cout <<ans[i][k];
        }
        cout <<"\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
    using namespace std;
    int main() 
    {
    	int N, x, m[1000], count, min;

    	cin>>N>>x;

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

    		cin>>m[i];
    		x -= m[i];

    		if(i == 0)
    			min = m[i];
    		else if(min > m[i])
    			min = m[i];

    	}

    	count = N;
    	count += x / min;
    	cout<<count;
    	
    }

Measured memory_bytes: 256
def main():
  n=list(input())
  n=[int(i) for i in reversed(n)]
  l=len(n)
  n.append(0)
  
  ans=0
  for i in range(l):
    if n[i]<=4:
      a=n[i]
    elif n[i]==5:
      if n[i+1]<=4:
        a=n[i]
      else:
        a=10-n[i]
        n[i+1]+=1
    else:
      n[i+1]+=1
      a=10-n[i]
    ans+=a
  ans+=n[l]
  print(ans)  
if __name__=='__main__':
    main()


Measured memory_bytes: 21356
N=int(input())
A=list(map(int,input().split()))
B=[A[i]-i-1 for i in range(N)]
B.sort()
if N%2:
    b=B[N//2]
else:
    b=(B[N//2-1]+B[N//2])//2
ans=sum([abs(a-b) for a in B])
print(ans)


Measured memory_bytes: 28024
N, K = map(int, input().split())

mod = 10**9+7 #出力の制限

res = 0
for i in range(K, N+2):
    ma = (2*N-i+1)*i/2
    mi = (i-1)*i/2
    res += (ma-mi+1)%mod

print(int(res%mod))

Measured memory_bytes: 9160
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,i;
    cin>>n;
    double x,tot=0;
    string u;
    for (i=0;i<n;i++)
    {
        cin>>x>>u;
        if (u=="JPY")
            tot+=x;
        else
            tot+=380000*x;
    }
    cout<<tot<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

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

ll factorial(ll n) {
  ll answer = 1;
  while (n > 1) {
    answer *= n;
    answer %= mod;
    n--;
  }
  return answer;
}

ll combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

ll permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
// for (auto p : prime_factor(n)) {
//	while (p.second--) {
//		cout << p.first << endl;
//	}
//}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

vector<ll> Eratosthenes(const ll N) {
  bool is_prime[1000000 + 1];
  vector<ll> P;
  for (ll i = 0; i <= N; i++) {
    is_prime[i] = true;
  }
  for (ll i = 2; i <= N; i++) {
    if (is_prime[i]) {
      for (ll j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
      }
      P.emplace_back(i);
    }
  }
  return P;
}

typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

int main() {
  int n;
  cin >> n;
  ivec d(n);
  REP(i, n) { cin >> d[i]; }

  sort(ALL(d));
  int ans = 0;
  int size = d.size();
  if (size % 2 == 0) {
    ans = d[size / 2] - d[size / 2 - 1];
  } else {
    ans = d[size / 2 + 1];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
const ll LL_MAX=LLONG_MAX;
template <typename T>
T in(){
    T x;
    cin >> x;
    return x;
}

template <typename T,typename U>
void forin(T* x,U n){
    for (U i=0;i<n;i++) cin >> x[i];
}

template <typename T>
int div1(T x) {
    return x%1000000007;
}

template <typename T>
void out(T x){
    cout << x << endl;
}

int digit(int n){
    int ans=0;
    while (n>0){
        ans+=n%10;
        n/=10;
    }
    return ans;
}

main(){
    int a=in<int>(),b=in<int>(),c=in<int>();
    if (a+b+c<22) out("win");
    else out("bust");
}

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

int main() {
  char c;
  cin >> c;
  
  if((c == 'a') or (c == 'i') or (c == 'u') or (c == 'e') or (c == 'o'))
    cout << "vowel" << endl;
  else
    cout << "consonant" << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;

int main()
{
	int64_t n, k;
	cin >> n >> k;
	vector<int64_t> a(n);
	vector<int64_t> f(n);
	for (int i = 0; i < n; i++) {
		int64_t a_in;
		cin >> a_in;
		a.at(i) = a_in;
	}
	for (int i = 0; i < n; i++) {
		int64_t f_in;
		cin >> f_in;
		f.at(i) = f_in;
	}

	int64_t a_sum = 0;
	for (int i = 0; i < n; i++) {
		a_sum += a.at(i);
	}
	if (a_sum <= k) {
		cout << 0 << endl;
		return 0;
	}

	sort(a.begin(), a.end());
	sort(f.begin(), f.end());
	reverse(f.begin(), f.end());

	int64_t time_max = 0;
	for (int i = 0; i < n; i++) {
		int64_t time = a.at(i) * f.at(i);
		if (time > time_max) {
			time_max = time;
		}
	}

	int64_t time_min = 0;
	int64_t ans;
	while (true) {
		int64_t time_half = (time_max + time_min) / 2;
		int64_t syugyo = 0;
		for (int i = 0; i < n; i++) {
			int64_t time = a.at(i) * f.at(i);
			if (time > time_half) {
				if ((time - time_half) % f.at(i) == 0) {
					syugyo += (time - time_half) / f.at(i);
				} else {
					syugyo += (time - time_half) / f.at(i);
					syugyo++;
				}
			}
		}
		if (syugyo > k) {
			time_min = time_half;
		} else {
			time_max = time_half;
		}
		if (time_max - time_min <= 1) {
			ans = time_max;
			break;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 3456
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e18;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    string s; cin >> s;
    string ans;
    if(s == "A") ans = "T";
    else if(s == "T") ans = "A";
    else if(s == "C") ans = "G";
    else if(s == "G") ans = "C";
    cout << ans << endstr;
    return 0;
}


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

using namespace std;
using ll = long long;
#define int ll
using PII = pair<int, int>;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using VVV = vector<VV<T>>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll INF = (1LL<<60);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  int h, w;
  cin >> h >> w;
  VV<int> a(h, V<int>(w));
  REP(i, h) REP(j, w) cin >> a[i][j];

  VV<int> ans;
  int x = 0, y = 0, turn = 0;
  int all = 0;
  while(all < h*w) {
    // cout << x << "," << y << endl;
    int nx = x, ny = y;
    if(y%2==0 && x == w-1) ny++;
    else if(y%2 && x == 0) ny++;
    else if(y%2 == 0) nx++;
    else nx--;

    if(turn == 0) {
      if(a[y][x]%2 == 1) {
        turn = 1;
        if(IN(0LL, w, nx) && IN(0LL, h, ny)) {
          ans.PB({y, x, ny, nx});
        }
      }
    } else if(turn == 1) {
      if(a[y][x]%2 == 1) {
        turn = 0;
      } else {
        if(IN(0LL, w, nx) && IN(0LL, h, ny)) {
          ans.PB({y, x, ny, nx});
        }
      }
    }

    x = nx, y = ny;
    all++;
  }

  cout << ans.size() << endl;
  REP(i, ans.size()) {
    cout << ans[i][0]+1 << " " << ans[i][1]+1 << " " << ans[i][2]+1 << " " << ans[i][3]+1 << endl;
  }

  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> data(n);
  for (int i=0; i<n; i++) {
  cin >> data.at(i);
  }
  reverse(data.begin(), data.end());
  
  for (int i=0; i<n; i++) {
    if (data.size() != i+1) cout << data.at(i) << " ";
    else cout << data.at(i) << endl;
  }
  return 0;
}


Measured memory_bytes: 3116
// She is Pretty pretty!
#include<bits/stdc++.h>

using namespace std;
#define int long long 
const int N = 1e6 + 100;
constexpr int mod = 1e9 + 7;
int cnt, head[N], f1[N], f2[N];
struct edge {
    int des;
    int next;
} e[N << 1];
int n;

void ins(int u, int v) {
    ++cnt;
    e[cnt].des = v;
    e[cnt].next = head[u];
    head[u] = cnt;
}

void dfs(int x, int fa) {
    f1[x] = f2[x] = 1;
    for (int i = head[x]; i; i = e[i].next) {
        if (e[i].des != fa) {
            dfs(e[i].des, x);
            f1[x] = f1[x] * (f1[e[i].des] + f2[e[i].des]) % mod;
            f2[x] = f2[x] * f1[e[i].des] % mod;
        }
    }
}

int32_t main() {
    cin >> n;
    for (int i = 1; i < n; i++) {
        int x, y;
        cin >> x >> y;
        ins(x, y);
        ins(y, x);
    }
    dfs(1, 0);
    cout << (f1[1] + f2[1]) % mod << endl;
    return 0;
}


Measured memory_bytes: 16640
require "forwardable"

MOD = 2019
class Modint
  extend Forwardable
  def_delegators :@a, :hash #, :to_i
  
  def initialize(a); @a = a.to_i % MOD; end
  def + (other); Modint[@a + other.to_i]; end
  def - (other); Modint[@a - other.to_i]; end
  def * (other); Modint[@a * other.to_i]; end
  def ** (other); Modint[@a.pow other.to_i, MOD]; end
  def / (other); Modint[@a * other.to_i.pow(MOD-2, MOD)]; end
  def eql? (other); @a.eql? other.to_i; end
  def to_i; @a.to_i; end
  def inspect; "#{@a}"; end
  def coerce(other); [self, other]; end
  
  alias :pow :**
  class << self; alias :[] :new; end
end
M = Modint

a = gets.chomp.chars.map(&:to_i).reverse
n = a.size
dp = Array.new(n+1)
dp[0] = M[0]

n.times do |i|
  dp[i+1] = 10.pow(i,MOD) * a[i] + dp[i]
end
ans = dp.tally.values.map{ |v| v*(v-1)/2 }.sum
puts ans

Measured memory_bytes: 39584
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main (){
  int n,l;
  cin >> n >> l;
  if(l>=0)
    cout << (2*l+n)*(n-1)/2 << endl;
  else if(l<0 && l+n-1>=0)
    cout << (2*l+n-1)*n/2 << endl;
  else
    cout << (2*l+n-2)*(n-1)/2;
}


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

using ll = long long;
using ld  = long double;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=9223372036854775807;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-10; //微調整用（EPSより小さいと0と判定など）

int ii() { int x; if (scanf("%d", &x)==1) return x; else return 0; }
long long il() { long long x; if (scanf("%lld", &x)==1) return x; else return 0; }
string is() { string x; cin >> x; return x; }
char ic() { char x; cin >> x; return x; }
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); } // 古い問題用
void od(double x) { printf("%.15f ", x); }
// long doubleで受け取り、fをLfなどに変えて出力すると、変な数値が出る
// それをなんとかするには独自の出力を作らなければならなそう
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v){cerr << #v << endl; for(const auto& xxx: v){cout << xxx.first << " " << xxx.second << "\n";}} //動作未確認
void br() { putchar('\n'); }

// #define gcd __gcd //llは受け取らない C++17~のgcdと違うので注意
// int lcm(int a, int b){return a / gcd(a, b) * b;}
#define b_e(a) a.begin(),a.end() //sort(b_e(vec));
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll)(n) ; i++ )
#define DREP(i,m,n) for(ll i=(ll)(m) ; i > (ll)(n) ; i-- )
#define rep(i,n) REP(i,0,n)
#define m_p(a,b) make_pair(a,b)
#define p_b push_back
#define SZ(x) ((ll)(x).size()) //size()がunsignedなのでエラー避けに
#define endk '\n'


// coutによるpairの出力（空白区切り）
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << " " << p.second << ")";}
// coutによるvectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " "; //"\t"に変えるとTabで見やすく区切る
  }
  return s;
}
// coutによる多次元vectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

//最大値、最小値の更新。更新したor等しければtrueを返す
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

//4近傍（上下左右） rep(i, 2) にすると右・下だけに進む
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};

// -------- template end - //


// - library ------------- //


// --------- library end - //



int main(){

  ll T = il();

  rep(i, T){
    ll n, m, a, b;
    cin >> n >> m >> a >> b;

    cout << floor_sum(n, m, a, b) << endk;
  }



}



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

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define fore(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvl;
typedef pair<int, int> pint;
typedef vector<pint> vpint;

const int INF = 1e9;

int main() {
  

  int D, G;
  cin >> D >> G;

  int ans = INF;

  //  P[i問目] = <問題数, 全完ボーナス>　入力
  vpint P(D);
  forn (i, D) cin >> P[i].fi >> P[i].se;

  //  全完する問題を決め打つ
  for (int bit = 0; bit < (1 << D); ++bit) {
    vi S(D, 0); //  解いた問題は1にする
    int score = 0, cnt = 0;
    for (int i = 0; i < D; ++i) {
      if (bit & (1 << i)) {
        //  i番目の問題を解く
        score += (i+1) * 100 * P[i].fi + P[i].se;
        cnt += P[i].fi;
        S[i] = 1;
      }
    }
    //  まだ得点が足りないなら得点が高いものから解いていく
    int solving = D;
    while (score < G) {
      //  もしsolving番目の問題を解いていたらスルー
      solving--;
      if (S[solving]) continue;
      forn (i, P[solving].fi) {
        score += (solving+1) * 100;
        ++cnt;
        if (score >= G) break;
      }
      
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct UF {
  vector<int> par, siz;
  UF(int n): par(n), siz(n,1) {
    for (int i = 0; i < n; i++) {
      par[i] = i;
    }
  }
  int find(int x) {
    return par[x] == x ? x: par[x] = find(par[x]);
  }
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (siz[x] < siz[y]) swap(x,y);
    siz[x] += siz[y];
    par[y] = x;
    return true;
  }
  bool same(int x, int y) {
    return find(x) == find(y);
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  UF uf(n);
  for (int i = 0; i < m; i++) {
    int t;
    cin >> t;
    int x, y;
    cin >> x >> y;
    if (t) {
      cout << uf.same(x, y) << endl;
    } else {
      uf.unite(x,y);
    }
  }
}


Measured memory_bytes: 4764
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x = 0;
		for(; a <= b; a++){
			if((c % a) == 0) x++;
		}
		System.out.println(x);
	}
}

Measured memory_bytes: 26276
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <sstream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <cmath>
#include <map>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

pair<bool,string> as[111];
int d[111][111];
int main(){
  int N;
  map<string,int> label;
  while(cin>>N){
    for(int i=0;i<N;i++){
      string s;
      cin>>s;
      if(s=="goto"){
        as[i].first=true;
        cin>>s;
        as[i].second=s.substr(0,(int)s.size()-1);
      }
      else{
        as[i].first=false;
        as[i].second=s.substr(0,(int)s.size()-1);
        label[as[i].second]=i;
      }
    }
    const int INF=1<<29;
    // 初期化
    for(int i=0;i<=N;i++)
      for(int j=0;j<=N;j++)
        if(i==j)d[i][j]=0;
        else d[i][j]=INF;
    for(int i=0;i<N;i++){
      if(as[i].first){
        d[i][label[as[i].second]]=0;
        if(i+1!=label[as[i].second])
          d[i][i+1]=1;
      }
      else
        d[i][i+1]=0;
    }
    // wfしてd[0][N]間最短経路を計算
    for(int k=0;k<=N;k++)
      for(int i=0;i<=N;i++)
        for(int j=0;j<=N;j++)
          d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
    cout<<d[0][N]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1276
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define ALL(v) v.begin(), v.end()

vector<ll> v;

void dfs(ll i, ll sum, string ss)
{
    if (i == 3)
    {
        if (sum + v[i] == 7)
        {
            cout << ss << "+" << v[i];
            cout << "=7" << endl;
            exit(0);
        }
        else if (sum - v[i] == 7)
        {
            cout << ss << "-" << v[i];
            cout << "=7" << endl;
            exit(0);
        }
        return;
    }

    if(i==0)
    {
        dfs(i + 1, sum + v[i], to_string(v[i]));
        dfs(i + 1, sum - v[i], to_string(v[i]));
    }
    else
    {
        dfs(i + 1, sum + v[i], ss + "+" + to_string(v[i]));
        dfs(i + 1, sum - v[i], ss + "-" + to_string(v[i]));
    }
}

int main(int argc, char const *argv[])
{
    string s;
    cin >> s;
    for (ll i = 0; i < 4; i++)
    {
        v.push_back(s[i] - '0');
    }

    dfs(0, 0, "");
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] minFreq = new int[26];
        Arrays.fill(minFreq, Integer.MAX_VALUE);

        int[] curFreq = new int[26];

        String s = "";
        for(int i = 0; i < n; i++) {
          s = sc.next();
          Arrays.fill(curFreq, 0);
          
          for(int c = 0; c < s.length(); c++)
            curFreq[s.charAt(c) - 'a']++;

          for(int k = 0; k < curFreq.length; k++)
            minFreq[k] = Math.min(minFreq[k], curFreq[k]);
        }

        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < minFreq.length; i++) {
          while(minFreq[i] > 0) {
            sb.append((char)(i + 'a'));
            minFreq[i]--;
          }
        }
        System.out.println(sb.toString());
    }
}


Measured memory_bytes: 23764