akhauriyash/Code-Regression huggingface dataset:
/** coder Mohammad Al-Hussein *_^ */
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define mp make_pair
#define All(v) v.begin(),v.end()
#define mod  1000000007
#define write freopen("output.txt","w",stdout)
#define read freopen("test (1).txt","r",stdin)
#define FIO std::ios_base::sync_with_stdio(false);
using namespace std;
int dp[16][16][2];
vector<int> v;

int dx[4] = {-2,-2,1,-1};
int dy[4] = {1,-1,-2,-2};
int solve(int x,int y,bool turn)
{
    if(x < 0 || y < 0 || x > 14 || y > 14)
    {
        if(!turn)  return 0;
        else return 1;
    }
    int &ret = dp[x][y][turn];

    if(ret != -1) return ret;

    if(turn)
    {
        bool x1 = 0,x2 = 0,x3 = 0,x4 = 0;
        x1 = solve(x+dx[0],y+dy[0],!turn);
        x2 = solve(x+dx[1],y+dy[1],!turn);
        x3 = solve(x+dx[2],y+dy[2],!turn);
        x4 = solve(x+dx[3],y+dy[3],!turn);

        return ret = x1 || x2 || x3 || x4;
    }
    else
    {
        bool x1 = 0,x2 = 0,x3 = 0,x4 = 0;
        x1 = solve(x+dx[0],y+dy[0],!turn);
        x2 = solve(x+dx[1],y+dy[1],!turn);
        x3 = solve(x+dx[2],y+dy[2],!turn);
        x4 = solve(x+dx[3],y+dy[3],!turn);
        return ret = x1 && x2 && x3 && x4;
    }
}
int a[105][105];
int main()
{
    string s;
    int sum = 0;
    cin >> s;
    for(int i=1;i<s.length();i++)
        if(s[i] != s[i-1])
        sum++;
    cout << sum << endl;







    return 0;
}















//
//    ll k;
//    scanf("%I64d",&k);
//    ll L = 1,R = 1e9,mid,ans;
//    while(L <= R)
//    {
//        mid = (L+R)/2;
//        if(1LL * mid*(mid-1)/2 >= k)
//        {
//            ans = mid;
//            R = mid-1;
//        }
//        else
//            L = mid+1;
//    }
//    if(ans * (ans-1) / 2 == k)
//    {
//        for(int i=ans; i>=1; i--)
//            printf("%d ",i);
//        return 0;
//    }
//    else
//    {
//        int m = ans-1;
//        int r = 1;
//        while(1)
//        {
//            if(k > m)
//            {
//                vis[r] = 1;
//                my.push_back(r++);
//                k -= m;
//                m--;
//            }
//            else
//            {
//                for(int i=ans; i>=1; i--)
//                    if(!vis[i])
//                        my.push_back(i);
//                int s1 = my[my.size()-1];
//                for(int i=my.size()-1; i>=2; i--)
//                {
//                    if(m-- > 0)
//                        swap(my[i],my[i-1]);
//                }
//            }
//        }
//    }
//    for(int i=my.size()-1; i >= 1; i--)
//        cout << my[i] << ' ';


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    long N = scan.nextLong();
    long A = scan.nextLong();
    long B = scan.nextLong();
    scan.close();

    long count = N / (A + B);
    long amari = N % (A + B);

    System.out.println(A * count + (A>=amari ? amari : A));
  }
}

Measured memory_bytes: 23892
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		
		Scanner in = new java.util.Scanner(System.in);
		char[] S = in.next().toCharArray();
		char[] T = in.next().toCharArray();
		int min = T.length;
		int diff;
		for(int i=0; i<=S.length-T.length; i++) {
			diff = 0;
			for(int j=0; j<T.length; j++) {
				if(S[i+j] != T[j]) {
					diff++;
				}
			}
			if(min > diff) {
				min = diff;
			}
		}
		
		System.out.println(min);
		
		
		in.close();
	}
}


Measured memory_bytes: 35512
#include<bits/stdc++.h>
using namespace std;
string str;
bool is(int x, int y);
int main()
{
	cin >> str;
	cout << ((is(0, str.length() - 1) && is(0, str.length() / 2 - 1) && is(str.length() / 2 + 1, str.length() - 1)) ? "Yes" : "No") << endl;
	return 0;
}
bool is(int x, int y)
{
	while (x <= y)
	{
		if (str[x] != str[y])
			return false;
		x++;
		y--;
	}
	return true;
}

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


typedef long long ll;
const ll INF = 1e18;


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

	vector<ll> P(N + 1), C(N + 1);
	for (int i = 1; i <= N; ++i) cin >> P[i];
	for (int i = 1; i <= N; ++i) cin >> C[i];

	ll ans = -INF;
	for (int s = 1; s <= N; ++s) {
		// find loop
		ll tot = 0, len = 0;
		int x = s;
		vector<int> visited(N + 1, 0);
		while (!visited[x]) {
			visited[x] = 1;
			tot += C[x];
			len++;
			x = P[x];
		}

		// search max
		ll now = 0;
		for (int i = 1; i <= len; ++i) {
			x = P[x]; now += C[x];
			if (i > K) break;
			ll sc = now;
			if (tot > 0) sc += ((K - i) / len) * tot;
			ans = max(ans, sc);
		}
	}

	cout << ans << endl;

	return 0;
}


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

typedef struct{
  char mark;
  int value;
} card;

#define MAX 36

int N;

int isStable(card *,card *);

int main(){
  int i,j,minj,is;
  card C1[MAX],C2[MAX],temp;

  scanf("%d",&N);
  if(N<1 || N>MAX){
    exit(1);
  }
  for(i=0;i<N;i++){
    scanf(" %c%d",&C1[i].mark,&C1[i].value);
  }

  for(i=0;i<N;i++){
    C2[i]=C1[i];
  }

  //BubbleSort
  for(i=0;i<N;i++){
    for(j=N-1;j>=i+1;j--){
      if(C1[j].value<C1[j-1].value){
	temp=C1[j];
	C1[j]=C1[j-1];
	C1[j-1]=temp;
      }
    }
  }

  //SelectionSort
  for(i=0;i<N;i++){
    minj=i;
    for(j=i;j<N;j++){
      if(C2[j].value<C2[minj].value){
	minj=j;
      }
    }
    temp=C2[i];
    C2[i]=C2[minj];
    C2[minj]=temp;
  }

  //BubbleSort output
  for(i=0;i<N-1;i++){
    printf("%c%d ",C1[i].mark,C1[i].value);
  }
  printf("%c%d\n",C1[N-1].mark,C1[N-1].value);
  printf("Stable\n");

  is=isStable(C1,C2); //SelectionSort isStable

  //SelectionSort output
  for(i=0;i<N-1;i++){
    printf("%c%d ",C2[i].mark,C2[i].value);
  }
  printf("%c%d\n",C2[N-1].mark,C2[N-1].value);
  if(is==1){
    printf("Stable\n");
  }else{
    printf("Not stable\n");
  }

  return 0;
}

int isStable(card *in,card *out){
  int i;

  for(i=0;i<N;i++){
    if(in[i].mark!=out[i].mark){
      return 0; //false
    }
  }

  return 1; //true
}

Measured memory_bytes: 608
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define MAX 500000
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
using namespace __gnu_pbds; 
using namespace std;

typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> new_data_set; 

ll arr[MAX][3];
ll dp[110][110000];
ll f(pii* a,ll W,ll n){
	if(W<0) return -1;
	if(W==0) return 0;
	if(n==0) return 0;
	if(dp[n][W]!=-1) return dp[n][W];
	ll first = f(a+1,W,n-1);
	ll second = f(a+1,W-a[0].fi,n-1);
	if(second==-1) return first;
	second += a[0].se;
	dp[n][W]=max(first,second);
	return dp[n][W];
}

int main(){
	ios_base::sync_with_stdio(false);
	memset(dp,-1,sizeof(dp));
	ll n,W;cin>>n>>W;
	pii a[n];
	For(i,0,n) cin>>a[i].fi>>a[i].se;
	cout<<f(a,W,n)<<endl;
}

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

using namespace std;

#define int long long

typedef long long ll;

long long n;
pair<double, double> xy[500];

bool comp(pair<double, double> f, pair<double, double> s)
{
    return atan2(f.second, f.first) < atan2(s.second, s.first);
}

signed main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> xy[i].first >> xy[i].second;
    }
    sort(xy, xy + n, comp);
    for (int i = n; i < 2 * n; i++)
    {
        xy[i] = xy[i - n];
    }
    double ans = 0;
    for (int i = 0; i < n; i++)
    {
        double x = 0, y = 0;
        for (int j = 0; j < n; j++)
        {
            x += xy[i + j].first;
            y += xy[i + j].second;
            ans = max(ans, x * x + y * y);
        }
    }
    cout << setprecision(20) << sqrt(ans);
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll a,b,c,cnt=0,i,j;
    cin>>a>>b>>c;
    for(i=a; i<=b; i++)
    {
        if(c%i==0) cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}



Measured memory_bytes: 3100
#include<iostream>
#include<math.h>
#include<string>
#include<map>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<bitset>
#include<stack>
#include<algorithm>
#include<climits>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long int
#define vll vector<ll>
#define mii map<ll, ll>
#define debug(x) cerr << #x << " is " << x << "\n";
#define debug1(x, y) cerr << #x << " is " << x << "\n" << #y << " is " << y << "\n";
#define w(x) ll x; cin >> x; while(x--)
#define endl "\n"
#define f first 
#define s second 
#define fo(n) for(ll i = 0LL; i < n; ++i) 
#define setbits(n) __builtin_popcount(n)
#define all(x) x.begin(), x.end()
#define sortAll(x) sort(x.begin(), x.end())
#define pb push_back
#define mk make_pair
#define PERMUTE next_permutation
#define RESET(a, b) memset(a, b, sizeof(a))
#define MOD 1000000007
using namespace std;
 
int main(){
    fast
    ll ans = 0;
    string s, t;
    cin >> s >> t;
    for(int i = 0; i < s.size(); ++i) {
        if(s[i] != t[i]) {
            ans++;
        } 
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3804
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long d = sc.NextLong();
        long t = sc.NextLong();
        long s = sc.NextLong();

        bool ok = (t * s) >= d;

        string answer = ok ? "Yes" : "No";

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 27480
from collections import deque

def main():
    S = deque(input())
    Q = int(input())
    revFlag = False
    for i in range(Q):
        tmp = list(input().split())
        if tmp[0] == "1":
            if revFlag:
                revFlag = False
            else:
                revFlag = True
        else:
            if tmp[1] == "1":
                if revFlag:
                    S.append(tmp[2])
                else:
                    S.appendleft(tmp[2])
            else:
                if revFlag:
                    S.appendleft(tmp[2])
                else:
                    S.append(tmp[2])
    if revFlag:
        S.reverse()
    print("".join(S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 79864
#pragma GCC optimize("O3", "unroll-loops")
//#pragma GCC target("avx2")
//#pragma GCC target ("sse4")
#pragma optimize("fast-math")

#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
#define endl '\n'
#define ull unsigned long long
#define si short int
#define ll long long
#define ld long double
#define pb push_back
#define pii pair<int, int>
#define pdd pair<double, double>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define piii pair<pair<int, int>, int>
#define all(vec) (vec).begin(), (vec).end()
#define rall(vec) (vec).rbegin(), (vec).rend()
#define piiii pair<pair<int, int>, pair<int, int>>
struct kek{
    int a,b,c,d;
};




vector<kek> arr;
int ans=0;
void gogo(int n, int m, int kolvo, vector<int> &now, int last){
    if(kolvo==n){
        int sm=0;
        for(int j=0;j<arr.size();j++){
            if(now[arr[j].b-1]-now[arr[j].a-1]==arr[j].c){
                sm+=arr[j].d;
            }
        }
        ans=max(ans, sm);
        return;
    }
    for(int i=last;i<=m;i++){
        now[kolvo]=i;
        gogo(n,m,kolvo+1, now, i);
    }

}
void solve() {
    int n, m ,q;
    cin>>n>>m>>q;
    arr.resize(q);
    for(int i=0;i<q;i++){
        cin>>arr[i].a>>arr[i].b>>arr[i].c>>arr[i].d;
    }
    vector<int> now(n);
    gogo(n, m, 0, now, 1);
    cout<<ans<<endl;

}

void testcases(int n) {
    n = 1 - n;
    if (!n) cin >> n;
    for (int i = 0; i < n; i++) {
        solve();
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    //freopen("C:\\Users\\Maximus\\CLionProjects\\Codeforces\\BestTeam\\output.txt", "r", stdin);
    //f=fopen("C:\\Users\\Maximus\\CLionProjects\\Codeforces\\BestTeam\\output.txt", "w");
    //freopen("C:\\Users\\Maximus\\CLionProjects\\Codeforces\\BestTeam\\output.txt", "w", stdout);

    unsigned int beg_time = clock();
    testcases(0);
    // 0 - no t, 1 - with t

    unsigned int end_time = clock();
    //cout << endl << endl << end_time - beg_time;
    return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>

int main(void){

	int x;
	int i;
	int j;
	int n;

	i=0;

	scanf("%d",&x);

	while(1){
		i = i+1;
		j=1;
		if(i==x+1)break;
		if( i % 3 == 0){
			printf(" %d",i);
		}
		else{
			while(1){
				if(j>=10000)break;
				n=i/j;	
				if(n % 10 ==3){
					printf(" %d",i);
					break;
				}
				j=j*10;
			}
		}
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;

public class Main {

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

		int n = Integer.parseInt(sc.next());
		
		int [][]c = new int [10][10];
		
		int temp = 0;
		for(int i = 1 ;i <= n ;i++) {
			
			if(i == Math.pow(10, temp+1)) {
				temp++;
			}
			
			int pow10 = (int)Math.pow(10,temp);
			c[i/pow10][i%10]++;
		}
		
		long ans = 0;
		
		for(int i = 1 ;i <= 9 ;i++) {
			for(int j = 1 ; j <= 9 ;j++) {
				ans += (long)c[i][j]*c[j][i];
			}
		}
		
		System.out.println(ans);

	}

}


Measured memory_bytes: 23892
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define FOR(i,a,b) for (int i=(a),for_##i##_max=(b);i<=(for_##i##_max);++i)
#define RFOR(i,a,b) for (int i=(a),rfor_##i##_min=(b);i>=(rfor_##i##_min);--i)
#define REP(i,n) for (int i=0,rep_##i##_len=(n);i<(rep_##i##_len);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

namespace { // Basics

template<typename T>
void chmin(T &x, T y) {
  x = std::min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
  x = std::max(x, y);
}

template<typename T>
__attribute__((unused))
const auto minimum = static_cast<T const &(*)(T const &, T const &)>(std::min);

template<typename T>
__attribute__((unused))
const auto maximum = static_cast<T const &(*)(T const &, T const &)>(std::max);

template<typename T>
__attribute__((unused))
T constexpr infty = std::numeric_limits<T>::max / 3;
template<>
__attribute__((unused))
auto constexpr infty<int> = 1'100'100'100;
template<>
__attribute__((unused))
auto constexpr infty<long long int> = 100'500'400'300'200'100LL;

using lli = long long int;
using ld = long double;

} // namespace

using namespace std;

template <typename T>
struct seq {
  int side;
  vector<T> dat;
  vector<T> block;
  seq(int n): side(csqrt(n)), dat(n, 0), block(side, 0) {
  }
  void add(int s, int t, T x) {
    int i = s;
    while (i < t && i % side != 0) {
      dat[i] += x;
      ++i;
    }
    while (i + side < t) {
      block[i / side] += x;
      i += side;
    }
    while (i <= t) {
      dat[i] += x;
      ++i;
    }
  }
  T get(int i) {
    return dat[i] + block[i / side];
  }
  static int csqrt(int n) {
    int k = 1;
    while (k * k < n) { ++k; }
    return k;
  }
};

int main() {
  // cout << fixed << setprecision(10);

  int N, Q; cin >> N >> Q;
  seq<lli> a(N+1);
  REP(i, Q) {
    int T; cin >> T;
    if (T == 0) {
      int S, T, X; cin >> S >> T >> X;
      a.add(S, T, X);
    } else {
      int I; cin >> I;
      cout << a.get(I) << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3560
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<cstring>
#include<sstream>
using namespace std;

typedef long long ll;

int main() {
  ll a[5];
  ll N; cin >> N;
  ll minNum = 1e18;
  for ( int i = 0; i < 5; i++ ) {
    cin >> a[i];
    minNum = min(minNum,a[i]);
  }
  if ( minNum >= N ) {
    cout << 5 << endl;
    return 0;
  }

  ll k = (N-1)/minNum;
  ll ans = 5 + k;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import bisect
import math
n = int(input())
l = sorted(list(map(int,input().split())))
if len(l)==2 :
  print(l[-1],l[-2])
  exit()
  
a = l[-1]/2
s = bisect.bisect_left(l,a)
if l[s]==a:
  print(l[-1],l[s])
  exit()
k1 = l[s-1]
k2 = l[s]
s1 = a-k1
if k2==l[-1]:
  k2 = k1
s2 = abs(k2-a)
#print(s,k1,k2,s1,s2)
if s1<=s2:
  print(l[-1],k1)
else:
  print(l[-1],k2)

Measured memory_bytes: 14180
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;


void eating_symbols_easy()
{
  string s;
  cin >> s;

  int cnt = 0;
  for (int i = 0; i < 4; ++i)
  {
    if (s[i] == '+') ++cnt;
    else --cnt;
  }
  cout << cnt << "\n";
}


void multiple_of_2_and_n()
{
  int n;
  cin >> n;

  if (n % 2 == 0) cout << n << "\n";
  else cout << 2 * n << "\n";
}


void task_scheduling_problem()
{
  vector<int> a(3);
  for (int i = 0; i < 3; ++i) cin >> a[i];

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

  cout << a[2] - a[0] << "\n";
}


void rated_for_me()
{
  int r;
  cin >> r;

  if (r < 1200) cout << "ABC\n";
  else if (r < 2800) cout << "ARC\n";
  else cout << "AGC\n";
}


void atcoder_crackers()
{
  int n, k;
  cin >> n >> k;

  if (n % k == 0) cout << 0 << "\n";
  else cout << 1 << "\n";
}


void garden()
{
  int a, b;
  cin >> a >> b;

  cout << (a - 1) * (b - 1) << "\n";
}


void train()
{
  int n, i;
  cin >> n >> i;

  cout << n - i + 1 << "\n";
}


void Pair()
{
  int k;
  cin >> k;

  if (k % 2 == 0) cout << k / 2 * k / 2 << "\n";
  else cout << k / 2 * (k / 2 + 1) << "\n";
}


void ABC333()
{
  int a, b;
  cin >> a >> b;

  if ((a == 1 && (b == 1 || b == 3)) || (a == 3 && (b == 1 || b == 3))) cout << "Yes\n";
  else cout << "No\n";
}


int main()
{
  //eating_symbols_easy();
  //multiple_of_2_and_n();
  //task_scheduling_problem();
  //rated_for_me();
  //atcoder_crackers();
  //garden();
  //train();
  //Pair();
  ABC333();
}

Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <vector>
#include <string>
//#include <algorithm>

using namespace std;

int main(){

	string in;

	getline(cin, in);

	for (int i = 0; i < in.size(); i++){
		if (isupper(in[i]) != 0)in[i] = tolower(in[i]);
		else if (islower(in[i]) != 0) in[i] = toupper(in[i]);
	}

	cout << in << endl;


	return 0;
}

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

using namespace std;

typedef long long ll;

#define REP(i, n) for(int i=0; i<n; ++i)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b, c, x, y;
	cin>>a>>b>>c>>x>>y;
	int m;
	x>y ? m=a : m=b;
	int ans;
	if(a+b<=c*2) ans=a*x+b*y;
	else ans=c*min(x, y)*2+min(m, c*2)*abs(x-y);
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
const int mo=998244353,N=4e3+5;
int i,j,k,n,f[N][N],a[N],b[N];
char c[N];
int main(){
	scanf("%s",c+1);n=strlen(c+1);
	for(i=1;i<=n;++i)a[i]=a[i-1]+c[i]-'0',b[i]=b[i-1]+'2'-c[i];f[0][0]=1;
	for(i=0;i<=a[n];++i)
		for(j=!i;j<=b[n];++j){
			k=std::min(n,i+j);
			if(i<=a[k] && j<=b[k])f[i][j]=((i?f[i-1][j]:0)+(j?f[i][j-1]:0))%mo;
		}
	printf("%d\n",f[a[n]][b[n]]);
	return 0;
}

Measured memory_bytes: 60416
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

struct UnionFind
{
    vector<int> par;
   
    UnionFind(int n) : par(n,-1){}
    void init(int n) { par.assign(n,-1);}
 
    int root(int x){
        if(par[x]<0) return x;
        return par[x]=root(par[x]);
    }
 
    bool issame(int x, int y){
        return root(x)==root(y);
    }
    bool merge(int x, int y){
        x=root(x);
        y=root(y);
        if(x==y) return false;
        if(par[x]>par[y])swap(x,y);
        par[x]+=par[y];
        par[y]=x; //大きさが正になるよ
        return true;
    }
    int size(int x){
        return -par[root(x)];
    }
};


signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m;
    cin>>n>>m;
    UnionFind uni(n);
    for (int i = 0; i < m; i++)
    {
        int a,b;
        cin>>a>>b;
        a--,b--;
        uni.merge(a,b);
    }
    int ans=0;
    for (int i = 0; i < n; i++)
    {
        chmax(ans,uni.size(i));
    }
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 4784
#! /usr/bin/env python

if __name__ == '__main__':
    N = int(input())
    a=[[0,0,0]]
    for i in range(N):
        a.append(list(map(int,input().split())))
    flag=0
    for i in range(N):
        if (((a[i+1][0]-a[i][0]) < abs(a[i][1]-a[i+1][1]) + abs(a[i][2]-a[i+1][2])) or ((a[i+1][0]-a[i][0]) % 2 != (abs(a[i][1]-a[i+1][1]) + abs(a[i][2]-a[i+1][2])) % 2)):
            flag = 1
            break
    if flag == 0:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 27300
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        if (9 < a) {
            System.out.println(-1);
            return;
        }
        int b = scanner.nextInt();
        if (9 < b) {
            System.out.println(-1);
            return;
        }
        System.out.println(a*b);
    }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

Int calc(vector<Int> &v){
  Int n=v.size();
  Int res=0;
  using P = pair<Int, Int>;
  stack<P> sp;
  sp.emplace(-1,-1);
  for(Int i=0;i<n;i++){
    Int j=i;
    while(sp.top().second>v[i]){
      j=sp.top().first;
      chmax(res,(i-j)*sp.top().second);
      sp.pop();
    }
    if(sp.top().second<v[i]) sp.emplace(j,v[i]);
  }
  while(!sp.empty()){
    chmax(res,(n-sp.top().first)*sp.top().second);
    sp.pop();
  }
  return res;
}
signed main(){
  Int n;
  cin>>n;
  vector<Int> v(n);
  for(Int i=0;i<n;i++) cin>>v[i];
  cout<<calc(v)<<endl;
  return 0;
}



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

int main() {
    int n, a, b;
    cin >> n >> a >> b; n -= 2;
    ll ans = (ll)b*n - (ll)a*n + 1LL;
    cout << (ans >= 0 ? ans : 0) << endl;
}


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

using namespace std;

int main() {
	int n, a[15], sum = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		sum += a[i];
	}
	sort(a, a + n);
	sum -= a[n - 1];
	if (a[n - 1] < sum)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
from itertools import combinations,permutations # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))
nya = [i+1 for i in range(n)]

jun = []
for a in permutations(nya):
    jun.append(a)
for i in range(len(jun)):
    if jun[i] == P:
        p = i
    if jun[i] == Q:
        q = i
print(abs(p-q))


Measured memory_bytes: 8172
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;

class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        void solve(InputReader in, PrintWriter out) {
            int N = in.nextInt();
            int[] A = in.nextIntArray(N);

            int minus = 0;
            long ans = 0;
            for (int i = 0; i < N; ++i) {
                if (A[i] < 0) {
                    ++minus;
                    A[i] *= -1;
                }
                ans += A[i];
            }
            if (minus % 2 == 0) {
                out.println(ans);
            } else {
                Arrays.sort(A);
                out.println(ans - A[0]*2);
            }
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

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

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

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

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


Measured memory_bytes: 43372
import sys
from collections import deque
input = sys.stdin.readline

H, W = map(int,input().split())

maze_array = [input().split()[0] for _ in range(H)]

ans = 0
for hh in range(H):
    for ww in range(W):
        if maze_array[hh][ww] == "#":
            continue
        flag = [[0 for _ in range(W)] for _ in range(H)]
        queue = deque()
        queue.append((hh,ww,0))
        flag[hh][ww] = 1
        while len(queue):
            h, w, p = queue.popleft()
            # print(h,w,p)
            if w != W - 1 and flag[h][w+1] == 0 and maze_array[h][w+1] == ".":
                flag[h][w+1] = 1
                ans = max(ans,p+1)
                queue.append((h,w+1,p+1))
            if h != H - 1 and flag[h+1][w] == 0 and maze_array[h+1][w] == ".":
                flag[h+1][w] = 1
                ans = max(ans,p+1)
                queue.append((h+1,w,p+1))
            if w != 0 and flag[h][w-1] == 0 and maze_array[h][w-1] == ".":
                flag[h][w-1] = 1
                ans = max(ans,p+1)
                queue.append((h,w-1,p+1))  
            if h != 0 and flag[h-1][w] == 0 and maze_array[h-1][w] == ".":
                flag[h-1][w] = 1
                ans = max(ans,p+1)
                queue.append((h-1,w,p+1))
print(ans) 
             

Measured memory_bytes: 69616
#include <bits/stdc++.h>
#include <stdio.h>
#include <vector>
#define rep(i,n) for(int i = 0; i < n; i++)
using ll = long long;
using namespace std;
// O(log N)　keyのある場所を返す。なかったら-1を返す
int search(int key, vector<int> a){
  int right = a.size();
  int left = 0;
  while(right >= left){
    int middle = left + (right - left) / 2;
    if(a[middle] == key) return middle; //keyが入ってる場所を返す
    else if(a[middle] > key) right = middle - 1;
    else if(a[middle] < key) left = middle + 1;
  }
  //なければ-1を返す
  return -1;
}
// O(N^2) babble sort
int main(){
  int n;
  cin >> n;
  int f[n][10];
  int p[n][11];
  rep(i, n){
    rep(j, 10){
      cin >> f[i][j];
    }
  }
  rep(i, n){
    rep(j, 11){
      cin >> p[i][j];
    }
  }
  int ans = -10000000 * n;
  for(int check = 1; check < (1 << 10); check++){
    int highScore = 0;
    rep(N, n){
      int cnt = 0;
      rep(j, 10){
        if(((check >> j) & 1) && f[N][j]) cnt++;
      }
      highScore += p[N][cnt];
    }
    ans = (highScore > ans) ? highScore : ans;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	char a[6];
	for(int i=0;i<6;i++){
		cin>>a[i];
	}
	if(a[0]==a[5]&&a[1]==a[4]&&a[2]==a[3]){
		cout<<"YES"<<endl;
	}
	else {
		cout<<"NO"<<endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void) {

 int W,H,x,y,r; 

   scanf("%d %d %d %d %d",&W,&H,&x,&y,&r); 

   if(H>=y+r&&W>=x+r&&r<=x&&r<=y)

 { 

  printf("Yes\n");

 } 

 else

 {

  printf("No\n"); 

 } 

 return 0;

}

Measured memory_bytes: 584
import Data.List
import Control.Applicative

solve :: [Int] -> (Int, [Int])
solve xs = rec 0 xs
    where rec i xs
            | xs == nextXs = (i, xs)
            | otherwise    = rec (i+1) nextXs
            where nextXs = next xs
          next xs = map (length . flip filter xs . (==)) xs
                    

main = do
    n <- readLn :: IO Int
    if n == 0 then return ()
    else do
        xs <- map read <$> words <$> getLine
        let (count, fixXs) = solve xs
        print count
        putStrLn $ unwords $ map show $ fixXs
        main

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

bool is(size_t i) {
    size_t const target = i / 100;
    return i % 100 == target * 11;
}
int main() {
    size_t n;
    cin >> n;
    for (auto i = n; i <= 999; i++)  {
        if (is(i)) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}



Measured memory_bytes: 256
from bisect import bisect
S = input()
T = input()
LS = len(S)
LT = len(T)

H = {chr(i): [] for i in range(ord('a'), ord('z')+1)}
for i, s in enumerate(S):
    H[s].append(i)

dp = [0] * (LT+1)
dp[0] = -1
valid = True

for i in range(1,LT+1):
    t = T[i-1]
    p = dp[i-1] % LS if i > 1 else -1
    if len(H[t]) == 0:
        valid = False
        break
    q = bisect(H[t], p)
    if q == len(H[t]):
        dp[i] = dp[i-1] + LS - p + H[t][0]
    else:
        dp[i] = dp[i-1] + H[t][q] - p

print(dp[-1] + 1 if valid else -1)


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

int main(){
    int n;
    string s;
    cin >>n>>s;
    int ans=0;
    rep(i, n){
        if(s[i]=='A'&&i<n-2){
            if(s[i+1]=='B'&&s[i+2]=='C'){
                ans+=1;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3624
import std.stdio,std.string,std.conv;

int main()
{
	int[char] roman = ['I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000];
	string s;
	while((s = readln.chomp).length != 0)
	{
		int ans = 0;
		for(int i=0;i<s.length-1;i++)
		{
			if(roman[s[i]] >= roman[s[i+1]]) ans += roman[s[i]];
			else ans -= roman[s[i]];	
		}
		ans += roman[s[s.length-1]];
		writeln(ans);
	}
	return 0;
}

Measured memory_bytes: 1048
## coding: UTF-8
from decimal import *
from itertools import permutations, combinations,combinations_with_replacement,product
import math


s = input().split()
p = [int(w) for w in s] #これで勝手にNまで拾ってくれます


A = p[0]
B = p[1]
C = p[2]
D = p[3]

mode = 'Tattack'
while (A>0 and C>0):
    if(mode == 'Tattack'):
        C = C-B
        mode = 'Aattack'
    else:
        A = A-D 
        mode = 'Tattack'

if(A<=0):
    print('No')
else:
    print('Yes')

Measured memory_bytes: 9884
#include <stdio.h>

int main(void){
  int K, S, i, j, count = 0;
  scanf("%d %d", &K, &S);
  for(i=0; i <= K; i++){
    for(j=0; j <= K; j++){
      if(0 <= S - i - j && S - i - j <= K)
        count++;
    }
  }
  printf("%d",count);
  return 0;
}

Measured memory_bytes: 1724
import Control.Applicative
import Control.Monad
import Data.Ratio

main :: IO ()
main = do
  s <- getLine
  unless (s == "#") $ do
    prt $ solve s
    main

solve :: String -> Rational
solve = snd . foldr f (0, 0) . filter (\c -> c == 'w' || c == 'n')
  where
    f 'w' (0, _) = (1, 90)
    f 'n' (0, _) = (1, 0)
    f 'w' (i, a) = (i + 1, a + 90 % (2 ^ i))
    f 'n' (i, a) = (i + 1, a - 90 % (2 ^ i))

prt :: Rational -> IO ()
prt r
  | denominator r == 1 = print $ numerator r
  | otherwise = putStrLn $ show (numerator r) ++ "/" ++ show (denominator r)



Measured memory_bytes: 4024
def main():
    l = input().split(' ')

    while len(l) > 1:
        idx = 0
        while l[idx] not in ["+", "-", "*"]:
            idx += 1
        res = str(eval(str(l[idx-2] + l[idx] + l[idx-1])))
        l[idx-2] = res
        l.pop(idx-1)
        l.pop(idx-1)

    print(l[0])

main()


Measured memory_bytes: 5572
using System;
using System.Linq;
class aoj
{
    static void Main()
    {
        int[] c = new int[8];
        c[0] = 1;c[1] = 2;c[2] = 1;c[3] = 2;c[4] = 1;c[5] = 4;c[6] = 1;c[7] = 4;
        while (true)
        {
            string a = Console.ReadLine();
            if (String.IsNullOrEmpty(a)) break;
            int[] b = a.Split(' ').Select(int.Parse).ToArray();
            int[] f = new int[3];
            f[0] = 1000000000;
            for (int i = 0; i < 8; i++)
            {
                int e = 0;
                char[] h = new char[8];
                for (int j = 0; j < 8; j++)
                {
                    int d = j + i;
                    if (d >= 8)
                        d -= 8;
                    int g = b[j] - c[d];
                    if (g < 0)
                        g = 0;
                    e += g;
                    h[j] = (char)(c[d] + '0');
                }
                if (f[0] > e)
                {
                    f[0] = e;
                    f[1] = i;
                    string k = new string(h);
                    f[2] = int.Parse(k);
                }
                if (f[0] == e)
                {
                    string k = new string(h);
                    int l = int.Parse(k);
                    if (f[2] > l)
                    {
                        f[1] = i;
                        f[2] = l;
                    }
                }
            }
            int m = f[1];
            for (int i = 0; i < 8; i++)
            {
                int n = m + i;
                if (n >= 8)
                    n -= 8;
                if (i == 0)
                    Console.Write(c[n]);
                else
                    Console.Write(" " + c[n]);
            }
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 9548
import sys
input = sys.stdin.readline
 
N = int(input())
if N < 105:
  print(0)
elif N < 135:
  print(1)
elif N < 165:
  print(2)
elif N < 189:
  print(3)
elif N < 195:
  print(4)
else:
  print(5)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>

#define ALL(a)  (a).begin(),(a).end()

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

int main() {
    ll n;
    ll ans = 0;
    // vector<ll> a;
    vector<long double> l;

    cin >> n;

    for (int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        //a.push_back (tmp);
        if (i == 0) l.push_back (tmp);
        else l.push_back (l[i-1] + tmp);
    }

    long double s = l[n-1];

    ll idx_l, idx_r;
    auto p = lower_bound(ALL(l), s/2);
    idx_r = distance(l.begin(), p);

    p = upper_bound(ALL(l), s/2) - 1;
    idx_l = distance(l.begin(), p);

    ans = min(abs(s - l[idx_l] * 2), abs(s - l[idx_r] * 2));


    //cout << s << l[idx_l] << l[idx_r] << endl;
    cout <<  ans << endl;
}

Measured memory_bytes: 6512
nk = [int(s) for s in input().split()]
n, k = nk[0], nk[1]
tot = 0
all_sums = [0]
for i in range(1, 200001):
    all_sums.append(i+all_sums[-1])
for i in range(k, n+1):
    tot = (tot + (all_sums[n]-all_sums[n-i]) - (all_sums[i-1]) + 1)%1000000007
print(tot+1)

Measured memory_bytes: 82016
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<map>
#include<vector>

using namespace std;
typedef long long LL;

const int N=1e5,mod=1e9+7;

int n,k;
LL ans=1;
vector<int> V[N+5];

inline void Add(int u,int v)
{
	V[u].push_back(v);
	V[v].push_back(u);
}

int main()
{
	int a,b;
	scanf("%d %d",&n,&k);
	for(int i=1;i<n;i++)
	{
		scanf("%d %d",&a,&b);
		Add(a,b);
	}
	for(int i=1;i<=n;i++)
	{
		LL x=k-2;
		LL y=V[i].size()-1;
		if(i == 1)
			x++,y++;
		if(x<y)
		{
			printf("0\n");
			return 0;
		}
		LL res=1;
		for(LL ii=x,j=1;j<=y;j++,ii--)
		{
			res *= ii;
			res %= mod;
		}
		ans *= res;
		ans %= mod;
	}
	ans = ans*k%mod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 6136
N = int(input())
A = map(int,input().split())

l = [0 for i in range(9)]
for a in A:
  ind = 0
  while ind < 8:
    if a < (ind+1)*400:
      break
    ind += 1
  l[ind] += 1

ans_max = 0
ans_min = 0
for i in range(0, 8):
  if l[i] > 0:
    ans_max += 1
    ans_min += 1
if l[-1] > 0:
  ans_max = ans_max + l[-1]
  ans_min = max(ans_min, 1)
print(ans_min, ans_max)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	string s,t;
	cin >> s >> t;
	cout << t << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll n;
	cin >> n;
	ll x[n];
	zep(i, 0, n){
		cin >> x[i];
	}
	
	ll ans = INF;
	rep(i, 1, 100){
		ll buf = 0;
		zep(j, 0, n){
			buf += (x[j]-i)*(x[j]-i);
		}
		ans = min(buf, ans);
	}
	print(ans)
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
  	cin>>n;
  	int a[n];
  for(int i=0;i<n;i++){
  	cin>>a[i];
  	}
  int s=0;
  for(int i=0;i<n;i++){
  	for(int j=i+1;j<n;j++){
    s+=a[i]*a[j];
    }	
  }
  cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 256
import collections

N, K, Q = [int(_) for _ in input().split()]
d = collections.defaultdict(int)

A = [int(input()) for _ in range(Q)]
for a in A:
    d[a] += 1

for i in range(1, N+1):
    if d[i] <= Q - K:
        print("No")
    else:
        print("Yes")


Measured memory_bytes: 20116
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

vector<vector<int> > abcd;
vector<vector<int> > A;
int N, M;

void make_As(int m, vector<int> cur) {
    if(cur.size()==N) {
        A.push_back(cur);
    } else if(m>M) {
        return;
    } else {
        make_As(m+1, cur);
        cur.push_back(m);
        make_As(m, cur);
    }
}

int main() {
    int Q;
    cin >> N >> M >> Q;
    vector<int> tmp;
    make_As(1, tmp);
    abcd.assign(Q, vector<int>(4));
    for(int q=0; q<Q; q++) {
        for(int i=0; i<4; i++) {
            cin >> abcd[q][i];
        }
    }
    
    int ans=0;
    for(int i=0; i<A.size(); i++) {
        int tmp=0;
        for(int q=0; q<Q; q++) {
            if(A[i][abcd[q][1]-1]-A[i][abcd[q][0]-1]==abcd[q][2]) {
                tmp += abcd[q][3];
            }
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 9768
n, m = map(int, input().split())
resultList = [[0 for i in range(2)] for j in range(n)]
#print(resultList)
for i in range(m) :
    result = input().split()
    prob = int(result[0]) - 1
    #print(resultList, result[1])
    if result[1] == 'AC' and resultList[prob][0] == 0 :
        resultList[prob][0] = 1
    if result[1] == 'WA' and resultList[prob][0] == 0 :
        resultList[prob][1] += 1

#print(resultList)

ansAC = 0
ansWA = 0
for i in range(n) :
    ansAC += resultList[i][0]
    if resultList[i][0] == 1 :
        ansWA += resultList[i][1]

print(ansAC, ansWA)


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

public class Main {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        int n = in.nextInt();
        int w = in.nextInt();

        int[] wa = new int[n];
        long[] va = new long[n];
        for (int i = 0; i < n; i++) {
            wa[i] = in.nextInt();
            va[i] = in.nextInt();
        }
        long[][] dp = new long[n][w];
        for (int i = 0; i < w; i++) {
            if (i >= wa[0] - 1)
                dp[0][i] = va[0];
        }

        for (int i = 1; i < n; i++) {
            for (int j = 0; j < w; j++) {
                long val = j - wa[i] >= 0 ? dp[i - 1][j - wa[i]] + va[i] : 0;
                if (j >= wa[i] - 1) {
                    val = Math.max(val, va[i]);
                }
                dp[i][j] = Math.max(dp[i - 1][j], val);
            }
        }

        long ans = 0;
        for (int k = 0; k < w; k++) {
            ans = Math.max(ans, dp[n - 1][k]);
        }
        out.println(ans);
        out.close();
    }

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

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

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

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

    }
}


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

int main() {

    int n;
    cin >> n;

    vector<int> v(n);

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

    sort(v.begin(), v.end());

    int a = v[n - 1];

    double mid = a / 2.0;
    
    int b = v[0];
    double minD = abs(mid - b);

    for(int i = 1; i < n - 1; ++i) {
        double d = abs(mid - v[i]);

        if(minD > d) {
            minD = d;
            b = v[i];
        }
    }

    cout << a << " " << b << endl;

    return 0;
}

Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
void solve() {
    int r, c;
    cin >> r >> c;
    char str[r][c];
    for(int i=0;i<r;i++) {
        for(int j=0;j<c;j++) {
            cin >> str[i][j];
        }
    }
    int a[r][c], b[r][c], C[r][c], d[r][c];
    for(int i=0;i<r;i++) {
        for(int j=0;j<c;j++) {
            if(str[i][j] == '#')
                a[i][j] = 0;
            else if(j == 0 && str[i][j] == '.')
                a[i][j] = 1;
            else if(str[i][j] == '.')
                a[i][j] = a[i][j-1] + 1;
        }
    }
    // for(int i=0;i<r;i++) {
    //     for(int j=0;j<c;j++) {
    //         cout << a[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    // return ;
    for(int i=0;i<r;i++) {
        for(int j=c-1;j>=0;j--) {
            if(str[i][j] == '#')
                b[i][j] = 0;
            else if(j == c-1 && str[i][j] == '.')
                b[i][j] = 1;
            else if(str[i][j] == '.')
                b[i][j] = b[i][j+1] + 1;
        }
    }
    // for(int i=0;i<r;i++) {
    //     for(int j=0;j<c;j++) {
    //         cout << b[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    for(int j=0;j<c;j++) {
        for(int i=0;i<r;i++) {
            if(str[i][j] == '#')
                C[i][j] = 0;
            else if(i == 0 && str[i][j] == '.')
                C[i][j] = 1;
            else if(str[i][j] == '.')
                C[i][j] = C[i-1][j] + 1;
        }
    }
    // for(int i=0;i<r;i++) {
    //     for(int j=0;j<c;j++) {
    //         cout << C[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    for(int j=0;j<c;j++) {
        for(int i=r-1;i>=0;i--) {
            if(str[i][j] == '#')
                d[i][j] = 0;
            else if(i == r-1 && str[i][j] == '.')
                d[i][j] = 1;
            else if(str[i][j] == '.')
                d[i][j] = d[i+1][j] + 1;
        }
    }
    // for(int i=0;i<r;i++) {
    //     for(int j=0;j<c;j++) {
    //         cout << d[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    int max = 0;
    for(int i=0;i<r;i++) {
        for(int j=0;j<c;j++) {
            int z = a[i][j] + b[i][j] + C[i][j] + d[i][j] - 3;
            if(z > max)
                max = z;
        }
    }
    cout << max << endl;
    return ;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 66688
program rss
  implicit none
  integer :: N,i,val
  integer,allocatable :: V(:),C(:)

  read(*,*) N
  allocate(V(N))
  allocate(C(N))

  read(*,*) V
  read(*,*) C
  val=0
  do i=1,N
     if(V(i).gt.C(i)) then
        val=val+(V(i)-C(i))
     endif
  enddo
  write(*,'(i0)') val
  deallocate(V)
  deallocate(C)



end program rss



Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	int n;
  cin>>n;
	if (n%2 == 0) {
       cout<<n;
	}
	
   else if (n%2 !=0)
   {
   	cout<<n*2;
   }
   
	
	return 0;
}

	


Measured memory_bytes: 256