akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ATOrT solver = new ATOrT();
        solver.solve(1, in, out);
        out.close();
    }

    static class ATOrT {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt(), a = in.nextInt(), b = in.nextInt();

            out.println(Math.min(n * a, b));
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

int d[100000];
signed main() {
	int a, b, c; scanf("%d%d%d", &a, &b, &c);
	for (int e = 0; e < a; e++) {
		scanf("%d", &d[e]);
	}
	sort(d, d + a);
	int sum = 0, hito = 0, hazime =INT_MIN;
	for (int i = 0; i < a; i++) {
		if (hazime < d[i]-c) {
			sum++;
			hazime = d[i];
			hito = 1;
		}
		else if (hito == b) {
			sum++;
			hazime = d[i];
			hito = 1;
		}
		else {
			hito++;
		}
	}
	printf("%d\n", sum);
}

Measured memory_bytes: 640
N=input()
a,b,c,d=N[0],N[1],N[2],N[3]

o=['+++','++-','+-+','+--','-++','-+-','--+','---']

ans=-1
for i in range(8):
    if eval(a+o[i][0]+b+o[i][1]+c+o[i][2]+d)==7:
        ans=i
        break

print(a+o[i][0]+b+o[i][1]+c+o[i][2]+d+'=7')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
    stack<int> s;
    stack<pair<int,int>> pond;
    string data;
    cin>>data;
    for(int i=0;i<data.size();i++){
        if(data.at(i)=='/'&&!s.empty()){
            int sum=i-s.top();
            if(!pond.empty()){
                while(!pond.empty()&&(s.top()<=pond.top().first)){
                sum+=pond.top().second;
                pond.pop();
                }
            }
            pond.push(make_pair(s.top(),sum));
            s.pop();
        }
        else if(data.at(i)=='_'){
        }
        else{
            if(data.at(i)!='/') s.push(i);
        }
    }
    
    int ans=0;
    stack<int> s1;
    while(!pond.empty()){
        s1.push(pond.top().second);
        ans+=pond.top().second;
        pond.pop();
    }
    cout<<ans<<endl<<s1.size();
    while(!s1.empty()){
        cout<<' '<<s1.top();
        s1.pop();
    }
    cout<<endl;
}


Measured memory_bytes: 3276
#include<stdio.h>

int main(void)
{
  int n, m;

  scanf("%d %d", &n, &m);

  int a[m];

  int i;

  for(i=0; i<m; i++){
	scanf("%d", &a[i]);
  }
  
  for(i=0; i<m; i++){
	n = n - a[i];
  }

  if(n<0){
	printf("-1\n");
  }else{
	printf("%d\n", n);
  }

  return 0;
}


Measured memory_bytes: 1764
from collections import defaultdict

S = input()
S = S[::-1]
N = len(S)
memo = defaultdict(int)
memo[0] = 1
ans = 0
rest = 0
for i in range(N):
    rest += int(S[i])*pow(10,i,2019)
    rest %= 2019
    ans += memo[rest]
    memo[rest] += 1
print(ans)



Measured memory_bytes: 74820
import sys
import math
def get_array(): return list(map(int,sys.stdin.readline().strip().split()))
def get_ints(): return map(int,sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
s=input()
t=input()
flag=0
for i in range(len(s)):
    if s[i]==t[i]:
        flag=flag+1 
    else:
        break 
if flag==len(s):
    print("Yes")
else:
    print("No")
    
    

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

// 小数点以下桁数
// fixed << setprecision(i)

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

int main()
{
  int n, ans = 1;
  char c;
  string s;

  cin >> n >> s;
  c = s[0];
  for (int i = 1; i < n; i++)
  {
    if (c != s[i])
    {
      c = s[i];
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3768
/*Remember: The Struggle is Important*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

#define     int          long long int
#define     fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     __gcd((a),(b))
#define     lcm(a,b)     ((a)*(b))/gcd((a),(b))
#define     pb           push_back
#define     ins          insert
#define     F            first
#define     S            second

const int inf=1e18,MOD=1e9+7;

void solve()
{
 int r,d,x;
 cin>>r>>d>>x;

 for(int i=0;i<10;++i)
 {
  x=r*x-d;

  cout<<x<<"\n";
 }
}

int32_t main()
{
 fast();

 int t=1;
 //cin>>t;
 while(t--)
 {
  solve();
 }

 return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(){
  char S[12];
  int max=0,i,count=0;
  int cnt[12];
  scanf("%s",&S);
  for(i=0;i<12;i++){
    cnt[i]=0;
  }

  for(i=0;i<11;i++){
    if(S[i]=='A' || S[i]=='T' || S[i]=='C' || S[i]=='G'){
      cnt[i]=1;
    }
  }
  for(i=0;i<11;i++){
    if(cnt[i]==1){
      count++;
      if(max<count)max=count;
    }else if(cnt[i]==0){
      count=0;
    }
  }
  printf("%d\n",max);

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define RFOR(i, a, b) for(int i = a; i >= b; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
const int INF = 1e9;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
int main() {
    int A, P;
    cin >> A >> P;
    int kakera = A*3 + P;
    cout << (kakera / 2) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define fr1(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define pb push_back
#define md 1000000007
int countDistinct(vector<string> arr, int n)
{
	unordered_set<string> s;
	int res = 0;
	for (int i = 0; i < n; i++) {
		if (s.find(arr[i]) == s.end()) {
			s.insert(arr[i]);
			res++;
		}
	}
	return res;
}
int main()
{
	fast;
	int n;
	cin >> n;
	vector<string> a;
	for (int i = 0; i < n; i++)
	{
		string temp;
		cin >> temp;
		a.pb(temp);
	}
	cout << countDistinct(a, n);
	return 0;
}

Measured memory_bytes: 30176
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>

int main(){
    int a,b,c;
    int k;
    scanf("%d %d %d %d",&a,&b,&c,&k);
    int sum;
     
    if(a<=k){
        sum += a;
        if(k-a>=0){
            if(k-a-b>=0){
                sum += -1*(k-a-b);
            }
        }
    }
    else{
        sum += k;
    }


        


    printf("%d",sum);

    return 0;
}


Measured memory_bytes: 1732
#define _CRT_NONSTDC_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>
#include <set>
#include <map>
#include <numeric>

#define NL << endl

using namespace std;
using ll = long long;
const int INTMAX = numeric_limits<int>::max();
const int INTMIN = numeric_limits<int>::min();
const ll LLMAX = numeric_limits<long long>::max();
const ll LLMIN = numeric_limits<long long>::min();
const int MOD = 1000000007;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

using namespace std;

map<int, int> v;
vector<int> sum;

signed main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		int a = v[t];
		v[t] = a + 1;
	}
	ll ans = 0;
	for (const auto& x : v) {
		if (x.second % 2) ans++;
	}

	cout << ans NL;

	return 0;
}



Measured memory_bytes: 4864
#include <iostream>
#include <string>
#include <stack>

using namespace std;

int main() {
	string a;
	const string b = "()[]";
	while (getline(cin, a)) {
		if (a.size() == 1 && a[0] == '.') {
			break;
		}
		int count[4] = {0};
		bool hantei = true;
		bool hantei2;
		stack<int> stk;
		for (int i = 0; i < a.size(); i++) {
			int j;
			hantei2 = false;
			for (j = 0; j < 4; j++) {
				if (a[i] == b[j]) {
					count[j]++;
					hantei2 = true;
					break;
				}
			}
			if (hantei2) {
			if (j == 0) {
				stk.push(1);
			} else if (j == 2) {
				stk.push(3);
			} else if (!stk.empty() && stk.top() != j) {
				//cout << 'a' << endl;
				hantei = false;
				break;
			} else if (!stk.empty()){
				stk.pop();
			}
			}
			if (count[0] < count[1]) {
				hantei = false;
				break;
			} else if (count[2] < count[3]) {
				hantei = false;
				break;
			}
		}

		if (hantei && (count[0] == count[1] && count[2] == count[3])) {
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
		}
	}
	return 0;
}

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  string l1="";
  int lng = s.length();
  int n1=0,n2=0;
  for(int i = 0; i<lng ; i++){
    l1.append("0");
    i++;
    if(i == lng) break;
    l1.append("1");
  }
  for(int i = 0; i<lng ; i++){
    if(s[i] != l1[i]) n1++;
    else n2++;
  }
  if(n1 <= n2) cout << n1 << "\n";
  else cout << n2 << "\n";
  return 0;
}


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

int mostFrequent(vector<int> arr, int n){
    // Insert all elements in hash.
    unordered_map<int, int> hash;
    for (int i = 0; i < n; i++)
        hash[arr[i]]++;

    // find the max frequency
    int max_count = 0, res = -1;
    for (auto i : hash) {
        if (max_count < i.second) {
            res = i.first;
            max_count = i.second;
        }
    }
    return max_count;
}

int main (){
	int n;
	cin>> n;
	int arr[n];
	vector <int> arr2;
	for(int i= 0; i<n; i++){
		cin>> arr[i];
	}
	for(int i= 0; i<n; i++){
		int x, z;
		x = arr[i]-1;
		z = arr[i]+1;

		arr2.push_back(x);
		arr2.push_back(arr[i]);
		arr2.push_back(z);
	}
	int size = arr2.size();

	sort(arr2.begin(), arr2.end());
	
	cout<< mostFrequent(arr2, size) <<"\n";
	
	

	return 0;
}

Measured memory_bytes: 6896
n=int(input())
res = []
for i in range(n):
    s,p=map(str, input().split())
    res += [(s,int(p))]
res1=res
res = sorted(res, key=lambda x:(x[0],-x[1]))
for i in range(n):
    print(res1.index(res[i])+1)



Measured memory_bytes: 9184
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)

sm=[]
count=0
for i in range(3*N):
    if count==N:
        break
    if i%2==1:
        sm.append(A[i])
        count+=1

ans=sum(sm)
print(ans)

Measured memory_bytes: 119520
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    cout << (N-2) * 180 << endl;
}

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

int main( void )
{
  string S;
  cin >> S;
  int count = 0;
  
  for( int i = 0; i < 3; i++ ) {
    if( S.at( i ) == '1' )
      count++;
  }
  cout << count << endl;
  
}
  

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define dbg(x) cout<<#x" = "<<(x)<<ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, d[55], r = 810;

int main() {
	cin >> n;
	repst(i,1,n) cin >> d[i];
	sort(d+1, d+n+1);
	repst(i,1,n) if (i%2==0) d[i] = 24-d[i];
	sort(d+1, d+n+1);
	repst(i,1,n) chmin(r, d[i]-d[i-1]);
	cout << r << ln;
}

Measured memory_bytes: 256
L = sorted(list(map(int, input().split())), reverse = True)
ans = 0
if (L[1] - L[2]) % 2 != 0:
  L[0] += 1
  L[1] += 1
  ans += 1
ans += L[0] - L[1] + (L[1] - L[2]) // 2
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

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

    int k;
    int x;

    cin >> k >> x;

    if (k * 500 >= x) {
        cout << "Yes";
    } else {
        cout << "No";
    }

    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int solve(string a, string b) {
  int n = a.size(), m = b.size();
  if (n > m) return 1;
  else if (n < m) return -1;
  rep(i, n) {
    if (a[i] > b[i]) return 1;
    else if (a[i] < b[i]) return -1;
  }
  return 0;
}

int main() {
  string a, b;
  cin >> a >> b;

  int ans = solve(a, b);
  if (ans == 1) cout << "GREATER" << endl;
  else if (ans == -1) cout << "LESS" << endl;
  else cout << "EQUAL" << endl;


  
  return 0;
}

Measured memory_bytes: 256
import heapq as hq
n = int(input())
a = list(map(int,input().split()))
x = sum(a[:n])
y = sum(a[2*n:])
fsum = [x]
lsum = [y]
hqx = a[:n]
hqy = [-a[2*n+i] for i in range(n)]
hq.heapify(hqx)
hq.heapify(hqy)
for i in range(n):
    hq.heappush(hqx,a[n+i])
    hq.heappush(hqy,-a[2*n-i-1])
    xmin = hq.heappop(hqx)
    ymax = -hq.heappop(hqy)
    fsum.append(fsum[-1]+a[n+i]-xmin)
    lsum.append(lsum[-1]+a[2*n-i-1]-ymax)
ans = -10**18
for i in range(n+1):
    ans = max(ans,fsum[i]-lsum[-i-1])
print(ans)

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

int main(void)
{
	long long int a, b, c;

	while(cin >> a >> b >> c){
		long long int con;

		if(a == b){
			if(a % c == 0)
				con = 1;
			else
				con = 0;
		}
		else if(!a){
			con = (b / c) + 1;
		}
		else{
			con = (b / c) - (a - 1) / c;
		}

		cout << con << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int c=1, n, count = 0;
    vector<int> arr(200000);
    cin >> n;
    for(int i=0; i<n; i++) {
        cin >> arr[i];
        if(arr[i] == c) {
            c++;
        }
        else {
            count++;
        }
    }
    if(c == 1) cout << -1 << endl;
    else cout << count << endl;
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
//#include<math.h>
#include<string.h>
//#include<time.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)

int main() {
	int i, j;
	char s[8][9];
	for (i = 0; i < 8; i++)
		fscanf(stdin, "%s", s[i]), getchar(), s[i][8] = '\0';

	for (puts("90"), j = 0; j < 8; j++, puts(""))
		for (i = 7; i >= 0; i--) fprintf(stdout, "%c", s[i][j]);
	for (puts("180"), i = 7; i >= 0; i--, puts(""))
		for (j = 7; j >= 0; j--) fprintf(stdout, "%c", s[i][j]);
	for (puts("270"), j = 7; j >= 0; j--, puts(""))
		for (i = 0; i < 8; i++) fprintf(stdout, "%c", s[i][j]);
	return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
  int N;
  cin >> N;
  vector<long long int>A(3*N);
  for(int i=0; i < 3*N; i++)
    cin >> A[i];
  sort(A.begin(), A.end(), greater<long long int>());
  long long int sum = 0;
  for(int i=0; i < N; i++)
    sum += A[2*i+1];
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 2560
# 1
# https://atcoder.jp/contests/keyence2019/tasks/keyence2019_a
if False:
    print('YES' if set(input().split())==set(list('1974')) else 'NO')

# 2
# https://atcoder.jp/contests/keyence2019/tasks/keyence2019_b
if False:
    S=input()
    ans='NO'
    K='keyence'
    for i in range(len(K)):
        l=K[:i]
        r=K[i:]
        # print(l,r)
        if l in S and r in S:
            l_i=S.index(l)
            for j in range(len(S)):
                # print(S[j:j+len(K)-1])
                if j+len(r)-1<len(S) and S[j:j+len(r)]==r:
                    r_i=j
            # print(l_i,r_i)
            if l_i<=r_i:
                ans='YES'
                break
    print(ans)

# 3
# https://atcoder.jp/contests/aising2019/tasks/aising2019_a
if False:
    N=int(input())
    H=int(input())
    W=int(input())
    print((N-H+1)*(N-W+1))

# 4
# https://atcoder.jp/contests/aising2019/tasks/aising2019_b
N=int(input())
A,B=map(int,input().split())
P=[int(i) for i in input().split()]
cnt=[0,0,0]
for p in P:
    if p<=A: cnt[0]+=1
    elif A<p<=B: cnt[1]+=1
    else: cnt[2]+=1
print(min(cnt)) 

Measured memory_bytes: 3064
#include <stdio.h>
#include <math.h>
int main(void){
    long long n,i,min=1000000000000000000,a;
    scanf("%lld",&n);
    min=n;
    for(i=0;i<5;i++){
        scanf("%lld",&a);
        if(min>a) min = a;
    }
    printf("%lld",(long long)ceil((double)n/min)+4);
    return 0;
}


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

int main() {

long long t;
//cin >> t;
t = 1;
while(t--){
	int n;
	cin >> n;
	float x = n/1.08;
	x = ceil(x);
	//cout << x;
	if(floor(x*1.08) == n) cout << x;
	else cout << ":(";
}
return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#define INF 10000000

using namespace std;

int main(){

  int n,m;
  int i,j,k,s;
  int r,a,b,c,d,e;
  int cost[102][102];
  
  while(1){

    cin>>n>>m;
    if(n==0 && m==0)break;

    for(i=1;i<=n;i++)for(j=1;j<=n;j++)cost[i][j]=INF;

    for(s=0;s<m;s++){
      cin>>r;
      
      if(r==0){
	cin>>a>>b;
	if(cost[a][b]==INF)cout<<-1<<endl;
	else cout<<cost[a][b]<<endl;
      } else {
	cin>>c>>d>>e;
	
	if(cost[c][d]>=e){
	  cost[c][d]=cost[d][c]=e;

	for(i=1;i<n+1;i++){
	  for(j=1;j<n+1;j++){
	    for(k=1;k<n+1;k++){
	      cost[j][k]=min(cost[j][k],cost[j][i]+cost[i][k]);
	    }
	  }
	}
	}
	
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1200
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
		
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final int M = sc.nextInt();
			
			System.out.println(M * (M - 1) / 2 + N * (N - 1) / 2);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}


Measured memory_bytes: 22228
import string
dic_str = {}
for i,item in enumerate(string.ascii_uppercase):
  dic_str[item] = i
"""
def rev(lis,bl = False):
  if not "[" in lis:
    return "".join(lis)
  else:
    start = -1
    end = -1
    i = 0
    while(i < len(lis)):
      if (start == -1) and (lis[i] == "["):
        start = i
      if (start != -1) and (lis[i] == "]"):
        end = i
        break
      i += 1
    print(start,end)
    return rev(list("".join(lis[0:start])+rev(lis[start+1:end],True)+"".join(lis[end+1:len(lis)+1])))
"""

  
while(True):
  strs = input()
  
  if strs == ".":
    break
  lis_str = list(strs)
  change_alpha = []
  count = 0
  i = 0
  while(i < len(lis_str)):
    if lis_str[i] in list(string.ascii_uppercase):
      change_alpha.append(string.ascii_uppercase[(dic_str[lis_str[i]]+count)%26])
      count = 0
    elif lis_str[i] == "?":
      change_alpha.append("A")
      count = 0
    elif lis_str[i] == "+":
      count += 1
    elif lis_str[i] == "-":
      count -= 1
    elif (lis_str[i] == "[") or (lis_str[i] == "]"):
      change_alpha.append(lis_str[i])
    i += 1
    
  i = 0
  start = -1
  end = -1
  while(i < len(change_alpha)):
    if change_alpha[i] == "[":
      start = i
      i += 1
    elif change_alpha[i] == "]":
      end = i
      #print(change_alpha)
      #print(change_alpha[start+1:end])
      #print(list(reversed(change_alpha[start+1:end])))
      change_alpha[start+1:end] = list(reversed(change_alpha[start+1:end]))
      #print(change_alpha)
      change_alpha.pop(start)
      change_alpha.pop(end-1)
      start = -1
      end = -1
      i = 0
    else:
      i += 1
  else:
    print("".join(change_alpha))


Measured memory_bytes: 6692
#include<bits/stdc++.h>
using namespace std;
#define int long long  
#define mod 1000000007
#define am 998244353
#define INFi 2147483647
#define INFl 9223372036854775807LL
#define fi first
#define se second
#define be begin()
#define en end()
int abs(int a,int b){
 return max(a,b)-min(a,b);
}
int gcd(int a,int b){//最大公約数
  int c=a%b;
  while(true){
    if(c==0) break;
    a=b;
    b=c;
    c=a%b;
  }
  return b;
}
bool IsPrime(int num){
  if (num < 2) return false;
  else if (num == 2) return true;
  else if (num % 2 == 0) return false;
  double sqrtNum = sqrt(num);
  for(int i=3;i<=sqrtNum;i+=2){
    if(num%i==0){
      return false;
    }
  }
}
int lcm(int a,int b){//最小公倍数
    return (a*b)/gcd(a,b);
}
signed main(){
// __builtin_ctz(N); Nを２で何回割り切れるかを返す
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a;
    int c,d;
    int b[1000000];
    cin>>a;
    for(int i=0;i<a;i++) cin>>b[i];
    c=a-1,d=0;
    int q=0,w=0;
    int p=0,o=0;
    int h=0;
    if(a%2==1) h=1;
    while(true){
	p=0,o=0;
      
	if(q<w) q+=b[d],p=1;
	else w+=b[c],o=1;
	if(c==d) break;
	if(p){
	    d++;
	    if(h) if(d==((a+1)/2)-1) d++;
	}
	
	if(o){
	    c--;
	    if(h) if(c==((a+1)/2)-1) c--;
	}
	
    }
    if(h){
	if(q<w) q+=b[(a+1)/2-1];
	else w+=b[(a+1)/2-1];
    }
    
    cout<<abs(q,w)<<"\n";
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> city(N, 0);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    city.at(a - 1)++;
    city.at(b - 1)++;
  }
  for (int i = 0; i < N; i++) {
    cout << city.at(i) << endl;
  } 
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

typedef long long ll;
typedef pair<int, int> P;

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

int main(){
    vector<int> N(4);
    cin >> N[0] >> N[1] >> N[2] >> N[3];
    sort(N.begin(), N.end());
    int ans = abs((N[0] + N[3]) - (N[1] + N[2]));
    cout << ans << endl;
}


Measured memory_bytes: 3164
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

S = str(input())
Q = int(input())
q = [0 for i in range(Q)]
for i in range(Q):
    q[i] = list(input().split(" "))
# print(q)

status = True # True: normal, False: reversed
ans = collections.deque()
for s in list(S):
    ans.append(s)
for i in range(Q):
    query = q[i]
    if query[0] == "1":
        status = not(status)
    else:
        if query[1] == "1":
            if status:
                ans.appendleft(query[2])
            else:
                ans.append(query[2])
        else:
            if status:
                ans.append(query[2])
            else:
                ans.appendleft(query[2])
if status:
    print("".join(list(ans)))
else:
    print("".join(reversed(list(ans))))


Measured memory_bytes: 38724
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define showmap(is, js, x) {rep(i, is){rep(j, js){cout << x[i][j] << " ";}cout << endl;}}
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}

/*
正面衝突の場合 U-D, L-R
斜め衝突の場合 U-L, L-D, D-R, R-U





*/


int X[1<<18], Y[1<<18];
char D[1<<18];
vector<pair<int, char>> V1[1<<19];
vector<pair<int, char>> V2[1<<19];

int n;

int solve_UR(){
	int Answer = (1 << 24);
	for (int i = 0; i <= 500000; i++) V1[i].clear();
	for (int i = 1; i <= n; i++) {
		if (!(D[i] == 'R' || D[i] == 'U')) continue;
		V1[X[i] + Y[i]].push_back(make_pair(X[i], D[i]));
	}
	for (int i = 0; i <= 500000; i++) {
		sort(V1[i].begin(), V1[i].end());
		for (int j = 0; j < (int)V1[i].size() - 1; j++) {
			if (!(V1[i][j].second == 'R' && V1[i][j + 1].second == 'U')) continue;
			Answer = min(Answer, V1[i][j + 1].first - V1[i][j].first);
		}
	}
	return Answer * 10;
}



int solve_UD(){
	int Answer = (1 << 24);
	for (int i = 0; i <= 500000; i++) V2[i].clear();
	for (int i = 1; i <= n; i++) {
		if (!(D[i] == 'L' || D[i] == 'R')) continue;
		V2[Y[i]].push_back(make_pair(X[i], D[i]));
	}
	for (int i = 0; i <= 500000; i++) {
		sort(V2[i].begin(), V2[i].end());
		for (int j = 0; j < (int)V2[i].size() - 1; j++) {
			if (!(V2[i][j].second == 'R' && V2[i][j + 1].second == 'L')) continue;
			Answer = min(Answer, V2[i][j + 1].first - V2[i][j].first);
		}
	}
	return Answer * 5;
}


void rotate(){
	for (int i = 1; i <= n; i++) {
		int cx = Y[i], cy = 200000 - X[i], cz;
		if (D[i] == 'U') cz = 'R';
		if (D[i] == 'R') cz = 'D';
		if (D[i] == 'D') cz = 'L';
		if (D[i] == 'L') cz = 'U';
		X[i] = cx; Y[i] = cy; D[i] = cz;
	}
}


int main()
{
    cin >> n;
    rep1(i, n){
        cin >> X[i] >> Y[i] >> D[i];
    }

    int t_time = 1<<24;    
    rep(t, 4){
        t_time = min(t_time, solve_UD());
        t_time = min(t_time, solve_UR());
        rotate();
    }

    if (t_time == (1<<24)) cout << "SAFE" << endl;
    else cout << t_time << endl;

}



Measured memory_bytes: 42676
n, a, b = map(int, raw_input().split())
users = raw_input()

ac, bc = 0, 0

for i in range(n):
    if users[i] == 'a':
        if ac + bc < a + b:
            print 'Yes'
            ac += 1
        else:
            print 'No'
    elif users[i] == 'b':
        if ac + bc < a + b and bc < b:
            print 'Yes'
            bc += 1
        else:
            print 'No'
    else:
        print 'No'

Measured memory_bytes: 6276
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n;
string s;

signed main() {
	int i;
	
	cin >> n >> s;
	rep(i, s.length()) {
		int id = (s[i] - 'A' + n) % 26;
		cout << (char)(id + 'A');
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
# include <iostream>

int main() {

	int n;
	std::cin >> n;

	int s[13];
	int h[13];
	int c[13];
	int d[13];

	for (int i = 0; i < 13; i++) {
		s[i] = 0;
		h[i] = 0;
		c[i] = 0;
		d[i] = 0;
	}

	for (int i = 0; i < n; i++) {
		char ch;
		int number;
		std::cin >> ch >> number;
		switch (ch) {
		case 'S':
			s[number - 1] = 1;
			break;
		case 'H':
			h[number - 1] = 1;
			break;
		case 'D':
			d[number - 1] = 1;
			break;
		case 'C':
			c[number - 1] = 1;
			break;
		}
	}

	for (int i = 0; i < 13; i++) {
		if (s[i] == 0)
			std::cout << "S " << i + 1 << std::endl;
	}

	for (int i = 0; i < 13; i++) {
		if (h[i] == 0)
			std::cout << "H " << i + 1 << std::endl;
	}

	for (int i = 0; i < 13; i++) {
		if (c[i] == 0)
			std::cout << "C " << i + 1 << std::endl;
	}

	for (int i = 0; i < 13; i++) {
		if (d[i] == 0)
			std::cout << "D " << i + 1 << std::endl;
	}

	std::cin >> n;

	return 0;
}

Measured memory_bytes: 3080
D = gets.to_i
C = gets.chomp.split.map(&:to_i)
s = D.times.map{gets.split.map(&:to_i)}
c = Array.new(26, 0)
t = []

(0..D-1).each do |i|

  (0..25).each do |l|
    c[l] += C[l]
  end
ans = 0
boder = s[i][0]+6*c[0]

  (1..25).each do |e|
    if s[i][e]+6*c[e] >= boder
      ans = e
      boder = s[i][e]+6*c[e]
    end
  end
c[ans] = 0
puts ans+1
end


  



Measured memory_bytes: 14356
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
//#define db double
#define all(x) x.begin(), x.end()
#define SZ(x) (int)(x.size())
#define mem(x, y) memset(x, y, sizeof(x))
#define what_is(x) cerr <<  "Line " << __LINE__ << ": " << #x << " is " << (x) << endl;
#define suf_zero(x) __builtin_ffs(x)
#define pre_zero(x) __builtin_clz(x)
#define num_one(x) __builtin_popcount(x)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define INFI 2000000009
#define INFLL (ll)1e18+7
#define fi first
#define se second
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1
#define PII pair<int, int>
#define rep(i, begin, end) for(__typeof(end) i =(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
void err(istream_iterator<string> it) {cerr<<endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << " , ";
    err(++it, args...);
}
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//#include<ext/pb_ds/hash_policy.hpp>
//using namespace __gnu_pbds;
//mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
//mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
const int mod = 23333333;
ll qp(ll b, ll n){ll r=1;b%=mod;if(n<0) n+=mod-1;for(;n;n>>=1, b=b*b%mod)if(n&1) r=r*b%mod;return r;}
//#define RG register
///////////// BOUND /////////////////
//tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> T;
/////////////// MACRO ///////////////
const int maxn = 1e5+7;
int vis[maxn], a[maxn];
int main()
{
    int n, k;cin>>n>>k;int x;
    for(int i=1;i<=k;++i) {cin>> x;vis[x]=1;}
    int ok = 0, cnt=0;;
    while(n) a[cnt++] = n%10, n/=10;
    for(int i=cnt-1;i>=0;--i)
    {
        int gai = 0;
        if(ok) {for(int j=0;j<10;++j) if(vis[j]==0) {a[i]=j;gai=1;break;}}
        else 
        {
            for(int j=0;j<10;++j) if(vis[j]==0&&j>=a[i]) 
            {
                if(j>a[i]) ok=1;
                a[i]=j;gai=1;
                break;
            }
        }
        if(!gai)
        {
            for(int j=0;j<10;++j)
                if(vis[j]==0)
                {
                    if(j) cout << j;
                    else 
                        for(int j=1;j<10;++j)
                            if(vis[j]==0)
                            {cout<<j;break;}
                    for(int k=0;k<cnt;++k)
                        cout << j;
                    cout << endl;
                    return 0;
                }
        }
    }
    for(int i=cnt-1;i>=0;--i) cout << a[i];cout<<endl;
}

Measured memory_bytes: 256
import sys
import math
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

def main():
    a, b, h, m = map(int, input().split())
    hr = 30 * h + 0.5 * m
    mr = m * 6
    deg = abs(hr - mr)
    rad = math.radians(deg)
    cos = math.cos(rad)
    c = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * cos)
    print(c)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9448
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
int main(){
    int n,m,q;
    cin>>n>>m>>q;
    auto a=make_vec<int>(n,n);
    rep(i,m){
        int l,r;
        cin>>l>>r;
        l--;r--;
        a[l][r]++;
    }
    
    auto s=make_vec<int>(n+1,n+1);
    rep(i,n){
        rep(j,n){
            s[i+1][j+1]=s[i][j+1]+s[i+1][j]-s[i][j]+a[i][j];
        }
    }
    
    vector<int> V(q),W(q);
    rep(i,q) cin>>V[i]>>W[i];
    
    rep(i,q){
        int v=V[i],w=W[i];
        v--;
        cout<<s[w][w]-s[v][w]-s[w][v]+s[v][v]<<endl;
    }
}



Measured memory_bytes: 3712
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;

 
int main() {
	
	int N,x;
	vector<int> A(100000);
	cin>>N>>x;
	fy(N){
		cin>>A.at(y);
	}
	ll ans=0;
	fy(N-1){
		if(A.at(y)+A.at(y+1)>x){
                   if(y==0&&A.at(y)>x){
                       ans+=A.at(y)-x;
                       A.at(y)=x;
                   }
                      ll k=A.at(y)+A.at(y+1)-x;
			A.at(y+1)-=k;
			ans+=k;

		}
	}
	
	ce(ans)
	
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;
}
int64_t abs(int64_t n) {
  if (n < 0) {
    n = -n;
  }
  return n;
}

int main() {
  int n, x;
  cin >> n >> x;
  vector <int64_t> v(n);
  rep(i, n) {cin >> v.at(i);}
  vector <int64_t> ans(n);
  if (v.at(0) >= x) {
    ans.at(0) = x;
  } else {
    ans.at(0) = v.at(0);
  }
  rep(i, n-1) {
    if (ans.at(i)+v.at(i+1) >= x) {
      ans.at(i+1) = x - ans.at(i);
    } else {
      ans.at(i+1) = v.at(i+1);
    }
  }
  int64_t res = 0;
  rep(i, n) {
    res += v.at(i) - ans.at(i);
  }
  cout << res << endl;
}

Measured memory_bytes: 1792
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;

int main()
{
	int i, j, k, l, m,L,ans,K, n, o,cnt, p,sum,flag;
	cin >> L;
	int N[21][21];
	int d[21] = {};
	int c[21] = {};
	j = L;
	c[0] = 1;
	for (i = 1; i < 21; i++) {
		c[i] = c[i - 1] * 2;
	}
	i = 0;
	while (L > 0) {
		d[i] = L % 2;
		i++;
		L /= 2;
	}
	
	k = i - 1;
	cnt = 0;
	for (l = 0; l < k; l++) {
		if (d[l] == 1) {
			cnt++;
		}
	}
	cout << k + 1 << " " << 2 * k  + cnt << endl;
	sum = c[k];
	for (l = k-1; l >= 0; l--) {
		if (d[l] == 1) {
		
			cout << l + 1 << " " << k + 1<< " " << sum << endl;
			sum += c[l];
		}
	}

	for (l = 1; l <= k ; l++) {
		cout << l << " " << l + 1 << " " << c[l - 1] << endl;
		cout << l << " " << l + 1 << " " << 0 << endl;

	}
	
    return 0;
}



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

int main(){
  int N, K;
  cin >> N >> K;
  
  double ans = 0, tmp_score = 1;
  int times = 1;
  for(int i = N; i >= 1; i--){
    while(times * i < K){
      times *= 2;
      tmp_score /= 2.0;
    }
    ans += tmp_score / N;
  }
  cout << setprecision(12) << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
cnt = 0

while set(h) != {0}:
    height = []
    ind = []
    for i in range(n):
        if h[i] != 0:
            height.append(h[i])
            ind.append(i)
        elif h[i] == 0 and len(height) != 0:
            break

    cnt += min(height)
    for i in range(len(height)):
        h[ind[i]] -= min(height)

print(cnt)

Measured memory_bytes: 3064
package com.example.alds1.ten

import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val t = sc.next()
    val p = sc.next()
//    println(t)
    for (i in 0..t.length - p.length) {
//        println(t[i])
        var match = true
        for (j in 0 until p.length) {
//            println(t[i + j] + " " + p[j])
            if (t[i + j] != p[j]) {
//                println("not equal")
                match = false
                break
            }
        }
        if (match) {
            println(i)
        }
    }
}



Measured memory_bytes: 25632
import sys
sys.setrecursionlimit(100000)
dic={}
for i in range(int(input())):
    s=input()
    try:
        dic[s]+=1
    except:
        dic[s]=1
for i in range(int(input())):
    s=input()
    try:
        dic[s]-=1
    except:
        dic[s]=-1

print(max(list(dic.values())+[0]))

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(void){
long long int x,y;
int count=0;
scanf("%lld %lld",&x,&y);

for(;;){
    if(x<=y){x=x*2;count++;}
    else{break;}
}
printf("%d\n",count);
}

Measured memory_bytes: 128
N,W=map(int,input().split())
wv=[[0,0]]+[list(map(int,input().split())) for _ in range(N)]

dp=[[0 for i in range(W+1)] for j in range(N+1)]

for i in range(1,N+1):
    for j in range(W+1):
        dp[i][j]=dp[i-1][j]
        if j - wv[i][0] >= 0:
            dp[i][j]=max(dp[i][j],dp[i-1][j-wv[i][0]]+wv[i][1])

            
print(max(dp[N]))


Measured memory_bytes: 171656
// https://atcoder.jp/contests/abc118/tasks/abc118_c
 
// http://ctylim.hatenablog.com/entry/2015/08/30/191553
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
 
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define RSORT(c) sort((c).rbegin(), (c).rend())
#define MAXINDEX(c) distance((c).begin(), max_element((c).begin(), (c).end()))
#define MININDEX(c) distance((c).begin(), min_element((c).begin(), (c).end()))
#define DEBUG(x) std::cerr << #x << " = " << (x) << " (" << __FILE__ << "::" << __LINE__ << ")" << std::endl;
#define ERROR(s) std::cerr << "Error::" << __FILE__ << "::" << __LINE__ << "::" << __FUNCTION__ << "::" << (s) << std::endl;
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
 
 
#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;
 
int inputValue(){
  int a;
  std::cin >> a;
  return a;
}
 
void inputArray(int *p, int a){
    rep(i, a){
        std::cin >> p[i];
        // scanf("%d",p+i);
    }
}
 
void inputVector(std::vector<int> *p, int a){
  rep(i, a){
    int input;
    // std::cin >> input;
    scanf("%d",&input);
    p->push_back(input);
  }
}
 
template <typename T>
void output(T a, int precision){
  if (precision > 0){
    std::cout << std::setprecision(precision) << a << "\n";
  }else{
    std::cout << a << "\n";
  }
}
 
using namespace std;
 
int gcd(int a,int b){
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}
 
 
int main(int argc ,char **argv){
 
  int N = inputValue();
  vector <int> v;
  inputVector(&v, N);
 
  // cout << gcd(5,13) << endl;
  auto min = min_element((v).begin(), (v).end());
  int d = *min;
  EACH(k, v) {
    d = gcd(d, *k);
  }
  // cout << d << endl;
  printf("%d\n", d);
 
	return 0;
}



Measured memory_bytes: 892
#include <bits/stdc++.h>
const int INF=1e9;
using namespace std;

int main(){
  int n,m,cnt=0; cin>>n>>m;
  vector<vector<pair<int,int>>> g(n);
  vector<vector<int>> d(n,vector<int>(n,INF));

  for(int i=0; i<m; i++){
    int a,b,c; cin>>a>>b>>c;
    a--; b--;
    g[a].emplace_back(b,c);
    g[b].emplace_back(a,c);
  }

  for(int i=0; i<n; i++) d[i][i] = 0;

  for(int i=0; i<n; i++){
     for(auto itr : g[i]){
       d[i][itr.first] = itr.second;
    }
  }

  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]);
      }
    }
  }

  for(int i=0; i<n; i++){
    for(auto itr : g[i]){
      int j,distance;
      bool trace = false;
      j= itr.first;
      distance = itr.second;
      if(i > j) continue;

      for(int k=0; k<n; k++){
        if(distance + d[j][k] == d[i][k])
          trace = true;
      }
      if(! trace) cnt++;
    }
  }

  cout<<cnt<<endl;

  return 0;

}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
#define ll long long
char a[200];
int n,k;
int main(){
	cin>>n>>a>>k;
	char x=a[k-1];
	for(int i=0;i<strlen(a);i++){
		if(a[i]!=x){
			cout<<"*";
		}
		else cout<<a[i];
	}
	return 0;
}

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

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    vector<int> d(n);
    rep(i,n) d[i] = s[i]-'0';

    vector<vector<int>> dp(n+1,vector<int>(2,0));
    dp[0][0] = 0;
    dp[0][1] = 1;
    
    rep(i,n) {
        dp[i+1][0] = min(dp[i][0]+d[i], dp[i][1]+min(10-d[i], d[i]+1));
        dp[i+1][1] = min(dp[i][0]+min(10-d[i], d[i]+1), dp[i][1]+10-d[i]-1);
    }
    cout << dp[n][0] << endl;
    return 0;
}

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

int main() {
    ios_base::sync_with_stdio(false);	
    cin.tie(0);
	int n, k;
	cin >> n >> k;
	vector<int> v(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	int ans = 0;
	sort(v.begin(), v.end());
	for (int i = 0; i < k; i++) {
		ans += v[i];
	}
	cout << ans << "\n";
	return 0;
}


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

int main(){
    ll a, b, c, k; cin >> a >> b >> c >> k;

    if(k <= a) cout << k << endl;
    else if(k <= a+b) {
        cout << a << endl;
    } else {
        cout << a - (k -b-a) << endl;
    }

    return 0;
}

Measured memory_bytes: 3632
#!/usr/bin/env python3
import sys

# Python Program to find the count of 
# numbers in a range where the number 
# does not contain more than K non 
# zero digits 
  
# This function returns the count of 
# required numbers from 0 to num 
def countInRangeUtil(pos, cnt, tight, num, K): 
  
    # Last position 
    if pos == len(num): 
  
        # If count of non zero digits 
        # is less than or equal to K 
        if cnt == K: 
            return 1
        return 0
  
    # If this result is already computed 
    # simply return it 
    if dp[pos][cnt][tight] != -1: 
        return dp[pos][cnt][tight] 
  
    ans = 0
  
    # Maximum limit upto which we can place 
    # digit. If tight is 1, means number has 
    # already become smaller so we can place 
    # any digit, otherwise num[pos] 
    limit = 9 if tight else num[pos] 
  
    for dig in range(limit + 1): 
        currCnt = cnt 
  
        # If the current digit is nonzero 
        # increment currCnt 
        if dig != 0: 
            currCnt += 1
  
        currTight = tight 
  
        # At this position, number becomes 
        # smaller 
        if dig < num[pos]: 
            currTight = 1
  
        # Next recursive call 
        ans += countInRangeUtil(pos + 1, currCnt, currTight, num, K) 
  
    dp[pos][cnt][tight] = ans 
    return dp[pos][cnt][tight] 
  
# This function converts a number into its 
# digit vector and uses above function to compute 
# the answer 
def countInRange(x, K): 
    global dp, M 
  
    num = [] 
    while x: 
        num.append(x % 10) 
        x //= 10
  
    num.reverse() 
  
    # Initialize dp 
    dp = [[[-1, -1] for i in range(M)] for j in range(M)] 
    return countInRangeUtil(0, 0, 0, num, K) 

def solve(N: int, K: int):
    ans = countInRange(N, K) - countInRange(0, K)
    print(ans)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
dp = []
M = 100

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()



Measured memory_bytes: 5108
#include <stdio.h>

int main()
{
    int count;
    scanf("%d", &count);
    int input[100];
    for (int i = 0; i < count; ++i)
    {
        scanf("%d", &(input[i]));
    }
    for (int i = 0; i < count; ++i)
    {
        printf("%d", input[count - i - 1]);
        if (i != count - 1)
        {
            putchar(' ');
        }
        else
        {
            putchar('\n');
        }
    }
    return 0;
}



Measured memory_bytes: 2604