akhauriyash/Code-Regression huggingface dataset:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(1000000)
n=int(input())
visitedlist=[-1 for  i in range(n)]
kilist=[[] for i in range(n)]
anslist=[0 for i in range(n)]
searchedlist=[-1 for i in range(n)]
for i in range(n-1):
        a,b,c=map(int,input().split())
        kilist[a-1].append((b,c))
        kilist[b-1].append((a,c))        
def search(i):
        searchedlist[i-1]=1
        visitedlist[i-1]=1
        flag=0
        for j in kilist[i-1]:
            if visitedlist[j[0]-1]<0:
                visitedlist[j[0]-1]=1
                flag+=1
                anslist[j[0]-1]=anslist[i-1]+j[1]
        else:
            pass

        if flag>0:    
            for k in kilist[i-1]:
                if searchedlist[k[0]-1]==-1:
                    search(k[0])
q,k=map(int,input().split())
List=[0 for i in range(q)]
search(k)
for i in range(q):
    x,y=map(int,input().split())
    List[i]=anslist[x-1]+anslist[y-1]
for j in List:
    print(j)


Measured memory_bytes: 186928
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    string s;
    cin >> s;
    if (s == "ABC")
    {
        cout << "ARC" << endl;
    }
    else
    {
        cout << "ABC" << endl;
    }
}

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

constexpr int INF = 1e8;
using vi = vector<int>;

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

int main() {
    int W, H;
    cin >> W >> H;
    vector<string> v(H);
    int sy, sx, gy, gx;
    for(int i=0; i<H; ++i) {
        cin >> v[i];
        for(int j=0; j<W; ++j) {
            if(v[i][j] == '%') {
                sy = i;
                sx = j;
            }
            if(v[i][j] == '&') {
                gy = i;
                gx = j;
            }
        }
    }
    int S;
    cin >> S;
    vector<vector<string>> sw(S, vector<string>(H));
    for(int i=0; i<S; ++i) {
        for(int j=0; j<H; ++j) {
            cin >> sw[i][j];
        }
    }
    vector<vector<vi>> state(1 << S, vector<vi>(H, vi(W)));
    for(int i=0; i<H; ++i) {
        for(int j=0; j<W; ++j) {
            if(v[i][j] == '^' || 'A' <= v[i][j] && v[i][j] <= 'Z') {
                state[0][i][j] = 1;
            }
        }
    }
    for(int b=1; b<1<<S; ++b) {
        state[b] = state[0];
        for(int h=0; h<H; ++h) {
            for(int w=0; w<W; ++w) {
                for(int i=0; i<S; ++i) {
                    if((b >> i) & 1) {
                        if(sw[i][h][w] == '*') {
                            state[b][h][w] ^= 1;
                        }
                    }
                }
            }
        }
    }
    vector<vector<vector<vi>>> d(1 << S, vector<vector<vi>>(2, vector<vi>(H, vi(W, INF))));
    d[0][0][sy][sx] = 0;
    queue<tuple<int, int, int, int>> que;
    que.push(make_tuple(0, 0, sy, sx));
    int res = INF;
    while(!que.empty()) {
        int b, flr, y, x;
        tie(b, flr, y, x) = que.front();
        //cout << "b: " << b << " flr: " << flr+1 << "  y: " << y << "  x: " << x << "  d: " << d[b][flr][y][x] << endl;
        if(y == gy && x == gx) {
            res = d[b][flr][y][x];
            break;
        }
        que.pop();
        if(v[y][x] == '|') {
            if(d[b][flr^1][y][x] == INF) {
                d[b][flr^1][y][x] = d[b][flr][y][x] + 1;
                que.push(make_tuple(b, flr^1, y, x));
            }
        }
        if(isalpha(v[y][x])) {
            int k = ('A' <= v[y][x] && v[y][x] <= 'Z' ? v[y][x] - 'A' : v[y][x] - 'a');
            int nb = b ^ (1 << k);
            int nf = state[nb][y][x];
            if(d[nb][nf][y][x] == INF) {
                d[nb][nf][y][x] = d[b][flr][y][x] + 1;
                que.push(make_tuple(nb, nf, y, x));
            }
        }
        for(int i=0; i<4; ++i) {
            int ny = y + dy[i], nx = x + dx[i];
            if(ny < 0 || H <= ny || nx < 0 || W <= nx || v[ny][nx] == '#' || v[ny][nx] != '|' && flr != state[b][ny][nx]) {
                continue;
            }
            if(d[b][flr][ny][nx] == INF) {
                d[b][flr][ny][nx] = d[b][flr][y][x] + 1;
                que.push(make_tuple(b, flr, ny, nx));
            }
        }
    }
    cout << (res == INF ? -1 : res) << endl;
}


Measured memory_bytes: 38412
#define _CRT_SECURE_NO_WARNINGS
#include <cassert>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
ll MOD = 1000000007LL;


bool eq(char a, char b) {
	return a=='?' || b=='?' || a==b;
}

const int SZ = 2033;
char A[SZ], B[SZ], C[SZ];
int LA, LB, LC;
bool AB[SZ*8], BC[SZ*8], AC[SZ*8];

void process(char*S, char*T, bool *shift) {
	for (int i=0; S[i]; i++) for (int j=0; T[j]; j++)
		if (!eq(S[i], T[j]))
			shift[4*SZ + i-j] = true;
}


int main() {
	cin >> A >> B >> C;
	LA = strlen(A);
	LB = strlen(B);
	LC = strlen(C);

	process(A, B, AB);
	process(B, C, BC);
	process(A, C, AC);

	int ans = 1e9;
	for (int ab=-4000; ab<=4000; ab++) for (int bc=-4000; bc<=4000; bc++) {
		if (!AB[4*SZ+ab] && !BC[4*SZ+bc] && !AC[4*SZ+ab+bc]) {
			int L = min(0, min(ab, ab+bc));
			int R = max(LA, max(ab+LB, ab+bc+LC));
			ans = min(ans, R - L);
		}
	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
x = list(map(int, input().split()))
ans = 10**20
for i in range(n-k+1):
  dist = x[k+i-1] - x[i] + min(abs(x[k+i-1]), abs(x[i]))
  if ans > dist:
    ans = dist
print(ans)

Measured memory_bytes: 14384
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#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 repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(ll i=(ll)(b-1);i>=(ll)(a);i--)

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

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,k;cin>>n>>k;
  vector<ll>a(n),sa(n+1);
  rep(i,n)cin>>a[i];
  rep(i,n){
    sa[i+1]=sa[i]+a[i];
  }
  vector<ll>lr;
  rep(i,n)repi(j,i+1,n+1){
    lr.push_back(sa[j]-sa[i]);
  }
  sort(all(lr),greater<ll>());
  ll l=lr.size();
  rrep(i,63){
    ll b=1LL<<i;
    ll cnt=0;
    rep(j,l){
      if(lr[j]&b)cnt++;
    }
    if(cnt>=k){
      rep(j,l){
        if(lr[j]&b){}
        else lr[j]=0;
      }
    }
    else{
      rep(j,l){
        lr[j]|=b;
        lr[j]^=b;
      }
    }
  }
  sort(all(lr),greater<ll>());
  ll res=lr[0];
  rep(i,k){
    res&=lr[i];
  }
  cout<<res<<endl;
  return 0;

}


Measured memory_bytes: 6384
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    int h,w;
    cin >> h >> w;
    vector<vector<char>>c(h*2,vector<char>(w));
    for(int i=0;i<2*h;i+=2)rep(j,w) cin >> c.at(i).at(j);
    for(int i=1;i<2*h;i+=2)rep(j,w) c.at(i).at(j)=c.at(i-1).at(j);
    rep(i,2*h){
        rep(j,w) cout << c.at(i).at(j);
        cout << endl;
    }
}
    
    

Measured memory_bytes: 256
# coding: utf-8

# import numpy as np

"""
20191119
24分ギブアップ
質問

20191120
12分
"""


def main():
    N, W = map(int, input().split())
    ws = [None for _ in range(N)]
    vs = [None for _ in range(N)]
    for i in range(N):
        ws[i], vs[i] = map(int, input().split())

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

    for n in range(N):
        for w in range(W+1):
            if w >= ws[n]:
                dp[n][w] = max(dp[n-1][w-ws[n]]+vs[n], dp[n-1][w])  # use or not use
            else:
                dp[n][w] = dp[n-1][w]  # not use

    return max(dp[-1])


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 171528
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef map<char,int> mci;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vii;
typedef vector<char> vc;
typedef vector<vc> vcc;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define F first
#define S second
#define in insert
#define mina(a,b) (a)=min((a),(b));
#define maxa(a,b) (a)=max((a),(b));
const int INF = 1e9 + 7;
void solve(){
    vi v(3);
    for(int i = 0; i < 3; i++) cin>>v[i];
    sort(all(v));
    cout<<v[0]+v[1];
    
}
int main(){
    int T=1;
    //cin>>T;
    for(int i = 0; i < T; i++) solve(); 
}

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

int main () {
  char N;
  cin >> N;
  
  if ((int)N >=(int)'a' && (int)N<=(int)'z')
    cout << 'a' << endl;
  if ((int)N >=65 && (int)N<=90)
    cout << 'A' << endl;
 
}


Measured memory_bytes: 3672
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
	int N;
	cin >> N;
	if (N % 2 == 1) {
		cout << N / 2 * (N / 2 + 1) << endl;
	}
	else {
		cout << N / 2 * (N / 2) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 string S,T;
 cin >> S >> T;
  //cout << S << T << endl;
  int count = 0;
  for(int i = 0; i < 3; i++){
    if(S.at(i) == T.at(i)){
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){

    int N;
    char a[101],b[101];
    
    scanf("%d",&N);
    scanf("%s %s",&a,&b);

    for(int i=0;i<N;i++){
        printf("%c%c",a[i],b[i]);

    }
   
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void){
	char S[1000001]={};
	int num;
	int count=0;
	scanf("%s",S);

	if(S[0]=='0'){
		num=0;
	}else if(S[0]=='1'){
		num=1;
	}

	for(int i=1; i<sizeof(S); i++){
		if(S[i]==0){ break; } //judge finish
		num++;
		if(S[i]!='0'+(num%2)){ count++; }
	}

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


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

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int start;
    if (a >= c){
        start = a;
    }
    else {
        start = c;
    }
    int end;
    if (b <= d){
        end = b;
    }
    else {
        end = d;
    }
    int ans;
    if (end - start < 0){
        ans = 0;
    }
    else {
        ans = end - start;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
function Main(input) {
  var n = parseInt(input);
  var k = Math.floor(Math.log10(n)); // 10^k≦nを満たす最大のk
  var sum = 0;
  for(var i=1; i<=k; i+=2){
  	sum += Math.pow(10, (i-1))*9;
  }
  if(k%2==0){
  	sum += n-Math.pow(10, Math.floor(Math.log10(n))) + 1;
  }
  console.log(sum);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 11468
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A1 = sc.nextInt();
		int A2 = sc.nextInt();
		int A3 = sc.nextInt();
		if(A1 + A2 + A3 >=22) {
			System.out.println("bust");
		}else {
			System.out.println("win");
		}
	}

}


Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
int main()
{
	int n,m;
	cin>>n>>m;
	char grid[n+1][m+1];
	int dp[n+1][m+1];
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			cin>>grid[i][j];
			dp[i][j] = 0;
		}
	}
	dp[1][1] = 1;
	for(int j=2;j<=m;j++)
	{
		if(grid[1][j]=='.')
		{
			if(grid[1][j-1] == '.')
			{
				dp[1][j] = dp[1][j-1];
			}
		}
	}
	for(int j=2;j<=n;j++)
	{
		if(grid[j][1]=='.')
		{
			if(grid[j-1][1]=='.')
			{
				dp[j][1] = dp[j-1][1];
			}
		}
	}
	for(int i=2;i<=n;i++)
	{
		for(int j=2;j<=m;j++)
		{
			if(grid[i][j]=='.')
			{
				if(grid[i][j-1]=='.' && grid[i-1][j]=='.')
				{
					dp[i][j] = (dp[i-1][j]%mod + dp[i][j-1]%mod)%mod;
				}
				else if(grid[i][j-1]=='.' && grid[i-1][j]!='.')
				{
					dp[i][j] = dp[i][j-1];
				}
				else if(grid[i][j-1]!='.' && grid[i-1][j]=='.')
				{
					dp[i][j] = dp[i-1][j];
				}
			}
		}
	}
	cout<<dp[n][m]%mod<<"\n";
	return 0;
}	


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

#define sz(x) (int)x.size() 
#define pb push_back 
#define mp make_pair 
#define fi(a, b) for(int i=a; i<=b; i++) 
#define fj(a, b) for(int j=a; j<=b; j++) 
#define fo(a, b) for(int o=a; o<=b; o++) 
#define fdi(a, b) for(int i=a; i>=b; i--) 
#define fdj(a, b) for(int j=a; j>=b; j--) 
#define fdo(a, b) for(int o=a; o>=b; o--) 

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while(false) {}
#endif

typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef vector<int> vi; 
typedef vector<ll> vll;
typedef vector<pii> vpii; 
typedef vector<pll> vpll; 
typedef long double ld;
typedef unsigned long long ull;

/////////////////////////////////

int const MAX = 5e3 + 41;
int const MOD = 1e9 +7;

int add(int a, int b) {
	a += b;
	if (a >= MOD) a -= MOD;
	return a;
}

int mult(int a, int b) {
	return (ll) a * b % MOD;
}

int ff[MAX];
vi e[MAX];
int child[MAX];

void dfs0(int x, int p = -1) {
	child[x] = 1;
	for (int y : e[x]) {
		if (y == p) continue;
		dfs0(y, x);
		child[x] += child[y];
	}
}

int d[MAX][MAX];
int dp[2][MAX];
int n;

void clear(int id, int q) {
	fi(0, q) {
		dp[id][i] = 0;
	}
}

void dfs(int x, int p = -1) {
	for (int y : e[x]) {
		if (y == p) continue;
		dfs(y, x);
	}

	memset(dp, 0, sizeof(dp));
	dp[0][1] = 1;
	int sum = 1;
	for (int y : e[x]) {
		if (y == p) continue;
		clear(1, sum);

		fj(0, sum) {
			fo(0, child[y]) {
				{
					//1
					int v1 = dp[0][j];
					int v2 = d[y][o];
					int v = mult(v1, v2);
					dp[1][j + o] = add(dp[1][j + o], v);
				}
				{
					//2
					int v1 = dp[0][j];
					int v2 = d[y][o];
					int v3 = MOD - 1;
					int v4 = ff[o];
					int v = mult(v1, mult(v2, mult(v3, v4)));
					dp[1][j] = add(dp[1][j], v);
				}
			}
		}

		sum += child[y];
		fj(0, sum) {
			dp[0][j] = dp[1][j];
		}
	}

	fj(0, sum) {
		d[x][j] = dp[0][j];
	}
}

int ans;

void solve() {
	ff[0] = 1;
	for (int i = 2; i < MAX; i += 2) {
		ff[i] = mult(ff[i - 2], i - 1);
	}
	dfs0(1);
	dfs(1);

	//
	fi(1, n) {
		err("i = %d\n", i);
		fj(0, child[i]) {
			err("j = %d ways = %d\n", j, d[i][j]);
		}
	}
	//

	fi(0, n) {
		int v1 = ff[i];
		int v2 = d[1][i];
		int v = mult(v1, v2);
		ans = add(ans, v);
	}

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

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	scanf("%d", &n);
	fi(1, n - 1) {
		int x, y;
		scanf("%d %d", &x, &y);
		e[x].pb(y);
		e[y].pb(x);
	}
	solve();		

	
#ifdef LOCAL
	err("ELAPSED TIME: %.3Lf\n", (ld) clock() / CLOCKS_PER_SEC);
#endif	
	
	return 0;
}

Measured memory_bytes: 98560
import sys

n, m = map(int, input().split())
num = [-1]*n

for i in range(m):
  s,c = map(int, input().split())
  if num[s-1] != -1 and num[s-1] != c:
      print(-1)
      sys.exit()
  num[s-1] = c
  
if n == 1 and num[0] == -1:
    num[0] = 0
elif n != 1 and num[0] == -1:
    num[0] = 1

num = ['0' if x == -1 else str(x) for x in num]

if len(str(int(''.join(num)))) == n:
    print(''.join(num))
else:
    print(-1)


Measured memory_bytes: 9224
/*																													   
 Templatka c++ Kacper Fis																							   																											   //
*/																													  
																								   
#include <bits/stdc++.h>																							   
																													   
using namespace std; 																								   
																													   
const int INF = 1000000001;																						   
const float PI = 3.14;																								   
typedef long long LL;																								   
																													   
typedef vector<int> vi;																								   
typedef list<int> li;																								   
typedef queue<int> qi; 																								   
typedef pair<int,int> ii; 																							   
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'															   
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford			   
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra	   
																													   																				   
vector<ii>::iterator iter;																							   
																													   																				   
#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}							   
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}						   
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)													   
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);											   
#define pb(x) push_back(x) 																							   
#define pf(x) push_front(x)																							   
#define mp(x, y) make_pair(x, y)                                                                                       
///////////////////////////////////////////////GLOBAL DEFINITIONS////////////////////////////////////////////////////////


///////////////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])																					 
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);                  												       
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
	int n;
	cin >> n;
	int A[21];
	int B[51];
	int C[51];
	
	for(int i = 1; i <= n; i++){
		cin >> A[i];
	}
	for(int i = 1; i <= n; i++){
		cin >> B[i];
	}
	for(int i = 1; i <= (n-1); i++){
		cin >> C[i];
	}

	int points = 0;
	for(int i = 1; i <= n; i++){
		points += B[A[i]];
		//cout << "current points: " << points << endl;
		if(i > 1){
			if(A[i-1] == A[i]-1){
				//cout << "yes for: " << i << endl;
				points += C[A[i-1]];
			}
		}
	}
	cout  << points << endl;


	
	
	
	
	
	
	
	
	
	
	
	
	return 0;
}


Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <stack>
#include <queue> // priority_queue も入ってる
#include <set>   // 要素数は size() で取得 multisetもある
#include <map>
#include <array> // sizeはコンパイル時定数で固定
#include <vector>
#include <numeric>   // accumulate, gcd
#include <algorithm> // count_ifに必要
#include <iomanip>   // cout << setprecision(15) << x で小数の出力精度を指定
#include <tuple>
#include <utility> //pair

using namespace std;
// 問題が起こるまでintは使用禁止2020-04-13
using ll = long long;

// TODO: 終了判定を改造する
// 終了判定
bool check(ll x, ll y, ll ans)
{
    return x * x * x * x * x - y * y * y * y * y == ans;
}

int main()
{
    ll ans;
    cin >> ans;
    // (x,y)の初期値を入れる
    // (x,y)の初期値
    ll x = floor(sqrt(sqrt((double)ans)));
    ll y = 0;
    bool done = false;
    ll finalX;
    ll finalY;

    if (check(x, y, ans))
    {
        finalX = x;
        finalY = y;
        done = true;
    }

    ll k = 0;

    while (!done)
    {
        k += 2;
        --x;
        --y;
        for (ll i = 0; i < k; ++i)
        {
            ++x;
            if (check(x, y, ans))
            {
                finalX = x;
                finalY = y;
                done = true;
            }
        }
        for (ll i = 0; i < k; ++i)
        {
            ++y;
            if (check(x, y, ans))
            {
                finalX = x;
                finalY = y;
                done = true;
            }
        }
        for (ll i = 0; i < k; ++i)
        {
            --x;
            if (check(x, y, ans))
            {
                finalX = x;
                finalY = y;
                done = true;
            }
        }
        for (ll i = 0; i < k; ++i)
        {
            --y;
            if (check(x, y, ans))
            {
                finalX = x;
                finalY = y;
                done = true;
            }
        }
    }

    cout << finalX << ' ' << finalY << endl;
}

Measured memory_bytes: 3264
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {

	string S;
	cin >> S;
	cout << count(S.cbegin(), S.cend(), '1');
	return 0;
}

Measured memory_bytes: 256
import string

n = int(raw_input())
while n != 0:
	f = []
	t = []
	for i in xrange(n):
		l = raw_input().split()
		f.append(l[0])
		t.append(l[1])
	d = string.maketrans(''.join(f), ''.join(t))
	s = []
	for i in xrange(int(raw_input())):
		s.append(raw_input().strip())
	print ''.join(s).translate(d)
	n = int(raw_input())

Measured memory_bytes: 9628
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

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

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

      return tokenizer.nextToken("\n");
    }

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

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

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

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    String s = sc.next();
    long k = sc.nextLong();
    long sum = 0L;
    int result = 1;
    for (int i = 0; i < s.length(); i++) {
      int d = Character.getNumericValue(s.charAt(i));
      if (d == 1) {
        sum++;
      } else {
        result = d;
        break;
      }
      if (sum >= k) {
        break;
      }
    }
    System.out.println(result);
  }
}

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

int N, M, C, B[20];

int main()
{
  cin >> N >> M >> C;
  for( int i = 0; i < M; i++ ){
    cin >> B[i];
  }
  
  int a;
  int cnt = 0;
  
  for( int i = 0; i < N; i++ ){
    int sum = C;
    for( int j = 0; j < M; j++ ){
      cin >> a;
      sum += a * B[j];
    }
    cnt += sum > 0;
  }
  
  cout << cnt;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <numeric>
#include <sstream>
#include <queue>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl

void solve107(int d, int w, int h) {
    int n;
    cin >> n;
    int r;
    vector<int> v;
    v.push_back(d);
    v.push_back(w);
    v.push_back(h);
    sort(ALL(v));
    double lim = v[0]*v[0]/4.0 + v[1]*v[1]/4.0;
    REP(i,n) {
        cin >> r;
        if (lim < r*r) cout << "OK" << endl;
        else cout << "NA" << endl;
    }
}

int main() {
    int d, w, h;
    while (cin >> d >> w >> h, d + w + h) {
        solve107(d, w, h);
    }
    return 0;
}

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

int main() {
    int T; cin >> T;
    vector<string> tbl = {
        "ッターン！",
        ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"
    };
    while (T--) {
        string s; cin >> s;
        int key = 0, idx = -1;
        for (int i = 0; i < s.length(); i++) {
            if (s[i] == '0') {
                if (key) cout << tbl[key][idx];
                key = 0;
                idx = -1;
            } else {
                key = s[i] - '0';
                (idx += 1) %= tbl[key].size();
            }
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3056
#include <bits/stdc++.h>
#define ii pair <int , int>
#define is pair <int, string>
#define ll long long
#define mx 100000
#define sf scanf
#define sf(n) scanf("%d",&n)
#define pf printf
using namespace std;
vector <int> v;

/*int intConvert(string s){
    int n;
    stringstream geek(s);
    geek >> n;
    return n;
}*/

/*string strConvert(int n){
    string s;
    stringstream ss;
    ss << n;
    s=ss.str();
    return s;
}*/


int main(){
    int a,b;
    cin>>a>>b;
    
    ll ans=a*b;
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3592
const config = {
    input: '/dev/stdin',
    newline: '\n'
};

const line = require('fs').readFileSync(config.input, 'utf-8').split(config.newline);
const gcd = (a, b) => b === 0 ? a : gcd(b, a%b);
console.log(gcd(...line[0].split(' ').map(x => parseInt(x))));



Measured memory_bytes: 17204
#include<stdio.h>

int main(){
  int A[100000];
  int n,i,j,p,r,x,num;

  scanf("%d",&n);
  for(i =0;i < n; i++) scanf("%d",&A[i]);

  r = n-1;
  p = 0;
  x = A[r];
  i = p-1;

  for(j = p; j < r;j++){
    if(A[j] <= x){
      i = i+1;
      num = A[i];
      A[i] = A[j];
      A[j] = num;
    }
  }
  num = A[i+1];
  A[i+1] = A[r];
  A[r] = num;

  for (j = 0 ;j <= i; j++) printf("%d ",A[j]);
  printf("[%d] ",A[i+1]);
  for (j = i + 2 ;j < r; j++) printf("%d ",A[j]);
  printf("%d\n",A[r]);
}



Measured memory_bytes: 2100
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#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 IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  int A, B, M;
  cin >> A >> B >> M;

  vector<int> a(A);
  REP(i, A) cin >> a[i];
  vector<int> b(B);
  REP(i, B) cin >> b[i];

  int ans = INF;
  REP(i, M){
    int x, y, z;
    cin >> x >> y >> z;
    chmin(ans, a[x-1]+b[y-1]-z);
  }

  int sum1 = INF;
  REP(i, A) chmin(sum1, a[i]);
  int sum2 = INF;
  REP(i, A) chmin(sum2, b[i]);

  chmin(ans, sum1+sum2);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int maxn=1e5+5;
const int maxm=5e2+5;
const int maxq=55;
const int INF=0x3f3f3f3f;
int v[maxn];
map<int,int> mp;
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&v[i]);
        }
        int evennum=0,evencnt=0;int evennum2=0,evencnt2=0;
        int oddnum=0,oddcnt=0;int oddnum2=0,oddcnt2=0;
        mp.clear();
        for(int i=1;i<=n;i+=2)
        {
            mp[v[i]]++;
            if(v[i]==oddnum) oddcnt++;
            else if(v[i]==oddnum2)
            {
                oddcnt2++;
                if(mp[v[i]]>oddcnt)
                {
                    int tnum=oddnum;int tcnt=oddcnt;
                    oddnum=oddnum2;oddcnt=oddcnt2;
                    oddnum2=tnum;oddcnt2=tcnt;
                }
            }
            else
            {
                if(mp[v[i]]>oddcnt2)
                {
                    if(mp[v[i]]>oddcnt)
                    {
                        oddnum2=oddnum;oddcnt2=oddcnt;
                        oddnum=v[i];oddcnt=mp[v[i]];
                    }
                    else {oddnum2=v[i];oddcnt2=mp[v[i]];}
                }
            }
        }
        mp.clear();
        for(int i=2;i<=n;i+=2)
        {
            mp[v[i]]++;
            if(v[i]==evennum) evencnt++;
            else if(v[i]==evennum2)
            {
                evencnt2++;
                if(mp[v[i]]>evencnt)
                {
                    int tnum=evennum;int tcnt=evencnt;
                    evennum=evennum2;evencnt=evencnt2;
                    evennum2=tnum;evencnt2=tcnt;
                }
            }
            else
            {
                if(mp[v[i]]>evencnt2)
                {
                    if(mp[v[i]]>evencnt)
                    {
                        evennum2=evennum;evencnt2=evencnt;
                        evennum=v[i];evencnt=mp[v[i]];
                    }
                    else {evennum2=v[i];evencnt2=mp[v[i]];}
                }
            }
        }
        if(oddnum!=evennum)
        {
            printf("%d\n",n-oddcnt-evencnt);
        }
        else
        {
            int ans=min(n-oddcnt-evencnt2,n-oddcnt2-evencnt);
            printf("%d\n",ans);
        }
    }
}


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

ll gcd(ll a, ll b) {
  if(a==0) return b;
  if(a>b) return gcd(a%b, b);
  else return gcd(b%a, a);
}
ll lcd(ll a, ll b) {
  return a*b/gcd(a,b);
}

int main() {
  ll n,m;
  cin >> n >> m;
  string s,t;
  cin >> s >> t;
  bool flag=true;
  ll l=lcd(n,m);
  ll nl=l/n,ml=l/m;
  ll nmLcd = lcd(nl,ml);

  for(ll i=1;i<=l;i+=nmLcd) {
    if( (i-1)%nl==0 && (i-1)%ml==0) {
      if( s[(i-1)/nl] != t[(i-1)/ml]) {
        flag=false;
        break;
      }
    }
  }
  if(flag) cout << l << endl;
  else cout << -1 << endl;
}

Measured memory_bytes: 512
N, M = map(int, input().split())
p = list(map(lambda x: int(x) -1 , input().split()))
class UnionFind:
    def __init__(self, n):
        self.data = [-1] * n
    def union(self, x, y):
        x,y = self.root(x), self.root(y)
        if x != y :
            if self.data[y] < self.data[x]:
                x,y = y,x
            self.data[x] += self.data[y]
            self.data[y] = x
        return x != y
    def root(self, x):
        if self.data[x] < 0 :
            return x
        self.data[x] = self.root(self.data[x])
        return self.data[x]
    def findSet(self, x, y):
        return self.root(x) == self.root(y)
uf = UnionFind(N)
for _ in range(M):
    px,py = map(int, input().split())
    px -= 1
    py -= 1
    uf.union(px,py)
ans = 0
for i, v in enumerate(p):
    ans += 1 if uf.findSet(v,i) else 0
print(ans)


Measured memory_bytes: 14008
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

struct UnionFind {
    vector<int> par, rnk;

    UnionFind(int N) : par(N), rnk(N) {
        for (int i = 0; i < N; ++i)
            par[i] = i;
    }

    int root(int x) {
        return par[x] == x ? x : par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    void unite(int x, int y) {
        x = root(x), y = root(y);
        if (x == y)
            return;
        if (rnk[x] < rnk[y])
            swap(x, y);
        if (rnk[x] == rnk[y])
            rnk[x]++;
        par[y] = x;
    }
};

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

    int N, M;
    cin >> N >> M;
    UnionFind uf(N + M);

    for (int i = 0; i < N; ++i) {
        int K;
        cin >> K;
        for (int j = 0; j < K; ++j) {
            int L;
            cin >> L;
            L--;
            uf.unite(i, N + L);
        }
    }

    bool isok = true;
    for (int i = 1; i < N; ++i) {
        if (!uf.issame(0, i)) {
            isok = false;
            break;
        }
    }

    cout << (isok ? "YES" : "NO") << endl;

    return 0;
}


Measured memory_bytes: 4548
N = int(input())

ac = 0
wa = 0
tle = 0
re = 0

for _ in range(N):
    s = input()
    if s == "AC":
        ac += 1
    elif s == "WA":
        wa += 1
    elif s == "TLE":
        tle += 1
    elif s == "RE":
        re += 1

print("AC x", ac)
print("WA x", wa)
print("TLE x", tle)
print("RE x", re)

Measured memory_bytes: 9208
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
using namespace std;

const auto gcu = getchar_unlocked;
const auto pcu = putchar_unlocked;
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;while(isspace(c)){c=gcu();}
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return n;}
//_T T in(int c){T n=0;bool m=false;while(isspace(c)){c=gcu();}if(c=='-')m=true,c=gcu();
//	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m?-n:n;}
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _ot _il void out
#define _ol _il void outl
_ot(bool b) {pcu('0'+b);}
_ot(const char *s){while(*s)pcu(*s++);}
_ot(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_ot(string s){for(char c:s)pcu(c);}
#endif
_T _ot(T n){static char buf[20];char *p=buf;if(n<0)pcu('-'),n*=-1;
	if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10; while (p!=buf)pcu(*--p);}
_ol(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _ot(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _ot(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _ol(T&&... t){out(move(t)...);outl();}

struct weighted_union_find {
	struct node {int p, r, w;};
	struct P {int p, w;};
	vector<node> nodes;
	weighted_union_find (int n) : nodes(n) {
		for (node &n: nodes)
			n.p = &n - &nodes[0];
	}
	P find(int x) {
		node &n = nodes[x];
		if (n.p != x) {
			P p = find(n.p);
			n.p = p.p;
			n.w = p.w += n.w;
			return p;
		} else
			return {x, 0};
	}
	void unite(int a, int b, int w) {
		P ar = find(a), br = find(b);
		node &an = nodes[ar.p], &bn = nodes[br.p];
		w += ar.w - br.w;
		if (an.r > bn.r) {
			bn.p = ar.p;
			bn.w = w;
		} else {
			an.p = br.p;
			an.w = -w;
			if (an.r == bn.r)
				bn.r++;
		}
	}
	void diff(int a, int b) {
		P ar = find(a), br = find(b);
		if (ar.p == br.p)
			outl(find(b).w - find(a).w);
		else
			outl("?");
	}
};

int main() {
	weighted_union_find u(in());
	for (int q = in(); q; q--) {
		if (in()) {
			int x = in();
			u.diff(x, in());
		} else {
			int x = in(), y = in();
			u.unite(x, y, in());
		}
	}
}


Measured memory_bytes: 3332
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

bool cmp(const pi &a, const pi &b){
  if(a.S != b.S) return a.S > b.S;
  return a.F < b.F;
}

int n, m;

int main(){
  while(scanf("%d%d", &n, &m) && (n||m)){
    vector<pi>res(m);
    rep(i, m) res[i] = (MP(i+1, 0));
    int in;
    rep(i, n) rep(j, m){
      scanf("%d", &in);
      res[j].S += in;
    }
    sort(res.begin(), res.end(), cmp);
    rep(i, m) printf(i?" %d":"%d", res[i].F); puts("");
  }
  return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<vector<int> > Graph;
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; }


const ll INF = 1e16;

int main(){
    int n,m;
    cin >> n >> m;
    int ans = 0;
    vector<vector<int> > s(m);
    vector<int>k(m);
    rep(i,m){
        cin >> k[i];
        rep(j,k[i]){
            int x;cin >> x;x--;
            s[i].push_back(x);
        }
    }
    vector<int>p(m);
    rep(i,m){
        cin >> p[i];
    }
    for(int bit=0;bit<(1<<n);bit++){
        bool flag=false;
        rep(j,m){
            int temp = 0;
            rep(l,k[j]){
                if(1&bit>>s[j][l])temp++;
            }
            if(temp%2!=p[j])flag=true;
        }
        if(!flag)ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
int main()
{
    string s;
    cin >> s;
    rep(i, s.size()) cout << "x";
    cout << endl;
}

Measured memory_bytes: 3552
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  int x,n;
  cin>>x>>n;
  int arr[n];
  for(int i=0;i<n;++i) cin>>arr[i];
  sort(arr,arr+n);
  int ans=0;
  int mindif=min(abs(x-arr[0]),abs(x-arr[n-1]));
  for(int i=0;i<=mindif+1;++i){
    if(!binary_search(arr,arr+n,x-i)){
      ans=x-i;
      break;
    }
    if(!binary_search(arr,arr+n,x+i)){
      ans=x+i;
      break;
    }
  }
  if(n==0)ans=x;
  cout<<ans;
}
    
    


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define fi first
#define se second
#define endl "\n" 
using namespace std;
using db = double;
using ll = long long;
using ull = unsigned long long; 
using pII = pair <int, int>;
using pLL = pair <ll, ll>;
constexpr int mod = 1e9 + 7;
template <class T1, class T2> inline void chadd(T1 &x, T2 y) { x += y; while (x >= mod) x -= mod; while (x < 0) x += mod; } 
template <class T1, class T2> inline void chmax(T1 &x, T2 y) { if (x < y) x = y; }
template <class T1, class T2> inline void chmin(T1 &x, T2 y) { if (x > y) x = y; }
inline int rd() { int x; cin >> x; return x; }
template <class T> inline void rd(T &x) { cin >> x; }
template <class T> inline void rd(vector <T> &vec) { for (auto &it : vec) cin >> it; }  
#define dbg(x...) do { cout << "\033[32;1m" << #x << " -> "; err(x); } while (0) 
void err() { cout << "\033[39;0m" << endl; } 
template <class T, class... Ts> void err(const T& arg, const Ts&... args) { cout << arg << ' '; err(args...); }
template <template<typename...> class T, typename t, typename... A> 
void err(const T <t> &arg, const A&... args) { for (auto &v : arg) cout << v << ' '; err(args...); }
void ptt() { cout << endl; }
template <class T, class... Ts> void ptt(const T& arg, const Ts&... args) { cout << ' ' << arg; ptt(args...); }
template <class T, class... Ts> void pt(const T& arg, const Ts&... args) { cout << arg; ptt(args...); }
void pt() {}
template <template<typename...> class T, typename t, typename... A>
void pt(const T <t> &arg, const A&... args) { for (int i = 0, sze = arg.size(); i < sze; ++i) cout << arg[i] << " \n"[i == sze - 1]; pt(args...); }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll qpow(ll base, ll n) { ll res = 1; while (n) { if (n & 1) res = res * base % mod; base = base * base % mod; n >>= 1; } return res; }
//head
int n, m, T; 
void run() {
	if (n < m) swap(n, m);
	pt((T + n - 1) / n);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	cout << fixed << setprecision(20);
	while (cin >> n >> m >> T) run();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7;
const ll LINF=1e18;
using namespace std;
#define int long long

signed main(){
  int N,M;cin>>N>>M;
  typedef pair<int,int> P;
  std::vector<P> v(N);
  for(int i=0;i<N;i++){
    int a,b;cin>>a>>b;v[i]=P(a,b);
  }
  sort(v.begin(),v.end());
  int ans=0;
  for(int i=0;i<N;i++){
    ans+=min(M,v[i].second)*v[i].first;
    M-=min(M,v[i].second);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1920
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int k = sc.nextInt();
		
		double[] e = new double[n];
		for(int i=0;i<n;i++) {
			int p = sc.nextInt();
			e[i] = (1+p)/2.0;
		}
		
		double sum = 0;
		for(int i=0;i<k;i++) {
			sum+=e[i];
		}
		
		int l = 0, r = k;
		double max = sum;
		while(r<n) {
			sum -= e[l++];
			sum += e[r++];
			if(sum > max)
				max = sum;
		}
		
		System.out.printf("%.12f\n", max);
	}

}


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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int maxn = 11;
VI S[maxn]; int P[maxn];

bool check(const int i, const int mask)
{
    int cnt = 0;
    FOR_ALL(s,S[i]) if (mask & (1<<*s))
        cnt++;
    return cnt % 2 == P[i];
}

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    int n,m;
    while (cin >> n >> m) {
        FOR(i,0,n)
            S[i].clear();
        FOR(i,0,m) {
            int k; cin >> k;
            FOR(_,0,k) {
                int s; cin >> s;
                S[i].push_back(s-1);
            }
        }
        FOR(i,0,m)
            cin >> P[i];
        int ans = 0;
        FOR(mask,0,1<<n) {
            bool good = true;
            FOR(i,0,m)
                good &= check(i,mask);
            if (good)
                ans++;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define For(i,m,n) for(int i=m;i<n;i++)
#define ll long long
#define l long
#define all(x) x.begin(),x.end()
#define pb push_back
#define len(x) x.len
ll mob=1000000007;
ll dp[10000][10000];
int main()
{
int x,y;
cin>>x>>y;
char a[x][y];
dp[0][0]=1;
FOR(i,x)
{
    FOR(j,y){cin>>a[i][j];}
}
FOR(i,x)
{
    FOR(j,y)
    {if(a[i][j]=='.')
      {  if(i==0||j==0)
        { if(i==0&&j!=0)
            dp[i][j]=dp[i][j-1];
          if(j==0&&i!=0)
          dp[i][j]=dp[i-1][j];
        }
        else
        {
             dp[i][j]=(dp[i-1][j]%mob+dp[i][j-1]%mob)%mob;
        }
            
        }
    else continue;
     
        
    }
}



cout<<dp[x-1][y-1]%mob;

return 0;}

Measured memory_bytes: 16324
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define RFOR(i,m,n) for(int i=m;i>=n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

int g(string s){

  int h = (s[0]-'0')*10+s[1]-'0';
  h *=3600;
  int m = (s[3]-'0')*10+s[4]-'0';
  m *=60;
  int t = (s[6]-'0')*10+s[7]-'0';

  return (h+m+t);
}

void f(int n){
  int c[1000000]={};
  rep(i,n){
    string a,b;
    cin>>a>>b;
    int t = g(a);
    int r = g(b);
    c[t]++;
    c[r]--;
  }
  rep(i,1000000){
    if(i==0) continue;
    c[i]+=c[i-1];
  }
  int ans = 0;
  rep(i,1000000){
    ans = max(ans,c[i]);
 } 


    cout<<ans<<endl;
}


int main(){
  while(1){
    int n;
    cin>>n;
    if(n==0) break;
    f(n);
  }

  return 0;
}



Measured memory_bytes: 7104
object Main extends App {
  var a = readInt
  var b = Array.tabulate(a)(i => readInt)
  var max = b.max
  var p = 0
  for(i <- 0 until a ) {
    if(b(i)==max && p!=1) {
      p = 1
      b(i) = 0
      println(b.max)
    } else {
     println(max) 
    }
  }
}

Measured memory_bytes: 48824
/*
      author  : nishi5451
      created : 15.08.2020 21:12:16
*/

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


int main(){
    ll x,k,d;
    cin >> x >> k >> d;
    ll ans;
    if(x<0){
        ll res = abs(x)/d;
        if(k>res){
            if((k-res)%2==0) ans = -(abs(x)%d);
            else ans = -(abs(x)%d)+d;
        }
        else ans = x+k*d;
    }
    else if(x>0){
        ll res = x/d;
        if(k>res){
            if((k-res)%2==0) ans = x%d;
            else ans = x%d-d;
        }
        else ans = x-k*d;
    }
    else{
        if(k%2==0) ans = 0;
        else ans = d;
    }
    cout << abs(ans) << endl;
    return 0;
}

Measured memory_bytes: 3632