akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
  
	public static void main(String[] args) {
	  FastReader sc = new FastReader();
	  int n = sc.nextInt();
      Set<Character> set = new HashSet<>();
      
      for (int i = 0; i < n; i++) {
    	  char c = sc.next().charAt(0);
    	  set.add(c);
      }
      
      if (set.size() == 3) {
    	  System.out.println("Three");
      } else if (set.size() == 4) {
    	  System.out.println("Four");
      }
  }

  static class FastReader {
    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }
  
    String next() { 
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException  e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

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

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

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

    String nextLine() {
      String str = "";
        try{
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
      }
  }
}


Measured memory_bytes: 21332
#include<stdio.h>
#include<string.h>
int main()
{
	int a=0,b=0,c=0,d,i;
	char x[100];
	scanf("%s",x);
	a=strlen(x);
	b=a/2;
	for(i=0;i<b;i++){
		if(x[i]!=x[a-1-i]){
			c=1;
			break;
		}
	}
	if(c==1){
		printf("No\n");
	}
	else {
		d=0;
		for(i=0;i<b;i++){
			if(x[i]!=x[b+1+i]){
				d=1;
			}
		}
		if(d==1) printf("No\n");
		else printf("Yes\n");
	}
	return 0;
}

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

int main(void) {
	int mahouzin[15][15];
	int kazu;
	int x,y;
	int ookisa;
	while(1) {
		scanf("%d",&ookisa);
		if(ookisa==0)break;
		memset(mahouzin,0,sizeof(mahouzin));
		mahouzin[ookisa/2][ookisa/2+1]=1;
		x=ookisa/2;y=ookisa/2+1;
		for(kazu=2;kazu<=ookisa*ookisa;kazu++) {
			x++;y++;
			while(1) {
				if(x>=ookisa)x=0;
				if(x<0)x=ookisa-1;
				if(y>=ookisa)y=0;
				if(mahouzin[x][y]==0) {
					mahouzin[x][y]=kazu;
					break;
				} else {
					x--;
					y++;
				}
			}
		}
		for(y=0;y<ookisa;y++) {
			for(x=0;x<ookisa;x++) {
				printf("%4d",mahouzin[x][y]);
			}
			puts("");
		}
	}
	return 0;
}

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

using namespace std;

int a[100050][3];
int dp[100050][3];

int ghadr(int a, int b) {
	return max((a - b) , (b - a));
}

int main() {
	long long int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i][0] >> a[i][1] >> a[i][2];
	}
	dp[0][0] = a[0][0];
	dp[0][1] = a[0][1];
	dp[0][2] = a[0][2];
	for (int i = 1; i < n; i++) {
		dp[i][0] = max (dp[i - 1][1] , dp[i - 1][2]) + a[i][0];
		dp[i][2] = max (dp[i - 1][1] , dp[i - 1][0]) + a[i][2];
		dp[i][1] = max (dp[i - 1][0] , dp[i - 1][2]) + a[i][1];
	}
	cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));
	return 0;
}


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    string s; cin >> s;
    int n = s.size();
    int res = 0;
    rep(i, n){
        rep(j, n){
            if(i+j >= n) continue;
            bool flg = true;
            Rep1(k, i, i+j){
                if((s[k] != 'A') && (s[k] != 'C') && (s[k] != 'G') && (s[k] != 'T')) flg = false;
            }
            if(flg) res = max(res, j+1);
        }
    }

    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


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

using namespace std;
using ll = long long;


int main()
{
	int n; cin >> n;
	vector<pair<int,int>> a(n);
	for(int i = 0; i < n; i++)cin >> a[i].first >> a[i].second;
	int cnt = 0;
	for(int i = 0; i < n; i++) {
		if(a[i].first != a[i].second)cnt = 0;
		else cnt++;
		if(cnt >= 3) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	long long a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max({a*c, a*d, b*c, b*d});
}

Measured memory_bytes: 3648
N = str(input())
n,mods = 0,[1]+[0]*2018
d = 1
for i in reversed(N):
  n = (n+int(i)*d)%2019
  mods[n] += 1
  d = (d*10)%2019

print(sum([i*(i-1)//2 for i in mods]))

Measured memory_bytes: 9284
#include <bits/stdc++.h>
#define Nmax 100002
using namespace std;

long long n,mn,mx,lst,x,v[Nmax];

int main()
{
    mn = mx = 2;
    cin>>n;
    for (int i=1;i<=n;i++)
    {
        cin>>v[i];
    }
    for (int i=n;i>0;i--)
        if (v[i]>2)
        {
            cout<<-1<<'\n';
            return 0;
        }
        else if (v[i]==2)
        {
            break;
        }
    for (int i=n;i>0;i--)
    {
        if (v[i]==1)
            continue;
        if (((mx/v[i]+1)*v[i]-1)/v[i]*v[i]<mn)
        {
            cout<<-1<<'\n';
            return 0;
        }
        mn = (mn/v[i]+(mn%v[i]!=0))*v[i];
        mx = (mx/v[i]+1)*v[i]-1;
    }

    cout<<mn<<' '<<mx<<'\n';

    return 0;
}
/*
4
5 4 3 2
6
1 9 5 3 2 1
1
3
*/


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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    int n,m;cin>>n>>m;

    vector<VPII> e(n);
    REP(i,m){
        int l,r,d;cin>>l>>r>>d;
        l--;
        r--;
        e[l].PB(MP(r,d));
        e[r].PB(MP(l,-d));
    }

    VL p(n);

    REP(i,n){
        if(p[i]!=0){
            continue;
        }
        p[i] = INF;
        queue<LL> q;
        q.push(i);
        while(!q.empty()){
            auto now = q.front();
            q.pop();

            for(auto x : e[now]){
                int next = x.first;
                int dist = x.second;
                if(p[next]!=0 && p[next]!=p[now]+dist){
                    cout<<"No"<<endl;
                    return;
                }
                if(p[next]==0){
                    q.push(next);
                    p[next]=p[now]+dist;
                }
            }
        }
    }
    cout<<"Yes"<<endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

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

int main()
{
    string s;
    cin >> s;
    bool ans = true;
    if(s[2]!=s[3]) ans=false;
    if(s[4]!=s[5]) ans=false;
    cout << (ans ? "Yes": "No") << endl;

    return 0 ;
}


Measured memory_bytes: 256
D=int(input())
*c,=map(int,input().split())
s=[]
for i in range(D):
    *x,=map(int,input().split())
    s.append(x)

dt=[]
last=[-1]*26
v=0
for d in range(D):
    news=[s[d][i]+c[i]*(d-last[i])*(d-last[i]-1)//2 for i in range(26)]
    maxi=0
    tmp=-float('inf')
    for i in range(26):
        if tmp<news[i]:
            maxi=i
            tmp=news[i]
    last[maxi]=d
    v+=s[d][maxi]
    for i in range(26):
        v-=c[i]*(d-last[i])
    dt.append(maxi+1)

def score(T):
    last=[-1]*26
    v=0
    for d in range(D):
        v+=s[d][T[d]-1]
        last[T[d]-1]=d
        for i in range(26):
            v-=c[i]*(d-last[i])
    return v

v0=max(score(dt)+10**6,0)

for _ in range(3):
    for d in range(1,D):
        y=-1
        newdt=dt+[]
        for i in range(26):
            if dt[d]!=i+1:
                newdt[d]=i+1
                v1=max(score(newdt)+10**6,0)
                if v0<v1:
                    y=i+1
                    v0=v1
        if y!=-1:
            dt[d]=y

for i in dt:
    print(i)

Measured memory_bytes: 75396
n, d = gets.split.map(&:to_i)
x = n.times.map { gets.split.map(&:to_i) }

c = 0
0.upto(n-2) do |i|
  (i+1).upto(n-1) do |j|
    v = d.times.map { |k| (x[i][k] - x[j][k]) ** 2 }.reduce(&:+)
    f = Math.sqrt(v)
    c += 1 if f == f.to_i
  end
end

puts c

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;
struct edge {int to,costa,costb;};

signed main() {
int n;
cin>>n;
int t[n+1],t0;t[0]=0;
for(int i=0;i<n;i++){
    cin>>t0;
    t[i+1]=t[i]+2*t0;
}
int ans[t[n]+1];
for(int i=0;i<=t[n];i++)ans[i]=min(i,t[n]-i);
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> que;int v;
for(int i=0;i<n;i++){
    cin>>v;
    que.push(make_pair(2*v,i));
}
pair<int,int>q;
while(!que.empty()){
    q=que.top();que.pop();
    for(int i=t[q.second];i<=t[q.second+1];i++)ans[i]=min(ans[i],q.first);
    for(int i=t[q.second]-1;i>=0&&ans[i]>ans[i+1]+1;i--)ans[i]=ans[i+1]+1;
    for(int i=t[q.second+1]+1;i<=t[n]&&ans[i]>ans[i-1]+1;i++)ans[i]=ans[i-1]+1;
}
float ans2=0;for(int i=0;i<=t[n];i++)ans2+=ans[i];
cout << std::setprecision(20)<<ans2/4;


return 0;


}


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n,a,b,c,d;
    cin >> n >> a >> b >> c >> d;
    
    string S;
    cin >> S;
    
    a--, b--, c--, d--;
    
    bool bad = false;
    
    for(int i = a; i < max(c,d); i++){
        if(S[i] == '#' && S[i+1] == '#') bad = true;
    }
    
    bool good = true;
    if(c > d){
        good = false;
        for(int i = b; i <= d; i++){
            if(S[i] == '.' && S[i+1] == '.' && S[i-1] == '.'){
                good = true;
            }
        }
    }
    
    if(bad || !good) cout << "No" << endl;
    else cout << "Yes" << endl;
}

 


Measured memory_bytes: 592
k = int(input())

mod_set = set()
num = 7
cnt = 1

while True:
    if num % k == 0:
        print(cnt)
        exit()
    else:
        if num % k in mod_set:
            print('-1')
            exit()
        else:
            mod_set.add(num % k)
    num = (num * 10 + 7) % k
    cnt += 1


Measured memory_bytes: 77948
#include <iostream>
#include <cstring>
#include <algorithm>
#include <string>
using namespace std;
string ss[4]={"dreamer","eraser","dream","erase"};
int main(){
    string str;
    while(cin>>str){
        int i;
        for(i=str.length()-1;i>=0;){
            bool have=0;
            for(int k=0;k<4;k++){
                if(i-ss[k].length()+1>=0&&i-ss[k].length()+1<str.length()&&str.substr(i-ss[k].length()+1,ss[k].length())==ss[k]){
                    i-=ss[k].length();
                    have=1;
                    break;
                }
            }
            if(have==0){
                    break;
            }
        }
        if(i<0)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
typedef long long ll;
typedef long double ld;
using namespace std;



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

  int n;
  cin >> n;
  vector<pair<int, int>> vc(n);
  for (auto& p : vc) cin >> p.f;
  for (auto& p : vc) cin >> p.s;
  int ans = 0;
  for (auto& p : vc) {
    if (p.f - p.s > 0) {
      ans += p.f - p.s;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
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; }
 
int main(){
    int N; cin >> N;
    int ans=0;
    
    for (int i=1; i<=N; i++) ans+=i;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX 500000
#define SEN 2000000000
int L[MAX/2+2],R[MAX/2+2];
int cnt;
void merge(int a[],int n,int left,int mid,int right){
	int n1=mid-left;
	int n2=right-mid;
	for(int i=0;i<n1;i++) L[i]=a[left+i];
	for(int i=0;i<n2;i++) R[i]=a[mid+i];
	L[n1]=R[n2]=SEN;
	int i=0,j=0;
	for(int k=left;k<right;k++){
		cnt++;
		if(L[i]<=R[j]){
			a[k]=L[i++];
		}else{
			a[k]=R[j++];
		}
	}
}
void mergesort(int a[],int n,int left,int right){
	if(left+1<right){
		int mid=(right+left)/2;
		mergesort(a,n,left,mid);
		mergesort(a,n,mid,right);
		merge(a,n,left,mid,right);
	}
}
int main(){
	int a[MAX],n,i;
	cnt=0;
	cin>>n;
	for(i=0;i<n;i++) cin>>a[i];
	mergesort(a,n,0,n);
	for(i=0;i<n;i++){
		if(i)cout<<" ";
		cout<<a[i];
	}
	cout<<endl;
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 6952
import java.util.*;

public class Main {
	public static void main(String[] args) {
      Scanner sc =new Scanner(System.in);
      int N = sc.nextInt();
      int M = sc.nextInt();
      int X = sc.nextInt();
      int Y = sc.nextInt();
      X += 100; Y+= 100;
      int[] count1 = new int[201];
      int[] count2 = new int[201];
      int[] x = new int[N];
      int[] y = new int[M];
      int ans =0;
      for (int i=0; i<N; i++) {
        x[i] = sc.nextInt() + 100;
      }
      for (int i=0; i<M; i++) {
        y[i] = sc.nextInt() + 100;
      }
      for (int i=0; i<=200; i++) {
        for (int j=0; j<N; j++) {
          if (x[j] > i && X > i) count1[i]++;
        }
        for (int j=0; j<M; j++) {
          if (y[j] <= i && Y<= i) count1[i]++;
        }
      }
      for (int i=0; i<=200; i++) {
        for (int j=0; j<N; j++) {
          if (x[j] <= i && X <= i) count2[i]++;
        }
        for (int j=0; j<M; j++) {
          if (y[j] > i && Y > i) count2[i]++;
        }
      }
      for (int i=0; i<=200; i++) {
        if (count1[i] == N+M || count2[i] == N+M) {
          ans++;
        }
      }
      if (ans != 0) {
        System.out.print("No War");
      } else {
        System.out.print("War");
      } 
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#define INF (long)1e9
const int MOD = 1e9 + 7;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
using namespace std;
typedef long long ll;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	long long A[100];
	A[0] = 2;
	A[1] = 1;
	for(int i = 2; i <= n; i++)
	{
		A[i] = A[i - 2] + A[i - 1];
	}
	cout << A[n] << endl;
	return 0;
}



Measured memory_bytes: 256
/* factorial */
#include <stdio.h>

unsigned factorial(int n)
{
 int i;
 unsigned long tmp=1;
 if(n!=0){
 for(i=n; i>0; i--)
 tmp *= i;
 }
 else{
 tmp = 1;
 }
return tmp;
}
 
int main()
{
 unsigned long a;
 scanf("%lu",&a);
 printf("%lu\n",factorial(a));
return 0;
}

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

int main(void)
{
    int m, f, r;

    while (cin >> m >> f >> r && !(m == -1 && f == -1 && r == -1)) {
        int mf(m + f);
        if (m == -1 || f == -1)
            cout << "F";
        else if (mf >= 80)
            cout << "A";
        else if (mf >= 65)
            cout << "B";
        else if (mf >= 50)
            cout << "C";
        else if (mf >= 30)
            if (r >= 50)
                cout << "C";
            else
                cout << "D";
        else
            cout << "F";
        cout << endl;
    }

    return 0;
}



Measured memory_bytes: 3044
a, b, c = [int(i) for i in input().split()]
if a < b:
    if b < c:
        print(a, b, c)
    elif c < a:
        print(c, a, b)
    else:
        print(a, c, b)
else:
    if a < c:
        print(b, a, c)
    elif c < b:
        print(c, b, a)
    else:
        print(b, c, a)

Measured memory_bytes: 7676
/* Dynamic Programming implementation of LCS problem */
#include<iostream> 
#include<cstring> 
#include<cstdlib> 
using namespace std; 

/* Returns length of LCS for X[0..m-1], Y[0..n-1] */
void lcs( string X,string Y, int m, int n ) 
{ 
int L[m+1][n+1]; 

/* Following steps build L[m+1][n+1] in bottom up fashion. Note 
	that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */
for (int i=0; i<=m; i++) 
{ 
	for (int j=0; j<=n; j++) 
	{ 
	if (i == 0 || j == 0) 
		L[i][j] = 0; 
	else if (X[i-1] == Y[j-1]) 
		L[i][j] = L[i-1][j-1] + 1; 
	else
		L[i][j] = max(L[i-1][j], L[i][j-1]); 
	} 
} 

// Following code is used to print LCS 
int index = L[m][n]; 

// Create a character array to store the lcs string 
char lcs[index+1]; 
lcs[index] = '\0'; // Set the terminating character 

// Start from the right-most-bottom-most corner and 
// one by one store characters in lcs[] 
int i = m, j = n; 
while (i > 0 && j > 0) 
{ 
	// If current character in X[] and Y are same, then 
	// current character is part of LCS 
	if (X[i-1] == Y[j-1]) 
	{ 
		lcs[index-1] = X[i-1]; // Put current character in result 
		i--; j--; index--;	 // reduce values of i, j and index 
	} 

	// If not same, then find the larger of two and 
	// go in the direction of larger value 
	else if (L[i-1][j] > L[i][j-1]) 
		i--; 
	else
		j--; 
} 

// Print the lcs 
cout << lcs; 
} 

/* Driver program to test above function */
int main() 
{ 
string X,Y;
cin>>X>>Y;
int m =X.length(); 
int n =Y.length(); 
lcs(X, Y, m, n); 
return 0; 
} 


Measured memory_bytes: 35456
n, m = list(map(int, input().split()))
roads = [list(map(int, input().split())) for i in range(m)]
roads_in_city = [0] * n
for road in roads:
    roads_in_city[road[0] - 1] += 1
    roads_in_city[road[1] - 1] += 1
for r in roads_in_city:
    print(r)

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
	private	static	BufferedReader	br = null;

	static {
		br  = new BufferedReader(new InputStreamReader(System.in));
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String	strNum = null;

		while ((strNum = parseStdin()) != null) {
			calc(strNum);
		}
	}

	private static void calc(String strNum) {
		int		nNum    = 0;
		int		nLen    = strNum.length();
		String	strWork = null;

		for (int n = 0; n < nLen;) {
			strWork = strNum.substring(n, nLen);
			if (strWork.startsWith("IV")) {
				nNum += 4;
				n    += 2;
			}
			else if (strWork.startsWith("IX")) {
				nNum += 9;
				n    += 2;
			}
			else if (strWork.startsWith("XL")) {
				nNum += 40;
				n    += 2;
			}
			else if (strWork.startsWith("XC")) {
				nNum += 90;
				n    += 2;
			}
			else if (strWork.startsWith("CD")) {
				nNum += 400;
				n    += 2;
			}
			else if (strWork.startsWith("CM")) {
				nNum += 900;
				n    += 2;
			}
			else if (strWork.startsWith("I")) {
				nNum += 1;
				n    += 1;
			}
			else if (strWork.startsWith("V")) {
				nNum += 5;
				n    += 1;
			}
			else if (strWork.startsWith("X")) {
				nNum += 10;
				n    += 1;
			}
			else if (strWork.startsWith("L")) {
				nNum += 50;
				n    += 1;
			}
			else if (strWork.startsWith("C")) {
				nNum += 100;
				n    += 1;
			}
			else if (strWork.startsWith("D")) {
				nNum += 500;
				n    += 1;
			}
			else if (strWork.startsWith("M")) {
				nNum += 1000;
				n    += 1;
			}
		}

		System.out.println(nNum);
	}

	private static String parseStdin() {
		String	strNum = null;

		try {
			String line = br.readLine();
			if (line != null) {
				if (!line.isEmpty()) {
					strNum = line;
				}
			}
		}
		catch (IOException e) {}

		return strNum;
	}
}

Measured memory_bytes: 16880
#include<stdio.h>
#define MAX 100001
#define NMAX 10001


void Union(int A[],int x,int y,int i,int n){
int tempX,tempY,j;

if(A[x]!=-1&&A[y]!=-1){
 tempX=A[x];
 tempY=A[y];
 for(j=0;j<n;j++){if(A[j]==tempX||A[j]==tempY)A[j]=i;}
}
else if(A[x]==-1&&A[y]==-1){
 A[x]=i;
 A[y]=i;
}
else{
 if(A[x]==-1){A[x]=A[y];}
 else{A[y]=A[x];}
}

return;
}



int same(int A[],int x,int y){
if(A[x]==A[y]&&A[x]!=-1&&A[y]!=-1){return 1;}
else{return 0;}
}


int main(){
int n,q;
int i,com,x,y;
int temp;
int C[MAX];
int A[NMAX];


scanf("%d %d",&n,&q);/*n,qの読み込み*/

for(i=0;i<n;i++){A[i]=-1;}/*Aの初期化*/
for(i=0;i<q;i++){C[i]=-1;}


for(i=0;i<q;i++){
 scanf("%d %d %d",&com,&x,&y);
 switch(com){
  case 0:Union(A,x,y,i,n);
         break;
  case 1:C[i]=same(A,x,y);
         break;
 }
}



for(i=0;i<q;i++){/*表示*/
 if(C[i]==0||C[i]==1){printf("%d\n",C[i]);}
}

return 0;
}


Measured memory_bytes: 2196
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair

using namespace std;
const int N=505, M=1200;
int n, col[N][N], vcnt, lft[M], rt[M];
vector<int> V[M];
void solve(int idx, int c)
{
	int l = V[idx].size();
	if(l==1) return;
	for(int i = 0; i < l-1; i++)
	{
		col[V[idx][i]][V[idx][i+1]]=c;
		for(int j = i+3; j < l; j+=2)
		{
			col[V[idx][i]][V[idx][j]]=c;
		}
	}
	if(l<=2) return;
	vcnt++;
	lft[idx]=vcnt;
	vcnt++;
	rt[idx]=vcnt;
	for(int i = 0; i < l; i+=2)
	{
		V[lft[idx]].pb(V[idx][i]);
	}
	for(int i = 1; i < l; i+=2)
	{
		V[rt[idx]].pb(V[idx][i]);
	}
	solve(lft[idx], c+1);
	solve(rt[idx], c+1);
}
signed main() 
{
	cin >> n;	
	for(int i = 1; i <= n; i++)
	{
		V[0].pb(i);
	}
	solve(0, 1);
	for(int i = 1; i < n; i++)
	{
		for(int j = i+1; j <= n; j++)
		{
			cout << col[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 2560
s = input()
s = s[::-1]
while len(s) > 0:
  if s[:5] == 'maerd':
    s = s[5:]
  elif s[:7] == 'remaerd':
    s = s[7:]
  elif s[:5] == 'esare':
    s = s[5:]
  elif s[:6] == 'resare':
    s = s[6:]
  else:
    print('NO')
    exit()
print('YES')

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

int main() {
  int a, b, c; cin >> a >> b >> c;
  for (int i = a; i <= a * b; i += a) {
    if (i % b == c) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K;
double X[100],Y[100],C[100];

double mi=1e9;

int go(double x,double y,double T) {
	int count=0;
	int i;
	
	
	FOR(i,N) if(hypot(x-X[i],y-Y[i])*C[i]<=T+(1e-9)) count++;
	return count;
}

double ok(double T) {
	int i,j;
	FOR(i,N) if(go(X[i],Y[i],T)>=K) return 1;
	
	FOR(j,N) FOR(i,j) {
		double r1=T/C[i];
		double r2=T/C[j];
		double d=hypot(X[i]-X[j],Y[i]-Y[j]);
		if(r1+r2<d) continue;
		if(r1+d<r2) continue;
		if(d+r2<r1) continue;
		double s=(r1+r2+d)/2;
		double a=sqrt(s*(s-r1)*(s-r2)*(s-d));
		double h=a/d*2;
		double d2=sqrt(r1*r1-h*h);
		double dx1=(X[j]-X[i])/d;
		double dy1=(Y[j]-Y[i])/d;
		double dx2=dy1;
		double dy2=-dx1;
		for(int cx=-1;cx<=1;cx+=2) {
			for(int cy=-1;cy<=1;cy+=2) {
				double tx=X[i]+cx*d2*dx1+cy*h*dx2;
				double ty=Y[i]+cx*d2*dy1+cy*h*dy2;
				if(go(tx,ty,T)>=K) return 1;
			}
		}
		
		
	}
	return 0;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	FOR(i,N) cin>>X[i]>>Y[i]>>C[i];
	
	double L=0,R=1e9;
	FOR(i,100) {
		double M=(L+R)/2;
		if(ok(M)) R=M;
		else L=M;
	}
	
	_P("%.12lf\n",L);
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include <iostream>

int n;
int cmb;
int dp[30];

int func(int now){
  if(now > n)
    return 0;
  if(now == n){
    dp[now] = 1;
    return 1;
  }


  return func(now+1) + func(now+2) + func(now+3);
}

int main(void){
  while(1){
    int ans;
    std::cin >> n;

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

    if(n == 0){
      return 0;
    }

    cmb = 0;
    ans = func(0);

    std::cout << ans / 10 / 365 + 1 << std::endl;
  }
}

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

using namespace std;

#define fore(i, s, e) for(int i = s; i < e; i++)
#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define fst first
#define snd second

typedef long long ll;

int main() {
    int n; cin >> n;
    string s; cin >> s;
    int i = 0;
    while(i < n && s[i] == '.') i++;
    int j = n;
    while(j > 0 && s[j - 1] == '#') j--;
    int a = 0, b = 0, ac = 0, bc = 0;
    int ii = i; 
    while(i < j) {
        a += s[i] == '.';
        b += s[i] == '#';
        i++;
    }
    int res = 1e9;
    i = ii;
    while(i < j) {
        if(s[i] == '#') {
            res = min(res, bc + a - ac);
        }
        ac += s[i] == '.';
        bc += s[i] == '#';
        i++;
    }
    cout << min({res, a , b}) << endl;
    return 0;
}

Measured memory_bytes: 640
#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>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;

int dp[3002];
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  int mod=1e9+7;
  string s;
  cin>>n>>s;
  dp[1]=1;
  rep(i,n-1)
  {
    if(s[i]=='<')
    {
      repi(j,1,i+1)
      {
        dp[j+1]+=dp[j];
        dp[j+1]%=mod;
      }
      for(int j=n;j>=1;j--)
      {
        dp[j]=dp[j-1];
      }
    }
    else
    {
      for(int j=i+1;j>1;j--)
      {
        dp[j-1]+=dp[j];
        dp[j-1]%=mod;
      }
    }
  }
  ll res=0;
  repi(i,1,n+1)res+=dp[i];
  cout<<res%mod<<endl;

  return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <string>

template <typename T> struct Node {
  Node *next, *prev;
  T value;

  Node() : value(0) {}
  Node(T v) : value(v) {}
};

template <typename T> struct LinkedList {
  int length;
  Node<T> *head, *tail, *current;

  LinkedList() : length(0) {
    head = new Node<T>;
    tail = new Node<T>;
    head->next = tail;
    tail->prev = head;
    current = head;
  };

  void insert(T value) {
    Node<T> *n = new Node<T>(value);
    n->next = head->next;
    head->next->prev = n;
    head->next = n;
    n->prev = head;
  }

  Node<T> *search(T value) {
    Node<T> *n = head->next;
    while (n != tail) {
      if (n->value == value)
        return n;
      n = n->next;
    }
    return n;
  };

  void delNode(Node<T> *n) {
    n->next->prev = n->prev;
    n->prev->next = n->next;
    delete n;
  };

  void delValue(T value) {
    Node<T> *n = search(value);
    if (n == tail)
      return;
    delNode(n);
  };

  void delFirst() { delNode(head->next); };

  void delLast() { delNode(tail->prev); };

  void print() {
    Node<T> *n = head->next;
    while (n != tail) {
      std::cout << n->value;
      n = n->next;
      if (n == tail) {
        std::cout << std::endl;
      } else {
        std::cout << " ";
      }
    }
  }
};

int main() {
  LinkedList<int> list;
  int n;
  std::cin >> n;

  std::map<std::string, int> cmdmap;
  cmdmap.insert(std::make_pair("insert", 0));
  cmdmap.insert(std::make_pair("delete", 1));
  cmdmap.insert(std::make_pair("deleteFirst", 2));
  cmdmap.insert(std::make_pair("deleteLast", 3));

  std::string cmd;
  int key;
  for (int i = 0; i < n; i++) {
    std::cin >> cmd;
    switch (cmdmap.at(cmd)) {
    case 0:
      std::cin>>key;
      list.insert(key);
      break;
    case 1:
      std::cin>>key;
      list.delValue(key);
      break;
    case 2:
      list.delFirst();
      break;
    case 3:
      list.delLast();
      break;
    }
  }
  list.print();
}



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

int main()
{
	char  a[30];
	char  b[30]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
	scanf("%s",a);
	int len=strlen(a);
	int i,j,flag=0;
	if(len!=26)
	{
		for(i=0;i<len;i++)
		{
			for(j=0;j<26;j++)
				if(b[j]==a[i])
				{
					b[j]=0;
					break;
				}
		}
		for(i=0;i<26;i++)
		{
			if(b[i]!=0)
				break;
		}
		a[len]=b[i];
		a[len+1]='\0';
	}
	else
	{
		for(i=len-2;i>=0;i--)
		{
			for(j=i+1;j<len;j++)
			{

				if(a[i]<a[j] && i==24)
				{
					a[i]=a[j];
					a[j]='\0';
					flag=1;
					break;
				}
				else if(a[i]<a[j] && i!=24)
				{
					char k=a[j];
					for(j=j+1;j<len;j++)        //取最小字符 
						if(k>a[j] && a[j]>a[i])
							k=a[j];
					a[i]=k;
					a[i+1]='\0';
					flag=1;
					break;
				}
			}
			if(flag)
					break;
			if(i==0)
			{
				a[0]='-';
				a[1]='1';
				a[2]='\0';
			}
		}
	}
	printf("%s\n",a);
	
	return 0;
} 

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

int main() {
	int R[200000], n;

	cin >> n;
	for (int i = 0; i < n; i++) cin >> R[i];

	int maxv = -1000000000;
	int minv =  R[0];

	for (int j = 1; j < n; j++) {
		if (maxv < R[j] - minv) {
			maxv = R[j] - minv;
		}
		if (minv > R[j]) {
			minv = R[j];
		}
	}
	cout << maxv << endl;
	return 0;
}

Measured memory_bytes: 3864
/// 11:57 AM 04/04/20
/// Author: t_bone_289 (An Immature Programmer.... I'm still developing !!)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
#define error(x) cout << #x << " = " << x << endl;
#define pi 3.14159265358979323846
typedef long long ll;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

template<typename T>
void ContainerError(T &v);

ll powmod(ll base, ll exp, ll MOD);

ll mpow(ll base, ll exp);

ll gcd(ll a, ll b);

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll n,k;
    cin>>n>>k;
    ll ans;
    ll z = n/k;
    n = n - (k*z);
    ans = min(n,k-n);
    cout<<ans;
    return 0;
}

template<typename T>
void ContainerError(T &v) {
    cout << "{";
    for (auto &x:v) { cout << x << ','; }
    cout << "}" << endl;
    return;
}

ll powmod(ll base, ll exp, ll MOD) {
    ll res = 1;
    while (exp > 0) {
        if (exp % 2 == 1) res = (res * base) % MOD;
        base = (base * base) % MOD;
        exp /= 2;
    }
    return (res % MOD);
}

ll mpow(ll base, ll exp) {
    ll res = 1;
    while (exp > 0) {
        if (exp % 2 == 1) res = (res * base);
        base = (base * base);
        exp /= 2;
    }
    return (res);
}

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }



Measured memory_bytes: 256
#include<stdio.h>
int main(void){
int x,y,i;
for(i=0;i<3000;i++){
scanf("%d %d",&x,&y);
if(0<=x&&x<=10000&&0<=y&&y<=10000){
if(x==0&&y==0)
return 0;
else{
if(x>y)
printf("%d %d\n",y,x);
else
printf("%d %d\n",x,y);
}
}
}
return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define ll long long
#define met(a) memset(a,0,sizeof(a))
#define inf 0x3f3f3f3f
using namespace std;
const int mod=1e9+7;
struct node{ll b,c,d;
} a[200010];
ll dir[100010],ans[100010];
void dfs(ll x,ll y,ll z)
{
    ll i,j;
    ll cnt;
    ans[x]=z;
    for(i=dir[x];i!=-1;i=a[i].d)
    {
        cnt=a[i].b;
        if(cnt==y)
            continue;
        dfs(cnt,x,z+a[i].c);
    }
    return;
}
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ll i,j,k,m,n,q;
    ll x,y,z,sum=0;
    cin>>n;
    for(i=1;i<100005;i++)
        dir[i]=-1;
    for(i=1; i<=n-1; i++)
    {
        cin>>x>>y>>z;
        a[sum].b=y,a[sum].c=z,a[sum].d=dir[x];
        dir[x]=sum;
        sum++;
        a[sum].b=x,a[sum].c=z,a[sum].d=dir[y];
        dir[y]=sum;
        sum++;
    }
    cin>>q>>k;
    dfs(k,-1,0);
    while(q--)
    {
        cin>>x>>y;
        cout<<ans[x]+ans[y]<<endl;
    }
    return 0;
}


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

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	ll N,M,Q;
    cin>>N>>M>>Q;
    vector<ll> a(Q),b(Q),c(Q),d(Q);

    rep(i,Q){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        --a[i];
        --b[i];
    }

    vector<ll> A(N,1);
    ll ind = 0;
    ll m_ind = 0;
    ll tmp_ans;
    ll ans = 0;
    while(true){
        ll tmp_ans = 0;
        rep(i,Q){
            if(A[b[i]]-A[a[i]]==c[i]){
                tmp_ans += d[i];
            }
        }
        ans = max(ans,tmp_ans);
        // rep(i,N){
        //     cout<<A[i]<<" ";
        // }
        // cout<<tmp_ans;
        // cout<<"\n";

        if(A[N-1-ind] < M){
            ++A[N-1-ind];
        }else{
            while(A[N-1-ind]==M){
                ++ind;
                if(ind==N){
                    goto fin; 
                }
            }
            ++A[N-1-ind];
            rep(i,ind){
                A[N-1-i] = A[N-1-ind];
            }
            ind = 0;
        }
    }

    fin:

    cout<<ans<<"\n";	
	return 0;
}


Measured memory_bytes: 3648
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE RankNTypes #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.Bits
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
import Control.Monad.ST
-- import Debug.Trace
-- trace _ = id

solve :: Int -> [[Int]] -> Int
solve bN ass = ans
  where
  aV = V.fromListN bN (map f ass)
    where f as = [m | (m,a) <- zip [0..bN-1] as, a == 1]

  ans = runST $ do
    vec <- VUM.replicate (2^bN) 0
    VUM.write vec 0 1
    forM_ [0..2^bN-2] $ \is -> do
      cur <- VUM.read vec is
      when (cur > 0) $ do
        let k = popCount is
        forM_ (aV V.! k) $ \m -> do
          unless (testBit is m) $ do
            VUM.modify vec (mAdd cur) (setBit is m)
    VUM.read vec (2^bN-1)

-------------------------------------------------------------------------------

prime :: Int
prime = 10 ^ 9 + 7

mAdd x y | w < prime = w
         | otherwise = w - prime
  where w = x + y

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> Int
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_bN]:remLines1 = remLines0
      bN = readBInt bs_bN
      ass = map (map readBInt) remLines1
  in solve bN ass

outAnswer :: Int -> IO ()
outAnswer = putStrLn . show

main :: IO ()
main = outAnswer . tmain =<< B.getContents


Measured memory_bytes: 18428
package main

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

func lib_MaxInt64(values ...int64) (max int64, err error) {
	if len(values) == 0 {
		return 0, errors.New("empty slice is given")
	}
	max = values[0]
	for _, value := range values {
		if max < value {
			max = value
		}
	}
	return
}
func lib_MustMaxInt64(values ...int64) (max int64) {
	max, err := lib_MaxInt64(values...)
	if err != nil {
		panic(err)
	}
	return max
}
func lib_New2DimInt64Slice(row, col int) [][]int64 {
	ret := make([][]int64, row)
	for r := 0; r < row; r++ {
		ret[r] = make([]int64, col, col)
	}
	return ret
}
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	const initialBufSize = 4096
	const maxBufSize = 1000000
	scanner.Buffer(make([]byte, initialBufSize), maxBufSize)
	scanner.Split(bufio.ScanWords)
	var N int64
	scanner.Scan()
	N, _ = strconv.ParseInt(scanner.Text(), 10, 64)
	var W int64
	scanner.Scan()
	W, _ = strconv.ParseInt(scanner.Text(), 10, 64)
	w := make([]int64, N)
	v := make([]int64, N)
	for i := int64(0); i < N; i++ {
		scanner.Scan()
		w[i], _ = strconv.ParseInt(scanner.Text(), 10, 64)
		scanner.Scan()
		v[i], _ = strconv.ParseInt(scanner.Text(), 10, 64)
	}
	fmt.Println(solve(N, W, w, v))
}
func solve(N int64, W int64, w []int64, v []int64) int64 {
	dp := lib_New2DimInt64Slice(int(N)+1, int(W+1))
	for i := 0; i < int(N); i++ {
		for j := int64(0); j <= W; j++ {
			newW := j + w[i]
			if newW <= W {
				dp[i+1][newW] = lib_MustMaxInt64(dp[i+1][newW], dp[i][j]+v[i])
			}
			dp[i+1][j] = lib_MustMaxInt64(dp[i+1][j], dp[i][j])
		}
	}
	return lib_MustMaxInt64(dp[N]...)
}


Measured memory_bytes: 81792
N = gets.strip.to_i
as = gets.strip.split.map(&:to_i)
bs = as.map(&:abs).sort

if as.include?(0) || as.select{|i| i < 0}.length % 2 == 0
  puts bs.inject(&:+)
else
  cs = bs.select{|i| i > 0 }
  puts cs[1..-1].inject(&:+) - cs[0]
end


Measured memory_bytes: 12784
#include <iostream>
#include <iomanip>
#include <ios>
#include <string>
using namespace std;
int main(void){
  string s;
  cin >> s;
  
  if(s.length() >= 4 && s.substr(0,4) == "YAKI")
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#![allow(non_snake_case, unused_macros, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,BTreeMap};

// Main
fn main(){
    input!{
        n: usize,
        s: chars,
    }
    let mut ans = 0;
    let mut tmp = 0;
    for i in 0..n{
        if s[i]=='I'{
            tmp += 1;
        }else{
            tmp -= 1;
        }
        ans = max(ans,tmp);
    }
    println!("{}", ans);
}




Measured memory_bytes: 4352
a,b,c,x,y = map(int,input().split())
ans=a*x+b*y
if x>y:
    e = c*2*y
    f = a*(x-y)
    ans=min(ans,e+f)
    g= 2*c*x
    ans=min(ans,g)
else:
    e = c*2*x
    f = b*(y-x)
    ans = min(ans,e+f)
    g = 2*c*y
    ans = min(ans,g)

print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
typedef struct Node * node;
struct Node{
   int val;
   node left;
   node right; // pointer
   node parent;
};
node insert(node T, int z){
    node y = NULL;
    node temp = T;
    while(temp!=NULL){
        y = temp;
        if(z<temp->val){
            temp = temp->left;
        } else {
            temp = temp->right;
        }
    }
    node insert = (node)malloc(sizeof(node));
    insert->val = z;
    if(y==NULL){ //empty tree{
        T = insert;
    }
    else if(z<(y->val)){
        y->left = insert;
    } else {
        y->right = insert;
    }
    return T;
}
void inorder(node root){
    if(root == NULL) return;
    inorder(root->left);
    printf(" %d",root->val);
    inorder(root->right);
}

void preorder(node root){
    if(root == NULL) return;
    printf(" %d",root->val);
    preorder(root->left);
    preorder(root->right);
}
void print(node root){
    inorder(root);
    printf("\n");
    preorder(root);
    printf("\n");
}
int res = 0;
void find_util(int val, node cur){
    if(cur == NULL) return;
    if(val==cur->val) res = 1; // find
    if(val<cur->val) {
        find_util(val, cur->left);
    } else {
        find_util(val,cur->right);
    }
}
void find(node root , int val){
    find_util(val, root);
    if(res == 0) printf("no\n");
    else if(res == 1) printf("yes\n");
}
int main()
{
    int n;
    scanf("%d",&n);
    node root = NULL;
    for(int i = 0; i<n; i++){
        char str[10];
        int val;
        scanf("%s %d",&str, &val);
        if(str[0] == 'i'){//insert
            root = insert(root,val);
        } else if(str[0] == 'f') {
            res = 0;
            find(root, val);
        } else{ // print
            print(root);
        }
    }
    return 0;
}


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

#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

using namespace std;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	ll ans=0;
	cin>>n;
	vi vs(n);
	for(int &x:vs) cin >> x;
	sort(all(vs));
	for(int i=0;i<n;++i){
		for(int j=i+1;j<n;++j){
			int aux = vs[i]+vs[j];
			auto it = lower_bound(all(vs),aux) - vs.begin();
			//cout<<it<<" "<<i<<" "<<j<<endl;
			ans+=(it-j-1);
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

template<typename T>
void fin(std::vector<T>const& t, char delim=' '){
  if(t.size() > 0) {
    for(int i = 0; i < t.size() -1; ++i) std::cout << t[i] << delim;
    std::cout << t.back();
  }
  std::cout << std::endl;
  exit(0);
}

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int N, sum = 0; std::cin >> N;
  std::vector<int> a(N);
  for(auto& ai: a) { std::cin >> ai; sum ^= ai; }
  for(auto& ai: a) ai ^= sum;
  fin(a);
  return 0;
}


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

struct Dice {
	int top;
	int north;
	int east;
	int south;
	int west;
	int bottom;
};

void rotn(Dice& d);
void rote(Dice& d);
//void rots(Dice& d);
//void rotw(Dice& d);
void rotc(Dice& d);
bool judge(Dice& d1, Dice& d2);
bool isdifferent(Dice& d1, Dice& d2);

int tmp;

int main() {
	int i, j, n;
	Dice d[100];
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> d[i].top >> d[i].south >> d[i].east >> d[i].west >> d[i].north >> d[i].bottom;
	}
	for (i = 0; i < n - 1; i++) {
		for (j = i + 1; j < n; j++) {
			if (isdifferent(d[i], d[j]) == false) {
				cout << "No\n";
				return 0;
			}
		}
	}
	cout << "Yes\n";
	return 0;
}



void rotn(Dice& d) {
	tmp = d.top;
	d.top = d.south;
	d.south = d.bottom;
	d.bottom = d.north;
	d.north = tmp;
}

void rote(Dice& d) {
	tmp = d.top;
	d.top = d.west;
	d.west = d.bottom;
	d.bottom = d.east;
	d.east = tmp;
}

/*
void rots(Dice& d) {
	tmp = d.top;
	d.top = d.north;
	d.north = d.bottom;
	d.bottom = d.south;
	d.south = tmp;
}

void rotw(Dice& d) {
	tmp = d.top;
	d.top = d.east;
	d.east = d.bottom;
	d.bottom = d.west;
	d.west = tmp;
}

*/

void rotc(Dice& d) {
	tmp = d.north;
	d.north = d.west;
	d.west = d.south;
	d.south = d.east;
	d.east = tmp;
}

bool judge(Dice& d1, Dice& d2) {
	if (d1.top == d2.top && d1.north == d2.north && d1.east == d2.east
		&& d1.south == d2.south && d1.west == d2.west && d1.bottom == d2.bottom)return true;
	else return false;
}

bool isdifferent(Dice &d1, Dice &d2) {
	int i, j;
	for (i = 0; i < 4; i++) {
		for (j = 0; j < 4; j++) {
			if (judge(d1, d2) == true) {
				return false;
			} else {
				rotc(d2);
			}
		}
		rotn(d2);
	}
	rote(d2);
	for (j = 0; j < 4; j++) {
		if (judge(d1, d2) == true) {
			return false;
		} else {
			rotc(d2);
		}
	}
	rote(d2); rote(d2);
	for (j = 0; j < 4; j++) {
		if (judge(d1, d2) == true) {
			return false;
		} else {
			rotc(d2);
		}
	}
	return true;
}

Measured memory_bytes: 1128
function main(input) {
  const [n, d] = input[0].trim().split(" ").map(i => parseInt(i));
  let cnt = 0;
  for(let i=1;i<=n;i++){
    let [x,y]=input[i].trim().split(" ").map(i => parseInt(i));
    if(Math.sqrt(x*x+y*y)<=d){
      cnt++;
    }
  }
  console.log(cnt);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));

Measured memory_bytes: 62992
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextLong()
  val mod = 1000000007

  def plus(a: Long, b: Long): Long = (a + b) % mod
  def minus(a: Long, b: Long): Long = (a - b + mod) % mod
  def times(a: Long, b: Long): Long = (a * b) % mod

  def pow(a: Long, n: Long, res: Long = 1): Long = {
    if (n == 0) {
      res
    } else if ((n&1) == 0) {
      pow(times(a,a), n >> 1, res)
    } else {
      pow(times(a,a), n >> 1, times(res,a))
    }
  }

  println(plus(minus(pow(10, n), times(2, pow(9, n))), pow(8, n)))
}


Measured memory_bytes: 55424