akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

const int N = 1e6+6;
int ache[N];
int cnt[N];

void fastin(int &n){
  char c = getchar();
  int neg = 0;
  while((c<48 && c!=45) || c>57)  c = getchar();
  if(c == 45) neg = 1, c=getchar();
  n = 0;
  while(c>=48 && c<=57) n=(n<<3)+(n<<1)+c-48, c=getchar();
  if(neg) n = -n;
  return ;
}


void pcpf(){
  for (int i = 2; i < N; ++i){
    if(cnt[i]==0){
      if(ache[i]) cnt[i]++;
      for (int j = 2*i; j < N; j+=i){
        if(ache[j]) cnt[i]++;
      }
    }
  }
}

int main(){
  ios::sync_with_stdio(0), cin.tie(0);
  
  int n;  fastin(n);
  int a[n];
  for (int i = 0; i < n; ++i){
    fastin(a[i]);
    ache[a[i]]++;
  }
  int gcd = a[0];
  for (int i = 1; i < n; ++i){
    gcd = __gcd(gcd, a[i]);
  }
  if(gcd!=1){
    cout << "not coprime" << endl;
    return 0;
  }
  pcpf();
  int sett = 0;
  for (int i = 0; i < N; ++i){
    if((i!=1 and ache[i]>1) or cnt[i]>1) sett = 1;
  }
  if(sett)  cout << "setwise coprime" << endl;
  else cout << "pairwise coprime" << endl;
  return 0;
}

Measured memory_bytes: 15260
import java.util.*;

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

        int N = sc.nextInt();
        int[] A = new int[N + 1];
        int[] B = new int[N];
        long ans = 0;
 
        for(int i=0; i<=N; i++){
            A[i] = sc.nextInt();
        }
        for(int i=0; i<N; i++){
            B[i] = sc.nextInt();
        }
 
        for(int i=0; i<N; i++){
            int x = Math.min(A[i], B[i]);
            ans += x;
            B[i] -= x;
            int y = Math.min(A[i + 1], B[i]);
            ans += y;
            A[i + 1] -= y;
        }
        System.out.println(ans);
    }
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    map<int, int> cnt;
    int u, v;
    for (int i = 0; i < M; i++) {
        cin >> u >> v;
        cnt[--u]++;
        cnt[--v]++;
    }
    for (int i = 0; i < N; i++) {
        if (cnt[i] % 2) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 4992
import java.util.*;
import java.util.Scanner;

class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        long ans = 0;
        for(int i=N;i>0;i--){
            if(Math.floor(Math.log10(i))%2==0){
                ans++;
            }
        }
        System.out.println(ans);
    }
}

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

int main(){

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

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

int h, w;
char c[105][105];

int main() {
  cin >> h >> w;
  for(int i = 0; i < h; ++i)
    for(int j = 0; j < w; ++j) cin >> c[i][j];
  for(int i = 0; i < 2 * h; ++i) {
    for(int j = 0; j < w; ++j) cout << c[i / 2][j];
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{

	ios_base::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);

// #ifndef ONLINE_JUDGE
// 	freopen("input.txt" , "r" , stdin);
// 	freopen("output.txt" , "w" , stdout);
// #endif

	ll a, b, n, mn, ans = 0;
	cin >> a >> b >> n;
	mn = min(b, n);
	if (mn == b && mn != 1)
	{
		mn = mn - 1;
	}
	ans = (a * mn) / b - a * (mn / b);
	cout << ans << endl;



}


Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
int main(){
int m,d;cin>>m>>d;
int cnt=0;
for(int i=22;i<=d;i++){
    int d1=i%10,d10=(i/10)%10;
    if(d1>=2&&d10>=2&&d1*d10<=m){cnt++;}
}
cout<<cnt<<endl;
}

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

int main(){


	long long N,M;
    std::cin >> N >> M;
  
    vector<pair<long long, long long> > pairs(N);
	
	if(N==1){
		printf("%d",1);
	}
	else{	
    	printf("%d",N-M+1);
	}
}

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

using namespace std;

int MOD=1e9+7;

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

    int dp[n+5];

    for(int i=0; i<=n; i++)
    {
        dp[i]=1;
    }

    int temp;
    for(int i=0; i<m; i++)
    {
        cin>>temp;
        dp[temp]=0;
    }

    for(int i=2; i<=n; i++)
    {
        if(dp[i]!=0){
            dp[i] = (dp[i-1] + dp[i-2])%MOD;
        }
    }

    cout<<dp[n]<<endl;

    return 0;
}

Measured memory_bytes: 640
import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;

immutable int[2][][3] D =
[
    [[1,0],[0,0],[2,0],[1,1],[1,-1]],
    [[1,1],[0,0],[0,1],[0,2],[1,0],[1,2],[2,0],[2,1],[2,2]],
    [[2,0],[0,0],[1,-1],[1,0],[1,1],[2,-2],[2,-1],[2,1],[2,2],[3,-1],[3,0],[3,1],[4,0]],
];
void main()
{
    immutable N = 10;
    immutable M = readln().chomp().to!int();
    auto m = iota(N).map!(_=>readln().split().map!(to!int).array()).array();
    int[3][] r;
    bool check(int x, int y)
    {
        return 0<=x && x<N && 0<=y && y<N && m[y][x]>0;
    }
    bool dfs(int x, int y)
    {
        if(y>=N) return false;
        if(x>=N) return dfs(0,y+1);
        if(m[y][x]==0) return dfs(x+1,y);
        foreach_reverse(i,d;D)
        {
            bool f=true;
            foreach(v;d)
                if(!check(x+v[1],y+v[0]))
                {
                    f=false;break;
                }
            if(!f) continue;
            foreach(v;d) --m[y+v[0]][x+v[1]];
            r~=[x+d[0][1],y+d[0][0],i.to!int()+1];
            if(r.length<M)
            {
                if(dfs(x,y)) return true;
            }
            else
            {
                if(m.map!(a=>a.reduce!"a+b"()).reduce!"a+b"()==0)
                    return true;
            }
            r.popBack();
            foreach(v;d) ++m[y+v[0]][x+v[1]];
        }
        return false;
    }
    dfs(0,0);
    foreach(a;r)
        a.to!(int[]).map!(to!string).join(" ").writeln();
}

Measured memory_bytes: 1116
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <queue>
#include <stack>
#include <stdlib.h>
using namespace std;
#define rep(i,n) for (int (i) = 0; (i) <n; (i)++) 
#include <math.h>
#include <bits/stdc++.h>
using namespace std;
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}

using namespace std;
int main(){
    int n,k;std::cin >> n>>k;
    if(n%k==0)std::cout << 0 << std::endl;
    else std::cout << 1 << std::endl;
    
}



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

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

    ll a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    pair<ll, int> p[m];
    for(int i = 0; i < m; i++){
        int b;
        ll c;
        cin >> b >> c;
        p[i].first = c;
        p[i].second = b;
    }

    sort(p, p + m, greater<pair<ll, int> >());
    sort(a, a + n);

    queue<ll> q;
    for(int i = 0; i < n; i++){
        q.push(a[i]);
    }

    int flag = 0;
    for(int i = 0; i < m; i++){
        for(int j = 0; j < p[i].second; j++){
            ll k = q.front();
            if(k < p[i].first){
                q.pop();
                q.push(p[i].first);
            }else{
                flag = 1;
                break;
            }
        }

        if(flag == 1){
            break;
        }
    }

    ll ans = 0;
    for(int i = 0; i < n; i++){
        ll k = q.front();
        q.pop();
        ans += k;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3456
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }

int N;
int X[16];
int Y[16];
int P[16];

int x_r[16];
int y_r[16];
int x_r_cnt = 0;
int y_r_cnt = 0;

int len()
{
	int sum = 0;

	for (int i = 0; i < N; i++)
	{
		int mi = LLONG_MAX;
		for (int j = 0; j < x_r_cnt; j++)
		{
			int sub = abs(x_r[j] - X[i]);
			mi = min(mi, sub);
		}
		for (int j = 0; j < y_r_cnt; j++)
		{
			int sub = abs(y_r[j] - Y[i]);
			mi = min(mi, sub);
		}

		sum += mi * P[i];
	}

	return sum;
}

int ans;
vector<int> kumi;

void check()
{
	int max = (int)pow(2, kumi.size());
	for (int i = 0; i < max; i++)
	{
		x_r[0] = 0;
		y_r[0] = 0;
		x_r_cnt = 1;
		y_r_cnt = 1;

		for (int j = 0; j < kumi.size(); j++)
		{
			if ((i & (1LL << j)) == 0)
			{
				x_r[x_r_cnt] = X[kumi[j]];
				x_r_cnt++;
			}
			else
			{
				y_r[y_r_cnt] = Y[kumi[j]];
				y_r_cnt++;
			}
		}

		int l = len();
		ans = min(ans, l);
	}
}

void func(int rest, int index)
{
	if (rest == 0)
	{
		check();
		return;
	}

	for (int i = index; i < N; i++)
	{
		kumi.push_back(i);
		func(rest - 1, i + 1);
		kumi.pop_back();
	}
}


signed main()
{
	cin >> N;
	REP(i, N) cin >> X[i] >> Y[i] >> P[i];

	for (int i = 0; i <= N; i++)
	{
		ans = LLONG_MAX;
		func(i, 0);
		cout << ans << endl;
	}
}



Measured memory_bytes: 3328
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] v = new int[n];
    int[] c = new int[n];
    for (int i = 0; i < n; i++) {
      v[i] = sc.nextInt();
    }
    for (int i = 0; i < n; i++) {
      c[i] = sc.nextInt();
    }
    
    System.out.println(maxValue(v, c, 0));
    
    //System.out.println(Arrays.toString(v));
    //System.out.println(Arrays.toString(c));
  }
  
  private static int maxValue(int[] v, int[] c, int start) {
    
    if (start == v.length - 1) {
      return Math.max(v[start] - c[start], 0);
    }
    
    int value1 = v[start] - c[start];
    int value2 = maxValue(v, c, start + 1);
    int sum = value1 + value2;
    
    return Math.max(sum, value2);
  }
}

Measured memory_bytes: 23508
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        //int N=sc.nextInt();
        int[] numbers=new int[3];
        for(int i=0; i<3; i++) {
            numbers[i]=sc.nextInt();
        }
        sc.close();
        int area =numbers[0] * numbers[1]/2;
        System.out.println(area);
    }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define ALL(a)  (a).begin(),(a).end()
 
const ll mod = 1000000007;
const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;
 
template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}
 
template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}


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

  vector<ll> a(n);
  vector<ll> b(n);
  vector<ll> c(n-1);
  
  cin >>a;
  cin >> b;
  cin >> c;


  ll ans = 0;
  ll al=-100;
  for(auto k:a){
    ans+=b[k-1];
    if (al==k-1){
      ans+=c[al-1];
    }
    al=k;
  }

  cout << ans;



}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main{
	final static int MOD = 1000000007;
	final static int INF = 1000000000;

	public static void main(String[] args) throws IOException{
		//final double PI = 3.14159265;
		NScanner sc = new NScanner(System.in);
		for(;;){
			int H = sc.nextInt();
			int W = sc.nextInt();
			if(H == 0 && W == 0)
				break;
			for(int i = 0; i < H; ++i){
				for(int j = 0; j < W; ++j){
					if((i+j) % 2 == 0)
						System.out.print("#");
					else
						System.out.print(".");
				}
				System.out.println();
			}
			System.out.println();

		}
		/*int n = sc.nextInt();
		long sum = 0;minv = INF, maxv = -INF;
		for(int i = 0; i < n; ++i){
			int a = sc.nextInt();
			sum += a;
			minv = Math.min(minv, a);
			maxv = Math.max(maxv, a);
		}
		System.out.printf("%d %d %d\n", minv, maxv, sum);*/
	}

}

class NScanner{

	private BufferedReader br;
	private StringTokenizer tok;

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

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

	private boolean hasNext(){
		return tok.hasMoreTokens();
	}

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

	public int nextInt() throws IOException{
		if(hasNext()){
			return Integer.parseInt(tok.nextToken());
		}else{
			getLine();
			return Integer.parseInt(tok.nextToken());
		}
	}

	public long nextLong() throws IOException{
		if(hasNext()){
			return Long.parseLong(tok.nextToken());
		}else{
			getLine();
			return Long.parseLong(tok.nextToken());
		}
	}

	public double nextDouble() throws IOException{
		if(hasNext()){
			return Double.parseDouble(tok.nextToken());
		}else{
			getLine();
			return Double.parseDouble(tok.nextToken());
		}
	}
}


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

using namespace std;

int main(){
	int data[100][100], M[100], N, K, l[100], flag[100][100], root[100];
	
	while(1){
		cin >> N;
		if(N == 0)
			break;
		
		for(int i = 0; i < 100; i++){
			M[i] = l[i] = 0;
			root[i] = 1;
			for(int j = 0; j < 100; j++)
				data[i][j] = flag[i][j] = 0;
		}
		
		for(int i = 0; i < N; i++){
			cin >> M[i];
			for(int j = 0; j < M[i]; j++){
				cin >> data[i][j];
				flag[i][data[i][j] - 1] = 1;
			}
		}
		cin >> K;
		for(int i = 0; i < K; i++)
			cin >> l[i];
		
		for(int i = 0; i < K; i++){
			for(int j = 0; j < N; j++){
				if(flag[j][l[i] - 1] == 0)
					root[j] = 0;
			}
		}
		
		int count = 0;
		for(int i = 0; i < N; i++){
			if(root[i] == 1)
				count++;
		}
		
		if(count == 1){
			for(int i = 0; i < N; i++){
				if(root[i] == 1){
					cout << i + 1 << endl;
					break;
				}
			}
		}
		else
			cout << -1 << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1240
#include <stdio.h>
#include <inttypes.h>

int N;
int A[512][512];

char kawariwaaru[512][512];

int main(void) {
	int i, j, k;
	int64_t asumikana = 0;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		for (j = 0; j < N; j++) {
			if (scanf("%d", &A[i][j]) != 1) return 1;
		}
	}
	for (k = 0; k < N; k++) {
		for (i = 0; i < N; i++) {
			for (j = 0; j < N; j++) {
				if (A[i][k] + A[k][j] < A[i][j]) {
					puts("-1"); /* 最短じゃねーじゃねーか！ */
					return 0;
				} else if (A[i][k] + A[k][j] == A[i][j] && k != i && k != j) {
					kawariwaaru[i][j] = 1; /* かわりはあるもの */
				}
			}
		}
	}
	for (i = 0; i < N; i++) {
		for (j = i + 1; j < N; j++) {
			if (!kawariwaaru[i][j]) asumikana += A[i][j];
		}
	}
	printf("%" PRId64 "\n", asumikana);
	return 0;
}


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

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

    int num_start = 0;
    int num_last = 0;
    int flag = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'A' && flag == 0){
            flag = 1;
            num_start = i;
        }
        else if(s[i] == 'Z' && flag == 1){
            num_last = i;
        }
    }

    cout << num_last - num_start + 1 << endl;
}

Measured memory_bytes: 640
A, B, C = map(int, input().split())
A, B, C = min(A, B, C), A+B+C - min(A, B, C) - max(A, B, C), max(A, B, C)
if A % 2 == B % 2 == C % 2:
    print((C-A)//2 + (C-B)//2)
elif A % 2 == B % 2:
    print((C-A)//2 + (C-B)//2 + 1)
else:
    print((C-A)//2 + (C-B)//2 + 2)


Measured memory_bytes: 38256
#include <iostream>
#include <string>

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

  std::string S;
  std::cin >> S;
  if(S[0] == 'S'){
    if(S[1] == 'U'){
      std::cout << 7 << std::endl;
    }
    else {
      std::cout << 1 << std::endl;
    }
  }
  else if (S[0] == 'M') {
    std::cout << 6 << std::endl;
  }
  else if (S[0] == 'T') {
    if (S[1] == 'U') {
      std::cout << 5 << std::endl;
    }
    else {
      std::cout << 3 << std::endl;
    }
  }
  else if (S[0] == 'W') {
    std::cout << 4 << std::endl;
  }
  else {
    std::cout << 2 << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

			int result = 0;
			for (int i = 0; i < k; i++) {
				result += l[n - 1 - i];
			}
			System.out.println(result);
		}
	}
}

Measured memory_bytes: 21972
N = int(input())
H = list(map(int, input().split()))

count = 1
for i in range(N-1,0,-1):
    subcount = 0
    for j in range(1,i+1):
        if H[i] >= H[i-j]:
            subcount += 1
        else:
            break
    if subcount == i:
        count += 1
print(count)

Measured memory_bytes: 3060
#include<iostream>
#include<cstring>
#define INT_MAX 0x3f3f3f3f

using namespace std;

int n,m,x,ans=INT_MAX;
int a[20][20],c[20];

void dfs(int idx,int p[],int cost){
    if(idx==n)return;
    int tmp[20],cnt=0;
    for(int i=0;i<m;i++){
        tmp[i]=p[i]+a[idx][i];
        if(tmp[i]>=x)cnt++;
    }
    if(cnt==m){
        ans=ans<=(cost+c[idx])?ans:(cost+c[idx]);
        dfs(idx+1,p,cost);
    }else{
        dfs(idx+1,p,cost);
        dfs(idx+1,tmp,cost+c[idx]);
    }
}

int main(){
    int p[20];
    memset(p,0,sizeof(p));
    cin>>n>>m>>x;
    for(int i=0;i<n;i++){
        cin>>c[i];
        for(int j=0;j<m;j++){
            cin>>a[i][j];
        }
    }
    dfs(0,p,0);
    if(ans==INT_MAX){
        cout<<-1<<'\n';
    }else{
        cout<<ans<<'\n';
    }
    return 0;
}

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

bool bad(const pair<int, int>& p1, const pair<int, int>& p2) {
    return p1.first > p2.first + 1;
}

void solve() {
    int H, W, M;
    cin >> H >> W >> M;
    vector<int> row(H, 0);
    vector<int> col(W, 0);
    set<pair<int, int>> st;
    for (int i = 0; i < M; ++i) {
        int h, w; cin >> h >> w; h--; w--;
        row[h]++;
        col[w]++;
        st.insert({h, w});
    }
    set<pair<int, int>, greater<pair<int, int>>> st1;
    set<pair<int, int>, greater<pair<int, int>>> st2;
    for (int i = 0; i < H; ++i) {
        if (row[i] == 0) continue;
        st1.emplace(row[i], i);
    }
    for (int i = 0; i < W; ++i) {
        if (col[i] == 0) continue;
        st2.emplace(col[i], i);
    }

    int ans = 0;
    for (auto it1 = st1.begin(); it1 != st1.end(); ++it1) {
        bool there = false;
        if (bad(*st1.begin(), *it1)) break;
        for (auto it2 = st2.begin(); it2 != st2.end(); ++it2) {
            if (bad(*st2.begin(), *it2)) break;
            int temp = it1->first + it2->first;
            if (st.count({it1->second, it2->second})) { there = true; temp--; }
            ans = max(ans, temp);
            if (!there) break;
        }
        if (!there) break;
    }
    cout << ans << endl;
}

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

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


Measured memory_bytes: 47788
using System;
using System.Linq;
class Program
{
    public static void Main()
    {
        string[] str = Console.ReadLine().Split(' ');
        int a, b, c, d;
        a = int.Parse(str[0]);
        b = int.Parse(str[1]);
        c = int.Parse(str[2]);
        d = int.Parse(str[3]);
        int ans = Math.Max(Math.Min(b, d) - Math.Max(a, c), 0);
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - 48;}
char myitoc(int N) {return '0' + N;}

signed main()
{
  int N, A;
  cin >> N >> A;
  vector<int> X(N);
  for (int i = 0; i < N; i++)
  {
    cin >> X.at(i);
  }
  
  vector<vector<int>> dp(N + 1, vector<int>(3000, 0));
  dp.at(0).at(0) = 1;
  for (int i = 0; i < N; i++)
  {
    for (int j = i; j >= 0; j--)
    {
      for (int k = 0; k < 50 * i + 1; k++)
      {
        dp.at(j + 1).at(k + X.at(i)) += dp.at(j).at(k);
      }
    }
  }
  
  
  int ans = 0;
  for (int i = 1; i < N + 1; i++)
  {
    ans += dp.at(i).at(i * A);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int N,M,X,Y;
    int x,y, x_max = -100, y_min = 100;
    
    //input
    cin >> N >> M >> X >> Y;
    for(int i=0; i<N; i++){
        cin >> x;
        if(x > x_max){
            x_max = x;
        }
    }
    for(int i=0; i<M; i++){
        cin >> y;
        if(y < y_min){
            y_min = y;
        }
    }
    if(X < Y){
        int Z = Y;
        for(int i=Z; i>X; i--){
            if(i > x_max && i <= y_min){
                cout << "No War" << endl;
                return 0;
            }
        }
    }
    cout << "War" << endl;
}


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

int main(){
    int n,p,a,i;
    while(cin >> n && n){
        p = 0;
        for(i = 0;i < 9;i++){
            cin >> a;
            p += a;
        }
        cout << n - p << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
char getGrade(int m,int f,int r){
   int sum = m+f;
   char grade;
   if(m==-1||f==-1){
       grade='F';
}else if(80<=sum){
    grade='A';
}else if(65<=sum&&sum<80){
    grade='B';
}else if(50<=sum&&sum<65){
    grade='C';
}else if(30<=sum&&sum<50){
    if(50<=r)grade='C';
    else grade='D';
}else if(sum<30){
    grade='F';
}
return grade;
}
int main(){
    int m,f,r;
    while(1){
        cin>>m>>f>>r;
        if(m==-1&&f==-1&&r==-1)break;
        cout<<getGrade(m,f,r)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3096
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int[] x = new int[105];
        int max = 0;
        boolean f = false;

        while(input.hasNext()) {
            int t = input.nextInt();
            x[t] += 1;
        }
        for (int n : x) {
            if (max < n) {
                max = n;
            }
        }
        for (int i = 1; i < 105; i++) {
            if (x[i] == max) {
                System.out.println(i);
            }
        }
    }
}

Measured memory_bytes: 26308
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#if __cplusplus >= 201103L
#include <chrono>
using namespace std::chrono;
#endif
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#ifdef LOCAL
#define prln(x) (cout << #x << ' ' << x << endl)
#define pr(x) (cout << #x << ' ' << x << ' ' )
#define prv(x) (cout << x << ' ')
#else
#define prln(x) 
#define pr(x)
#define prv(x)
#endif
#define clr(x) memset((x), 0, sizeof((x)))
#define clr1(x) memset((x), -1, sizeof((x)))
#define endl "\n"
#define pi acos(-1)
#define rep(i, st, ed) for (int i = (st); i <= (ed); ++i)
#define rep0(i, st, ed) for (int i = (st); i < (ed); ++i)
#define per0(i, st, ed) for (int i = (st); i > ed; --i)
#define per(i, st, ed) for (int i = (st); i >= ed; --i)
#define chmin(a, b) (a = a > b ? b : a)
#define chmax(a, b) (a = a < b ? b : a)
template<class T> void _sf(T &x) {cin >> x;}
void _sf(int &x) {scanf("%d", &x);}
void _sf(ll &x) {scanf("%lld", &x);}
void _sf(double &x) {scanf("%lf", &x);}
void _sf(char &x) {scanf(" %c", &x);}
void _sf(char *x) {scanf("%s", x);}
void sf() {}
template <class T, class...U> void sf(T & head, U&... tail) { _sf(head); sf(tail...);}
template<class T> void _out(const T &x) { cout << x; }
void _out(const int &x) { printf("%d", x); }
void _out(const ll &x) { printf("%lld", x); }
void _out(const double &x) { printf("%.16f", x); }
void _out(const char &x) { putchar(x); }
void _out(const char *x) { printf("%s", x); }
template<class T,class U> void _out(const pair<T,U> &x) {_out(x.F); putchar(' '); _out(x.S);}
template<class T> void _out(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _out(*i++)) if (i != x.cbegin()) putchar(' '); }
void out() {}
template<class T, class... U> void out(const T &head, const U &... tail) { _out(head); putchar(sizeof...(tail) ? ' ' : '\n'); out(tail...); }
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;

int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}


int main(){
    // #ifdef LOCAL
    //     freopen("in.txt", "r", stdin);
    //     freopen("out.txt", "w", stdout);
    // #endif
    int x;
    sf(x);
    for (int i = 1; i <= 8; ++i) {
        int l = 400 + (i - 1) * 200;
        int r = 599 + (i - 1) * 200;
        if (l <= x && x <= r) {
            printf("%d\n", 8 - i + 1);
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3824
from operator import itemgetter
N=int(input())
xl=[list(map(int, input().split())) for i in range(N)]
ab=[[xl[i][0]-xl[i][1], xl[i][0]+xl[i][1]] for i in range(N)]
ab=sorted(ab, key=itemgetter(0))
hiku=0
a=ab[0][0]
b=ab[0][1]
for i in range(1, N):
  if b>ab[i][0]:
    hiku+=1
    b=min(b, ab[i][1])
  else:
    b=ab[i][1]
      
print(N-hiku)

Measured memory_bytes: 43560
import sys
from collections import defaultdict
from collections import deque
import numpy as np
import heapq
from heapq import heappush, heappop
import itertools


#read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

N = int(input())

PATH = []
#COLOR = [[None for _ in range(N+1)] for _ in range(N+1)]
COLOR = defaultdict(int)
PT = [[] for _ in range(N+1)]
cmax = 1
for i in range(N-1):
    a, b = map(int, input().split())
    PATH.append((a, b))
    PT[a].append(b)
    PT[b].append(a)

    '''
    la = len(PT[a])
    lb = len(PT[b])

    l = la if la > lb else lb
    if l > cmax:
        cmax = l
    '''

q = deque([(1, -1)])
while(q):
    a, ng = q.popleft()
    bs = PT[a]

    c = 1
    for b in bs:
        if b > a:
            na = a
            nb = b
        else:
            na = b
            nb = a

        cab = COLOR[(na, nb)]

        if cab == ng:
            continue

        if cab == 0:
            if c == ng:
                c += 1
            clr = c
            COLOR[(na, nb)] = clr
            q.append((b, clr))
            c += 1

print(max(COLOR.values()))

clr = []
for a, b in PATH:
    clr.append(COLOR[(a, b)])

print("\n".join(map(str, clr)))


Measured memory_bytes: 57256
/*Author - sambhu show(jgec) */
#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define itc ll t;cin>>t;while(t--)
#define PI 3.141592653589793238
//ang=(PI*ang)/180.0 in radian
#define Max(a,b,c) max(a,max(b,c));
#define Min(a,b,c) min(a,min(b,c));
#define all(v) v.begin(),v.end()
#define ll long long int
#define ld long double
#define pb push_back
#define eb emplace_back
#define gcd(a,b) __gcd(a,b)
#define fi first
#define se second
#define endl "\n"
int dx[4] = {0, -1, 0, 1};
int dy[4] = {1, 0, -1, 0};
int XX[8] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
int main()
{

	int n;
	cin >> n;
	int ar[n + 1];
	int c = 0;

	for (int i = 1; i <= n; i++)
	{	cin >> ar[i];
		if (i & 1 && ar[i] & 1)
			c++;
	}
	cout << c << endl;

	return 0;
}

Measured memory_bytes: 3588
n = int(input())
t,a = map(int, input().split())
plcs = map(int, input().split())
min_val = float('inf')
min_ind=0
for i, plc in enumerate(plcs,1):
  tmp = t - 0.006 * plc
  if abs(tmp - a) < min_val:
    min_val = abs(tmp - a)
    min_ind = i

print(min_ind)

Measured memory_bytes: 3064
#122 C
N,Q= map(int,input().split())
S=input()
ans=[0]*(N+1)

for i in range(2,N+1):
    ans[i]=ans[i-1]
    if S[i-2:i]=='AC':
        ans[i]+=1
    
for i in range(Q):
    l,r=map(int,input().split())
    print(ans[r]-ans[l])

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

using namespace std;

int n;
vector<int> x(100, 0);

int main(){
    cin >> n;
    cin.ignore();
    for(int i = 0; i < n; i++){
        cin >> x[i];
    }
    cin.ignore();

    if(n <= 0) return 0;

    int ans = INT_MAX;
    for(int p = 1; p <= 100; p++){
        int sum = 0;
        for(int i = 0; i < n; i++){
            sum += (x[i] - p) * (x[i] - p);
        }
        if(ans > sum){
            ans = sum;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		n%= 1000;
		int change = -1;
		if(n !=0 ) {
			change = 1000 - n;
		} else {
			change = 0;
		}
		System.out.println(change);
	}

}


Measured memory_bytes: 27016
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("Failed to read bytes") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:usize = read();
    let q:usize = read();
    let mut g = vec![vec![0];n];
    for _ in 0..n-1 {
        let a:usize = read();
        let b:usize = read();
        g[a-1].push(b-1);
        g[b-1].push(a-1);
    }
    let mut parr = vec![0; n];
    for _ in 0..q {
        let p:usize = read();
        let q:usize = read();
        parr[p-1] += q;
    }

    let mut seen = vec![false; n];
    dfs(&g, &mut parr, &mut seen, 0, 0);
    for i in parr {
        print!("{} ", i);
    }
}

fn dfs(g: &Vec<Vec<usize>>, parr: &mut Vec<usize>, seen:&mut Vec<bool>, v:usize, pv:usize) {
    seen[v] = true;
    if v!= 0 {
        parr[v]+= parr[pv];
    }
    for nv in &g[v] {
        let nv = *nv;
        if seen[nv] {
            continue;
        }
        dfs(g, parr, seen, nv, v);
    }
}

Measured memory_bytes: 35112
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static int N;
	static int[]A, B, C;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		A = new int[N];
		B = new int[N];
		C = new int[N];
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		for(int i = 0; i < N; i++) {
			B[i] = sc.nextInt();
		}
		for(int i = 0; i < N; i++) {
			C[i] = sc.nextInt();
		}
		sc.close();
		Arrays.sort(A);
		Arrays.sort(B);
		Arrays.sort(C);
		long ans = 0;

		for(int i = 0; i < N; i++) {
			int k = B[i];
			int id1 = bs2(k, A);
			//System.out.println(id1);
			if(id1 != -1 && id1 != N) {
				int id2 = bs1(k, C);
				if(id1 != -1 && id2 != N) {
					ans += (long)(id1 + 1) * (N - id2);
				}
			}
		}
		System.out.println(ans);
	}
	// 条件を満たす最小の要素を返す
	static int bs1(int k, int[]G) {
		int l = -1;
		int r = N;
		while(r - l > 1) {
			int mid = (l + r) / 2;
			if(G[mid] > k) {
				r = mid;
			}else {
				l = mid;
			}
		}
		return r;
	}
	// 条件を満たす再際の要素を返す
	static int bs2(int k, int[]G) {
		int l = -1;
		int r = N;
		while(r - l > 1) {
			int mid = (l + r) / 2;
			if(G[mid] < k) {
				l = mid;
			}else {
				r = mid;
			}
		}
		return l;
	}
}

Measured memory_bytes: 94984
#include <bits/stdc++.h>
using namespace std;
 
//long long
using ll = long long;
 
// pair<int, int>
using PII = pair<int, int>;
 
//最大値、mod
const int MOD = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;
 
//出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(10) << x << endl
#define printc(x) cout << setw(2) << setfill('0') << x << endl;
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()
 
//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
 
//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
 
// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}
 
// a = max(a, b), a = min(a, b)
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; }
 
// 階乗(MODをとる)
ll pow_mod(ll num, ll pow, ll mod) {
    ll prod = 1;
    num %= mod;
    while (pow > 0) {
        if (pow & 1) prod = prod * num % mod;
        num = num * num % mod;
        pow >>= 1;
    }
    return prod;
}
 
 
 
// 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度)
// COMinit()
// COM(x, y)
// とコンビで使う
 
// テーブルを作る前処理
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
//int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};


int main(){
    ll N, X;
    cin >> N >> X;
    vector<ll>a(N);
    REP(i, N) cin >> a.at(i);
    ll ans = 0;
    if(a.at(0) > X) {
      ans += a.at(0) - X;
      a.at(0) = X;
    }
    for(ll i = 1; i < N; i++){
        ll tmp = 0;
        if(X < a.at(i) + a.at(i - 1)) {
            tmp = (a.at(i) + a.at(i - 1)) - X;
            a.at(i) -= tmp;
            ans += tmp;
        }
    }
    print(ans);
    return 0;
}

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

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

    long long b[500];

    long long a[500];
    int ans = 0;
    for(int i = 0;i < m;i++){
        cin >> b[i];
    }

    for(int i = 0;i < n;i++){
        long long tmp = 0;
        for(int j = 0;j < m;j++){
            cin >> a[j];
            tmp += a[j] * b[j];
        }
        if(tmp + c > 0) ans++;
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(x) cerr << #x << ": " << x << '\n';
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll x, y, cnt = 0;
  cin >> x >> y;
  while (x <= y) {
    x *= 2;
    cnt++;
  }
  cout << cnt << '\n';
}


Measured memory_bytes: 256
/*author:anshumanc007
   created on:08/01/2019
            */
//EMBRACE THE STRUGGLE!!!
#include <bits/stdc++.h>
#include <queue>
#include <stack>
using namespace std;


#define first fi
#define second se
typedef pair<long long int,long long int> pa;
#define MAX 100005
long long int MOD=1e9+7;
long long int INF=1e18;
long long int dp[105][MAX];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long int i,j,k,l,m,n,o,p,q,r,x,y,a,b,mini=INF,maxi=0,cnt=0,W;
    cin>>n>>W;
    long long int A[n];
    long long int value[n];
    for(i=0;i<n;i++)
    {
        cin>>A[i]>>value[i];
    }
    for(i=0;i<=W;i++)
    {
        for(j=0;j<=n;j++)
        {
            
        
            dp[j][i]=0;
        }
    }
    for(j=1;j<=n;j++)
    {
        for(i=1;i<=W;i++)
        {
            if(i>=A[j-1])
            {
                dp[j][i]=max(dp[j-1][i],dp[j-1][i-A[j-1]]+value[j-1]);
                
            }
            else
            {
                dp[j][i]=dp[j-1][i];
            }
        }
       
    }
    cout<<dp[n][W];
    
    
}

Measured memory_bytes: 80128
#include <stdio.h>
#include <math.h>
int main(void){
    int n,i,sum=0,max=0;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(max<a[i]) max=a[i];
        sum+=a[i];
    }
    if(max<sum-max) printf("Yes");
    else printf("No");
}

Measured memory_bytes: 128
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    unused_imports,
    dead_code
)]
//use permutohedron::LexicalPermutation as _;
use proconio::input;
//use proconio::marker::*;
use std::collections::*;
//use std::cmp::*;
//use std::num;
//use petgraph::unionfind::UnionFind;
const MOD: i64 = 1_000_000_007;
fn main() {
    input! {
        N:usize,mut K:usize,A:[i64;N]
    }

    let mut poss = Vec::with_capacity(N);
    let mut negs = Vec::with_capacity(N);
    for a in A {
        if a > 0 {
            poss.push(a);
        } else if a < 0 {
            negs.push(a);
        }
    }
    let z = N - poss.len() - negs.len();

    // 0の利用が不可避な場合
    if poss.len() + negs.len() < K || (z > 0 && poss.len() + negs.len() == K && negs.len() % 2 != 0)
    {
        println!("0");
        return;
    }

    // 正の数がない場合。
    if poss.len() == 0 {
        if K % 2 != 0 && z > 0 {
            // negs を奇数個選んだらマイナスになってしまうので、0があるなら0の方がマシ。
            println!("0");
            return;
        }
        negs.sort();
        if K % 2 != 0 {
            // 負の数を絶対値の小さい方からK個選ぶ。
            negs.reverse();
        }
        let mut ans = 1;
        for i in 0..K {
            ans = ans * negs[i] % MOD;
            //println!("negs_i={},ans={}", negs[i], ans);
        }
        ans = (ans + MOD) % MOD;
        println!("{}", ans);
        return;
    }

    let mut i = 0;
    let mut j = 0;
    let mut ans = 1;
    if N == K {
        // 全てを選ぶしかない場合
        i = poss.len();
        j = negs.len();
    } else {
        // それ以外の場合、まず絶対値の大きい順に並べる
        // possは最低1個以上ある。
        poss.sort();
        poss.reverse();
        negs.sort();
        if K % 2 != 0 {
            // Kが奇数の場合、possを一個追加して、Kを減らす。
            K = K - 1;
            i += 1;
        }
        // 2個ずつ追加していく。
        K = K / 2;
        for k in 0..K {
            if i + 1 >= poss.len() {
                j += 2;
            } else if j + 1 >= negs.len() {
                i += 2;
            } else if poss[i] * poss[i + 1] > negs[j] * negs[j + 1] {
                i += 2;
            } else {
                j += 2;
            }
        }
    }
    for a in 0..i {
        ans = ans * poss[a] % MOD;
    }
    for a in 0..j {
        ans = ans * negs[a] % MOD;
    }
    ans = (ans + MOD) % MOD;
    println!("{}", ans);
}


Measured memory_bytes: 7328
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

int N,K;
int A[110];
int memo[2][100010];

int DP(int p,int k)
{
	if(memo[p][k]!=0)return memo[p][k];
	int res=0;
	
	rep(i,0,N)
	{
		if(k<A[i])continue;
		if(p==0)chmax(res,DP(p^1,k-A[i]));
		else chmin(res,DP(p^1,k-A[i]));
	}
	if(res==0)
	{
		if(p==0)res=-1;
		else res=1;
	}

	memo[p][k]=res;
	return memo[p][k];
}

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

	cin>>N>>K;
	rep(i,0,N)cin>>A[i];
	rep(i,0,A[0])
	{
		memo[0][i]=-1;
		memo[1][i]=1;
	}

	int ans=DP(0,K);
	if(ans==1)cout<<"First"<<endl;
	else cout<<"Second"<<endl;
	
	return 0;
}

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

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout << #x << ": " << x << endl

void solve(long long N, std::vector<std::string> S) {
  ll ac = 0;
  ll wa = 0;
  ll tle = 0;
  ll re = 0;
  REP(i, N) {
    if (S[i] == "AC") {
      ac++;
    }
    if (S[i] == "WA") {
      wa++;
    }
    if (S[i] == "TLE") {
      tle++;
    }
    if (S[i] == "RE") {
      re++;
    }
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}

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


Measured memory_bytes: 6448
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std;

struct Node {
  int key;
  Node *right, *left, *parent;
};

Node *root, *NIL;

Node * find(Node *u, int k) {
  while ( u != NIL && k != u->key ) {
    if ( k < u->key ) u = u->left;
    else u = u->right;
  }
  return u;
}

void insert(int k) {
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z -> key = k;
  z -> left = NIL;
  z -> right = NIL;

  while ( x != NIL ) {
    y = x;
    if ( z->key < x->key ) {
      x = x->left;
    } else {
      x = x->right;
    }
  }

  z->parent = y;
  if ( y == NIL ) {
    root = z;
  } else {
    if ( z->key < y->key ) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

void inorder(Node *u) {
  if ( u == NIL ) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}

void preorder(Node *u) {
  if ( u == NIL ) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

int main() {
  int n, i, x;
  string com;

  scanf("%d", &n);

  for ( i = 0; i < n; i++ ) {
    cin >> com;
    if ( com[0] == 'f' ) {
      scanf("%d", &x);
      Node *t = find(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com == "insert" ) {
      scanf("%d", &x);
      insert(x);
    } else if ( com == "print" ) {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}


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

int main()
{
    long long N, K;
    cin >> N >> K;

    if (N > K) {
        do {
            N = N % K;
        } while (N >= K);
    }

    cout << min(N,K-N) << endl;

}

Measured memory_bytes: 256
elements = input()
vector_1 = list(map(float,input().split()))
vector_2 = list(map(float,input().split()))

for i in range(1,4):
    minkowski = sum([abs(a-b)**i for (a,b) in zip(vector_1,vector_2)])**(1/i)
    print("{0:.7f}".format(minkowski))

minkowski_inf=max([abs(a-b) for (a,b) in zip(vector_1,vector_2)])
print("{0:.7f}".format(minkowski_inf))

Measured memory_bytes: 7696
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <iomanip>

using namespace std;
long long A[100000];
const long long MOD = 1000000007;
long long power(long long m, long long n){
    long long res = 1;
    while(n > 0){
        if(n & 1) {
            res = (res * m) % MOD;
        }
        m = (m * m) % MOD;
        n >>= 1;
    }
    return res;
}

long long inverse(long long a){
    return power(a, MOD - 2);
}
int main(){
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }

    long long left_denom_sum = 0;
    long long right_denom_sum = 0;
    long long ans = 0;
    for(int i = 0; i < N; i++){
        right_denom_sum = (right_denom_sum + inverse(i + 1)) % MOD;
    }
    for(int i = 0; i < N; i++){
        ans = (ans + (((left_denom_sum + right_denom_sum) % MOD) * A[i]) % MOD) % MOD;
        left_denom_sum = (left_denom_sum + inverse(i + 2));
        right_denom_sum = ((right_denom_sum - inverse(N - i)) + MOD) % MOD;
    }
    for(int i = 0; i < N; i++){
        ans = (ans * (long long) (i + 1)) % MOD;
    }
    cout << ans << endl;
    return 0;
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            ////入力した値を数値変換する
            string str = Console.ReadLine();
            string[] strArray = new string[2];
            strArray = str.Split(' ');
            int[] intArray = Array.ConvertAll(strArray, int.Parse);


            if(intArray[0]+intArray[1]==15)
            {
                Console.WriteLine("+");
            }
            else if (intArray[0] * intArray[1] == 15)
            {
                Console.WriteLine("*");
            }
            else
            {
                Console.WriteLine("x");
            }
            
        }
    }

}

Measured memory_bytes: 27496
words = input()

lst = ['A', 'C', 'G', 'T']
max_count = 0
count = 0
for i in range(len(words)):
  if words[i] in lst:
    count += 1
    if i == len(words) - 1:
      if count > max_count:
        max_count = count
  else:
    if count > max_count:
      max_count = count
    count = 0
print(max_count)


Measured memory_bytes: 9048
import java.io.*;
public class Main
{
	public static void main(String[] args) throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int j,k,i,b,c,W,N,S;

		for(i=0;;i++){
			S=0;
		String str1 =br.readLine();
		int n=Integer.parseInt(str1);
		if(n==0)
			break;
			for(j=0;j<n/4;j++){
			String str2 =br.readLine();
			int a =Integer.parseInt(str2);
			S=S+a;
			}
			System.out.println(S);
	}
}
}

Measured memory_bytes: 24196