akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
const int N = 3e3 + 5;
const int mod = 1e9 + 7;
const int inv = 5e8 + 4; 
using namespace std; 

int n, q, a[N], f[N][N], ans; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

int fpow(int x, int y)
{
	int res = 1;
	for( ; y; y >>= 1, x = 1ll * x * x % mod)
		if(y & 1) res = 1ll * res * x % mod;
	return res; 
}

int main()
{
	n = read <int> (), q = read <int> ();
	for(int i = 1; i <= n; i++)
		a[i] = read <int> ();
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			f[i][j] = a[i] > a[j]; 
	for(int x, y, i = 1; i <= q; i++)
	{
		x = read <int> (), y = read <int> ();
		f[x][y] = f[y][x] = 1ll * (f[x][y] + f[y][x]) % mod * inv % mod; 
		for(int j = 1; j <= n; j++)
		{
			if(j == x || j == y) continue;
			f[x][j] = f[y][j] = 1ll * (f[x][j] + f[y][j]) % mod * inv % mod; 
			f[j][x] = f[j][y] = 1ll * (f[j][x] + f[j][y]) % mod * inv % mod; 
		}
	}
	for(int i = n; i >= 1; i--)
		for(int j = i - 1; j >= 1; j--)
			ans = (ans + f[j][i]) % mod; 
	printf("%lld\n", 1ll * ans * fpow(2, q) % mod); 
	return 0; 
}


Measured memory_bytes: 35456
#include <iostream>

int main() {
  int m, d;
  std::cin >> m >> d;
  int ans = 0;
  for (int i = 1; i <= m; ++i) {
    for (int j = 20; j <= d; ++j) {
      int a = j % 10;
      int b = j - a;
      if (a >= 2 && b / 10 * a == i) ++ans;
    }
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <set>
#include <cmath>
#include <math.h>

using namespace std;

int v[11]={0};
int ans=0;
int n=0;

int kai(int c){
    if(c==0){
        return 1;
    }
    int r=3;
    while(c>1){
        r*=3;
        c--;
    }
    return r;
}

int f(int a,int b){
    if(a>=n){
        return 0;
    }
    if((v[a]+b)%2==0){
        ans+=kai(n-a-1);
        return 0;
    }
    a++;
    for(int i=-1;i<2;i++){
        f(a,i);
    }
}
        
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
  
    for(int j=-1;j<2;j++){
        f(0,j);
    }
    cout<<ans<<endl;
      
    return 0;
}

Measured memory_bytes: 256
def selection_sort(a):
    size = len(a)
    cnt = 0
    for i in range(size):
        mini = i
        for j in range(i,size):
            if a[j] < a[mini]:
                mini = j
        if mini != i:
            a[i], a[mini] = a[mini], a[i]
            cnt += 1
    return (a, cnt)


_ = input()
l = [ int(s) for s in input().split() ]
(nl,swap) =  selection_sort(l)

print(*nl)
print(swap)


Measured memory_bytes: 5612
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

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

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

int main(){
	ios::sync_with_stdio(false);

	double vmin;
	double t, y;
	int n;

	while(scanf("%lf", &vmin)!=EOF){
		t=vmin/9.8;
		y=4.9*t*t;

		n=(int)((y+5)/5+1);

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

}

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

using namespace std;
using ll = long long;

int main() {
	int N;
	cin >> N;
	vector<int> w(N + 1);
	for (int i = 1; i <= N; ++i) { cin >> w[i]; }

	int res = 1e8;
	for (int t = 1; t < N; ++t) {
		int s1 = 0, s2 = 0;
		for (int i = 1; i <= N; ++i) {
			if (i <= t) { s1 += w[i]; }
			else { s2 += w[i]; }
		}
		res = min(res, abs(s1 - s2));
	}

	cout << res << endl;

	return 0;
}


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

using namespace std;

const double PI = 3.141592653589;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define int long long
#define ll long long
#define ll long long
#define all(c) (c).begin(),(c).end()
#define M 1000000007
#define INF LLONG_MAX
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
// Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n)
//  

const int N = 1e3 + 5;
char grid[N][N];
int ans[N][N];
int h, w, ch, cw, dh, dw;

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

bool valid(int x, int y)
{
	return (x > 0 and y > 0 and x <= h and y <= w);
}

void  bfs(int x, int y)
{
	deque<pair<int,int>> q;
	q.push_front({x, y});
	int in_queue[N][N];
	in_queue[x][y] = 1;
	memset(in_queue, 0, sizeof(in_queue));
	while(!q.empty())
	{
		x = q.front().first;
		y = q.front().second;
		in_queue[x][y] = 0;
		q.pop_front();
		for(int i=0;i<4;i++)
		{
			int X = x + dx[i], Y = y + dy[i];
            if(i > 4)
            {
                cout << "HERE\n";
                cout.flush();
            }
			if(valid(X, Y))
			{
				if(grid[X][Y] == '#') continue;
				if(ans[X][Y] == -1 || ans[X][Y] > ans[x][y])
				{
					ans[X][Y] = ans[x][y];
					if(in_queue[X][Y]) continue;
					q.push_front({X, Y});
					in_queue[X][Y] = 1;
				}

			}
		}
		// teleport to a square within square
		for(int i=-2;i<=2;i++)
		{
			for(int j=-2;j<=2;j++)
			{
				if(i == 0 and j == 0) continue;
				int X = x + i, Y = y + j;
				if(valid(X, Y) and grid[X][Y] != '#')
				{
					if(ans[X][Y] == -1 || ans[X][Y] > ans[x][y] + 1)
					{
						ans[X][Y] = ans[x][y] + 1;
						if(in_queue[X][Y]) continue;
						q.push_back({X, Y});
						in_queue[X][Y] = 1;
					}
				}
			}
		}
	}
}

int32_t main()
{
    fastio;
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
	cin >> h >> w >> ch >> cw >> dh >> dw;
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			cin >> grid[i+1][j+1];
		}
	}
	memset(ans, -1, sizeof(ans));
	ans[ch][cw] = 0;
	bfs(ch, cw);
	cout << ans[dh][dw] << "\n";	    
    return 0;
}



Measured memory_bytes: 20412
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
int imap[21][21];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, -1, 0, 1};
int n, m;

map<char, int> create_map() {
    map<char, int> m;
    m.insert({'N', 0});
    m.insert({'W', 1});
    m.insert({'S', 2});
    m.insert({'E', 3});
    return m;
}
map<char, int> dirs = create_map();

int main()
{
    int x, y, l, sum, nx, ny;
    char dir[2];
    for (; ;) {
        scanf("%d", &n);
        if (n == 0) break;
        for (int i = 0; i <= 20; i++) memset(imap[i], 0, sizeof(imap[i]));
        for (int i = 0; i < n; i++) {
            scanf("%d %d", &x, &y);
            imap[y][x] = 1;
        }
        x = y = 10;
        scanf("%d", &m);
        sum = 0;
        if (imap[10][10] == 1) { sum++; imap[10][10] = 0; }
        for (int i = 0; i < m; i++) {
            scanf("%s %d", dir, &l);
            nx = dx[dirs[dir[0]]], ny = dy[dirs[dir[0]]];
            for (int j = 0; j < l; j++) {
                x+= nx, y+=ny;
                if (imap[x][y] == 1) { sum++; imap[x][y] = 0; }
            }
        }
        (sum == n) ? printf("Yes\n") : printf("No\n");
    }
    return 0;
}



Measured memory_bytes: 2584
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn main() {
    let input = read_vec::<i32>();
    let a = input[0];
    let b = input[1];

    for i in 0..1001 {
        if (i as f32 * 0.08) as i32 == a && (i as f32 * 0.1) as i32 == b {
            println!("{}", i);
            return;
        }
    }
    println!("-1");
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define MOD 998244353
#define MAX 500000
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main()
{
  ll n, a, b, k;
  ll ans = 0;
  cin >> n >> a >> b >> k;
  COMinit();
  for (ll r = 0; r <= n; r++)
  {
    if((k-r*a)%b==0){
      ll g = (k - r * a) / b;
      ans += COM(n, r) * COM(n, g);
      ans %= MOD;
    }
  }
  cout << ans << endl;
}


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

class Main {
    static Scanner scanner = new Scanner();
    static PrintWriter out = new PrintWriter(System.out);
    static long mod = 1000000007;

    void solve() {
        String s = scanner.next();
        int n = s.length();
        int[] mod13 = new int[n + 1];
        mod13[0] = 1;
        for (int i = 1; i <= n; i++) {
            mod13[i] = mod13[i - 1] * 10 % 13;
        }

        long[][] dp = new long[n + 1][13];
        dp[0][0] = 1;
        for (int i = 1; i <= n; i++) {
            if (s.charAt(n - i) == '?') {
                for (int m = 0; m < 10; m++) {
                    for (int j = 0; j < 13; j++) {
                        int k = (m * mod13[i - 1] + j) % 13;
                        dp[i][k] = (dp[i][k] + dp[i - 1][j]) % mod;
                    }
                }
            } else {
                for (int j = 0; j < 13; j++) {
                    int k = ((s.charAt(n - i) - '0') * mod13[i - 1] + j) % 13;
                    dp[i][k] = dp[i - 1][j] % mod;
                }
            }
        }
        out.println(dp[n][5]);
    }

    public static void main(String[]$) {
        new Main().solve();
        out.close();
    }

    static class Scanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 32768);
        StringTokenizer tokenizer;

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

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

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

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

Measured memory_bytes: 36820
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] X = new int[N + 1];
		int[] SX = new int[N + 1];
		
		for (int i = 1; i <= N; i++) {
			X[i] = SX[i] = sc.nextInt();
		}
		
		Arrays.sort(SX);
		
		int mi = N / 2;
		for (int i = 1; i <= N; i++) {
			if (X[i] > SX[mi]) {
				System.out.println(SX[mi]);
			} else {
				System.out.println(SX[mi + 1]);
			}
		}
	}
}


Measured memory_bytes: 93032
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define m0(x) memset(x, 0, sizeof(x))

int A[150];

int main() {
  int n;
  scanf("%d", &n);
  rep(i, n) scanf("%d", &A[i]);
  int diff = 10000;
  for (int i = 0; i < n; i++) {
    int sum_a = 0, sum_b = 0;
    for (int j = 0; j < i; j++) sum_a += A[j];
    for (int j = i; j < n; j++) sum_b += A[j];
    if (diff > std::abs(sum_a - sum_b)) diff = std::abs(sum_a - sum_b);
  }
  printf("%d", diff);
}


Measured memory_bytes: 256
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
from heapq import heappush, heappushpop

def resolve():
    it = map(int, sys.stdin.read().split())

    T = next(it)
    ans = []
    for i in range(T):
        N = next(it)

        val = 0
        a1 = [[] for i in range(N)];
        a2 = [[] for i in range(N)];
        for i, v1, v2 in ((next(it)-1, next(it), next(it)) for i in range(N)):
            diff = v1 - v2
            if diff == 0 or i == N-1:
                val += v1
            elif diff > 0:
                a1[i].append(diff)
                val += v2
            else:
                i = N-1-i-1
                a2[i].append(-diff)
                val += v1

        for ax in (a1, a2):
            dq = []
            for i, aa in enumerate(ax):
                if not aa: continue
                for diff in aa:
                    ld = len(dq)
                    if ld <= i:
                        heappush(dq, diff)
                    else:
                        diff = heappushpop(dq, diff)

            val += sum(dq)

        ans.append(val)


    print(*ans, sep="\n")



if __name__ == "__main__":
    resolve()


Measured memory_bytes: 143528
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
answer = 0
for _ in range(N):
    temp = C
    A = list(map(int, input().split()))
    for i in range(M):
        temp += (A[i] * B[i])
    if temp > 0:
        answer += 1
print(answer)


Measured memory_bytes: 3060
#include<stdio.h>

int main(void)
{

  int n,a,b;
  int price1,price2;
  
  scanf("%d%d%d",&n,&a,&b);
  price1=a*n;
  price2=b;
  if(price1<price2)
    printf("%d\n",price1);
  else
    printf("%d\n",price2);
  
  return 0;
}


Measured memory_bytes: 128
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	
	public static int[][] move_dir = new int[][]{{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
	
	public static boolean ok(int x, int y, int w, int h){
		if(x < 0 || x >= w || y < 0 || y >= h){
			return false;
		}
		return true;
	}
	
	public static int dps(int x, int y, int w, int h, boolean[][] map, boolean[][] visited){
		if(!ok(x, y, w, h) || !map[y][x] || visited[y][x]){
			return 0;
		}
		
		visited[y][x] = true;
		int max = 0;
		for(int[] move : move_dir){
			final int nx = x + move[0];
			final int ny = y + move[1];
			
			if(!ok(nx, ny, w, h)){
				continue;
			}else if(!map[ny][nx]){
				continue;
			}else if(visited[ny][nx]){
				continue;
			}
			
			max = Math.max(max, dps(nx, ny, w, h, map, visited));
		}
		visited[y][x] = false;
		
		return max + 1;
	}
	
	public static int check(int w, int h, boolean[][] map){
		int max = 0;
		
		boolean[][] visited = new boolean[h][w];
		for(int y = 0; y < h; y++){
			for(int x = 0; x < w; x++){
				if(!map[y][x]){
					continue;
				}
				
				max = Math.max(max, dps(x, y, w, h, map, visited));	
			}
		}
		
		return max;
	}

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

		while(true){
			final int m = sc.nextInt();
			final int n = sc.nextInt();
			
			if(m == 0 && n == 0){
				break;
			}
			
			boolean[][] map = new boolean[n][m];
			
			for(int i = 0; i < n; i++){
				for(int j = 0; j < m; j++){
					map[i][j] = sc.nextInt() == 1;
				}
			}
			
			System.out.println(check(m, n, map));
		}
	}

}

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

using namespace std;

int maxList(vector<int> vec) {
    vector<int> backUp = vec;
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());
    int ans = vec.at(0);
    vec = backUp;
    return ans;
}

int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; ++i) {
        cin >> h.at(i);
    }
    reverse(h.begin(), h.end());
    h.push_back(-1);
    vector<int> ans = {};
    int count = 0;
    for (int j = 0; j < n; ++j) {
        if (h.at(j) <= h.at(j + 1)) {
            count++;
            ans.push_back(count);
        } else {
            count = 0;
            ans.push_back(count);
        }
    }
    cout << maxList(ans) << endl;
}


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

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

int N;
long long a[100010][3];
// DPテーブル
long long dp[100010][3];

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 3; j++) cin >> a[i][j];
  }

  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 3; ++j) {
      for (int k = 0; k < 3; ++k) {
        if (j == k) continue;
        chmax(dp[i + 1][k], dp[i][j] + a[i][k]);
      }
    }
  }

  long long ans = 0;
  for (int j = 0; j < 3; ++j) chmax(ans, dp[N][j]);
  printf("%lld", ans);
}


Measured memory_bytes: 4992
n = int(input())
d, x = map(int, input().split())
a = list(map(int, [input() for i in range(n)]))

ans = 0

for t in range(1, d+1):
    for ai in a:
        if ai == 1:
            ans += 1
        elif t == 1 or t%ai==1:
            ans += 1
print(ans+x)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,s=0,c=0;
    cin >> n>> m;
    int a[n+2];
    for(int i=0; i<n; i++) cin >> a[i];
 
    
    for(int i=0; i<n; i++) s += a[i];

    for(int i=0; i<n; i++) 
        if(a[i]*4*m >= s) 
            c++;
 
    if(c>=m) cout << "Yes" << endl;
    else cout << "No" << endl;
 
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

N = ii()
ans = 0
for i in range(1, N+1):
    ans += (i * (N//i) + i) * (N//i) // 2

print(ans)

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

int main(){
  int N,Y;cin>>N>>Y;
  int t=1,m,g,s;
  for(int i=0;i<=N;i++){
    for(int j=0;(i+j)<=N;j++){
      for(int k=0;k+i+j<=N;k++){
        if(i*10000+j*5000+k*1000==Y&&i+j+k==N){
          t=0;
          m=i,g=j,s=k;
          break;
        }
      }
    }
  }
  if(t==0){
    cout<<m<<" "<<g<<" "<<s<<endl;
  }else{
    cout<<-1<<" "<<-1<<" "<<-1<<endl;
  }
}


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

int main(){
  int w,h,n;cin>>w>>h>>n;
  int s=0,t=w,u=0,v=h;
  for(int i=0;i<n;i++){
    int x,y,a;cin>>x>>y>>a;
    if(a==1)s=max(x,s);
    else if(a==2)t=min(t,x);
    else if(a==3)u=max(u,y);
    else v=min(v,y);
  }
  if(t-s<=0||v-u<=0)cout<<0<<endl;
  else cout<<(t-s)*(v-u)<<endl;
}


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

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

  string str1, str2 ;

  if(str.size() % 2 == 0)
  {
    for(int i = 0 ; i < str.size() / 2 ; i++)
    {
      str1 += str.at(i) ;
    }

    for(int i = str.size() / 2 ; i < str.size(); i++)
    {
      str2 += str.at(i) ;
    }
  }
  else if(str.size() % 2 != 0)
  {
    for(int i = 0 ; i < str.size() / 2 ; i++)
    {
      str1 += str.at(i) ;
    }
    for(int i = str.size() / 2 + 1 ; i < str.size() ; i++)
    {
      str2 += str.at(i) ;
    }
  }
  
  int count = 0 ;
  int j = str1.size() - 1 ;
  for(int i = 0 ; i < str1.size() ; i++)
  {
    //cout << i << " " << j << endl ;
    if(str1.at(i) != str2.at(j))
    {
      count++ ;
    }
    j-- ;
  }

  cout << count << endl ;
}


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

int main()
{
	int p1,p2,p3;
	int j1,j2;
	int min=0;

	cin >> p1 >> p2 >> p3 >> j1 >> j2;

	min = p1+j1;

	if(min > p1+j2)
		min = p1+j2;

	if(min > p2+j1)
		min = p2+j1;

	if(min > p2+j2)
		min = p2+j2;

	if(min > p3+j1)
		min = p3+j1;

	if(min > p3+j2)
		min = p3+j2;

	cout << min-50 << endl;

	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <string>

int main()
{
  int n, l;
  std::cin >> n >> l;
  std::string s[n];
  for ( int i = 0; i < n; i++ ) std::cin >> s[i];

  std::sort(s, s+n);
  for ( int i = 0; i < n; i++ ) std::cout << s[i];
  std::cout << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int q;
	cin >> q;
	list<pair<int, char>> ss;
	REP(kurikaesu, q) {
		int p, n;
		char c;
		cin >> p>> c>> n;
		if (ss.empty())
			ss.insert(ss.begin(), {n,c});
		else {
			auto it = ss.begin();
			while (1) {
				if (it == ss.end()) {
					ss.push_back({ n,c });
					break;
				}
				if (p < it->first) {
					if (p == 0) {
						ss.insert(it, {n,c});
					}
					else {
						if (it->second == c) {
							it->first += n;
						}
						else {
							it->first -= p;
							ss.insert(it, { n,c });
							ss.insert(it, { p,c });
						}
					}
					break;
				}
				else {
					p -= it->first;
					it++;
				}
			}
		}
		list<pair<int, char>> ss2=ss;
		auto lit = ss2.begin();
		auto rit = ss2.end();
		rit--;
		while (1) {
			if (lit->first == 0 && rit->first == 0) {
				cout << "Yes" << endl;
				break;
			}
			if (lit->second == rit->second) {
				cout << "No" << endl;
				break;
			}
			else {
				int mi = min(lit->first, rit->first);
				lit->first -= mi;
				rit->first -= mi;
				if (lit->first == 0)
					lit++;
				if (rit->first == 0)
					rit--;
			}
		}
	}
}

Measured memory_bytes: 3224
import sys
h=['light ','']
for e in sys.stdin:
 e=float(e)
 for i in range(7):
  if[81,69,60,57,54,51,0][i]<e:
   print([h[e>91]+'heavy',h[e>75]+'middle',h[e>64]+'welter','light','feather','bantam',h[e>48]+'fly'][i]);break


Measured memory_bytes: 5588
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	int a, b, c, d;
	int e, f;
	cin >> a >> b >> c >> d;
	if (a > b) {
		e = b;
	}
	else {
		e = a;
	}
	if (c > d) {
		f = d;
	}
	else {
		f = c;
	}
	cout << e + f << endl;
	return 0;
}

Measured memory_bytes: 256
/*  TAHMID RAHMAN
    DAMIAN FOREVER
     MATH LOVER
    NEVER GIVE UP
*/
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define pb push_back
#define fi first
#define se second
#define in insert
#define mp make_pair
#define GCD(a,b) __gcd(a,b);
#define endl "\n"
#define FRU freopen("out.txt","w",stdout)
#define FRO freopen("in.txt","r",stdin)
#define INFLL 9223372036854775807
#define debug 0
#define MAXN   100001
#define ar array
const int mxN=2e5;
const int MOD=1e9+7;
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
//Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
int main()
{
    fastio;
    ll n,d,i,c=0;
    cin>>n>>d;
    for(i=0;i<n;i++)
    {
        double x,y;
        cin>>x>>y;
        if(sqrt(x*x+y*y)<=d)
            c++;
    }
    cout<<c<<endl;
}


Measured memory_bytes: 3820
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a);i>int(b);--i)
#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define show(v) rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl;
#define MOD 1000000007
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define SZ(x) ((int)(x).size())
#define sum(v,i) accumulate(all(v),i)
//#define int long long
using ll = long long;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
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; }
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }//最大公約数
int lcm(int a, int b) { return a * b / gcd(a, b); }	//最小公倍数
//template <typename... Args>void IN(Args& ... args) {cin >>args;IN(args...);return;} //まとめて入力　IN(a,b,c,d...)

void Main() {
	string s; cin >> s;
	int n = 0;
	if (s == "SUN")n = 7;
	else if (s == "MON")n = 6;
	else if (s == "TUE")n = 5;
	else if (s == "WED")n = 4;
	else if (s == "THU")n = 3;
	else if (s == "FRI")n = 2;
	else if (s == "SAT")n = 1;
	cout << n;





}

signed main() {
	Main();

	return 0;
}


Measured memory_bytes: 256
#include <iostream>




int main(void) {
  int a, n;
  int ans_min, ans_max;
  long int ans_sum;
  char deli = ' ';

  ans_min = 1000000;
  ans_max = -1000000;
  ans_sum = 0;

  std::cin >> n;
  for (int i = 0; i < n; i ++) {
    std::cin >> a;
    ans_sum += a;
    if (ans_min > a) {
      ans_min = a;
    }
    if (ans_max < a) {
      ans_max = a;
    }
  }

  std::cout << ans_min << deli << ans_max << deli << ans_sum << std::endl;


  return 0;
}



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

int main(){
  long long int a, b, k;
  cin >> a >> b >> k;
  
  if(a>k){
    cout << a-k << " " << b;
  }else if(a<=k&&k-a<b){
    cout << 0 << " " << b-(k-a);
  }else{
    cout << 0 << " " << 0;
  }
}
  

Measured memory_bytes: 256
n=int(input())
arr=list(map(int,input().split()))
inf=int(1e9+5)
dp=[inf]*n
dp[0]=0
for i in range(n):
  for j in (i+1,i+2):
    if(j<n):
      dp[j]=min(dp[j],dp[i]+abs(arr[i]-arr[j]))
print(dp[n-1])


Measured memory_bytes: 13928
#include<stdio.h>
#include<math.h>
int main(){
    double x1, x2, y1, y2;
    while((scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2)) == 4){
        printf("%lf\n", sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)));
    }
return 0;
}



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

using namespace std;

int main(){
	int n;
	scanf("%d", &n);
	int arr[n + 2];
	for(int i = 1; i <= n; i++){
		scanf("%d", &arr[i]);
	}
	int gcl[n + 2], gcr[n + 2];
	gcl[1] = arr[1];
	gcr[n] = arr[n];
	for(int i = 2; i <= n; i++){
		gcl[i] = __gcd(gcl[i - 1], arr[i]);
	}
	for(int i = n - 1; i >= 1; i--){
		gcr[i] = __gcd(gcr[i + 1], arr[i]);
	}
	int resp = max(gcr[2], gcl[n - 1]);
	for(int i = 2; i <= n - 1; i++){
		resp = max(resp, __gcd(gcl[i -1], gcr[i + 1]));
	}
	printf("%d\n", resp);
	return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define PI 3.14159265358979323
//void quick(int *,long long,long long);

int main(){
     
	float a,max,min;
	scanf("%f",&a);
	max=min=a;
	while(scanf("%f",&a)!=EOF){
		if(a>max)
			max=a;
		if(a<min)
			min=a;
	}
	printf("%.1f\n",max-min);
	return 0;
}

Measured memory_bytes: 648
#include <stdio.h>

bool b[11][100001], c[100001];
int p[100001];

int find(int x)
{
	if (p[x] != x) p[x] = find(p[x]);
	return p[x];
}

int main()
{
	int K;
	scanf("%d", &K);
	for (int i=0;i<K;i++) p[i] = i;
	for (int i=0;i<K;i++) p[find(i)] = find((i*10)%K);

	b[0][0] = 1;
	for (int i=0;;i++){
		for (int j=0;j<K;j++) c[j] = 0;
		for (int j=0;j<K;j++) if (b[i%11][j]) c[find(j)] = 1;
		for (int j=0;j<K;j++) if (c[find(j)]){
			b[i%11][j] = 1;
			for (int v=1;v<10;v++){
				b[(i+v)%11][(j*10+v)%K] = 1;
			}
		}
		if (i && b[i%11][0]){ printf("%d\n", i); break; }
		for (int j=0;j<K;j++) b[i%11][j] = 0;
	}

	return 0;
}

Measured memory_bytes: 1664
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)
#define Yes(condition) if(condition){ cout << "Yes" << '\n'; }else{ cout << "No" << '\n'; }
#define YES(condition) if(condition){ cout << "YES" << '\n'; }else{ cout << "NO" << '\n'; }
#define yes(condition) if(condition){ cout << "yes" << '\n'; }else{ cout << "no" << '\n'; }





int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    deque<ll> que;
    que.push_back(a[0]);
    ll i1 = 1, i2 = (ll)a.size() - 1;
    REP(i, (n - 1) / 2){
        if(i % 2 == 0){
            que.push_front(a[i2]);
            i2--;
            que.push_back(a[i2]);
            i2--;
        }
        else if(i % 2 == 1){
            que.push_front(a[i1]);
            i1++;
            que.push_back(a[i1]);
            i1++;
        }
    }
    if(n % 2 == 0){
        if(abs(que.front() - a[i1]) > abs(que.back() - a[i1])){
            que.push_front(a[i1]);
        }
        else{
            que.push_back(a[i1]);
        }
    }
    ll ans = 0, t1 = que.front(); que.pop_front();
    REP(i, n - 1){
        ll t2 = que.front(); que.pop_front();
        ans += abs(t2 - t1);
        t1 = t2;
    }
    
    deque<ll> que2;
    que2.push_back(a[n - 1]);
    i1 = 0; i2 = n - 2;
    REP(i, (n - 1) / 2){
        if(i % 2 == 0){
            que2.push_front(a[i1]);
            i1++;
            que2.push_back(a[i1]);
            i1++;
        }
        else if(i % 2 == 1){
            que2.push_front(a[i2]);
            i2--;
            que2.push_back(a[i2]);
            i2--;
        }
    }
    if(n % 2 == 0){
        if(abs(que.front() - a[i1]) > abs(que.back() - a[i1])){
            que2.push_front(a[i1]);
        }
        else{
            que2.push_back(a[i1]);
        }
    }
    ll sum = 0; t1 = que2.front(); que2.pop_front();
    REP(i, n - 1){
        ll t2 = que2.front(); que2.pop_front();
        sum += abs(t2 - t1);
        t1 = t2;
    }
    cout << max(ans, sum) << endl;
}


Measured memory_bytes: 1920
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
long h,w,a[100][100],b[100][100],i,j,n,f;
char c;
while(cin>>h){
cin>>w;
if(h==0)break;
for(i=0;i<h;i++){
for(j=0;j<w;j++){
cin>>c;
if(c=='@')a[i][j]=1;
else if(c=='#')a[i][j]=2;
else a[i][j]=3;
b[i][j]=0;
}
}
n=1;
for(;;){
f=0;
for(i=0;i<h;i++){
for(j=0;j<w;j++){
if(b[i][j]==0){b[i][j]=n++;f=1;break;}
}
if(f==1)break;
}
if(f==0)break;
for(;;){
f=0;
for(i=0;i<h;i++){
for(j=0;j<w;j++){
if(b[i][j]>0){
if(i+1<h&&b[i+1][j]==0&&a[i+1][j]==a[i][j]){b[i+1][j]=b[i][j];f=1;}
if(0<i  &&b[i-1][j]==0&&a[i-1][j]==a[i][j]){b[i-1][j]=b[i][j];f=1;}
if(j+1<w&&b[i][j+1]==0&&a[i][j+1]==a[i][j]){b[i][j+1]=b[i][j];f=1;}
if(0<j  &&b[i][j-1]==0&&a[i][j-1]==a[i][j]){b[i][j-1]=b[i][j];f=1;}
}
}
}
if(f==0)break;

}
}
cout<<n-1<<endl;
}
return 0;
}

Measured memory_bytes: 1316
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int
 
#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))
 
typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;
 
typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;
 
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;
 
namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    int T, P, R;
    while(cin >> T >> P >> R, T || P || R) {
        int info[60][15] = {};
        int rec[60] = {};
        int cor[60] = {};
        rep(i,0,R) {
            int team, p, time; string mes;
            cin >> team >> p >> time >> mes;
            if(mes == "WRONG") info[team][p]++;
            else {
                rec[team] += time + info[team][p] * 1200;
                cor[team]--;
            }
        }
        vector< pair<int ,pii> > v;
        repq(i,1,T) v.pb(make_pair(cor[i], pii(rec[i], i)));
        sort(v.begin(), v.end());
        rep(i,0,T) printf("%lld %lld %lld\n", v[i].sc.sc, -v[i].fr, v[i].sc.fr);
    }
    return 0;
}

Measured memory_bytes: 3300
using System.Collections.Generic;
using System.Linq;
using System;
class Program
{
    static void Main()
    {
        string[] a = Console.ReadLine().Split(' ');
        int[] b = new int[2];
        b[0] = int.Parse(a[0]);//Vert
        b[1] = int.Parse(a[1]);//Line

        List<int>[] vertList = new List<int>[b[0]];
        for (int i = 0; i < b[0]; i++){
            vertList[i] = new List<int>();
        }

        for (int i = 0; i < b[1]; i++){
            string[] c = Console.ReadLine().Split(' ');
            int[] d = new int[2];
            d[0] = int.Parse(c[0]) - 1;
            d[1] = int.Parse(c[1]) - 1;
            vertList[d[0]].Add(d[1]);
            vertList[d[1]].Add(d[0]);
        }

        int bridgeCount = 0;
        bool flag = true;
        while (flag)
        {
            flag = false;
            for (int i = 0; i < b[0]; i++)
            {
                if (vertList[i].Count() == 1)
                {
                    bridgeCount++;
                    int dest = vertList[i][0];
                    vertList[dest].Remove(i);
                    vertList[i].RemoveAt(0);
                    flag = true;
                }
            }
        }

        Console.WriteLine(bridgeCount.ToString());
    }
}

Measured memory_bytes: 13276
use std::io;


fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str
}


fn is_digit(c : char) -> bool {
    return '0' <= c && c <= '9';
}

fn main(){

    let ln1 = read_line();
    let mut lnsw = ln1.split_whitespace(); 

    let a = lnsw.next().unwrap().parse::<i32>().unwrap();
    lnsw.next().unwrap().parse::<i32>().unwrap();
    
    let ln2 = read_line();

    let mut valid : bool = true;
    
    for x in 0..(ln2.len()-1) {
        let c : char = ln2.chars().nth(x).unwrap();
        let ix : i32 = x as i32;
        if 0 <= ix && ix < a {
            if !is_digit(c) {
                valid = false;
            }
        }
        else if ix == a {
            if c != '-' {
                valid = false;
            }
        }
        else {
            if !is_digit(c) {
                valid = false;
            }
        }
    }

    if valid {
        println!("Yes");
    }
    else{
        println!("No");
    }
    
}


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

int main() {
	long long n,m,i,j,k,ans,cur,res,l,r;
	cin >> n;
	vector<long long> a(n),b(n);
	
	for(i=0; i<n; i++){
		cin >> a[i] >> b[i];
	}
	
	sort(a.begin(),a.end());
	if(n%2==0){
		l= a[(n-1)/2]+a[n/2];
	}else{
		l=a[n/2]*2;
	}
	
	sort(b.begin(),b.end());
	if(n%2==0){
		r=b[(n-1)/2]+b[n/2];
	}else{
		r=b[n/2]*2;
	}
	
	if(n%2==0){
		cout << r-l+1;
	}else{
		cout << (r-l)/2+1 << endl;
	}
	
	return 0;
}


Measured memory_bytes: 6428
#include <bits/stdc++.h>
#include <math.h>
#include<cmath>
 #include <sstream> // std::stringstream
 #include <istream> // std::getline
using namespace std;

int main() {
    int a, p, ans;
    cin >> a >> p;
    ans = (p+3*a)/2;
    cout << ans << endl;
    }


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String s1 = sc.next();
		String s2 = sc.next();

		int length = s1.length();
		String s3 = s2.substring(0, length);

		//System.out.println(s3);

		if(s1.equals(s3)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		sc.close();

	}

}


Measured memory_bytes: 35704
n,m=map(int, input().split())
a=[]

for i in range(n):
    a.append(list(map(int, input().split() ) ))
    a[i]+=[sum(a[i])]
    print(*a[i])
    #print(i)

b=[]
for j in range(m+1):
    tmp=0
    for l in range(n):
        tmp=tmp+a[l][j]
    b.append(tmp)
    

print(" ".join(list(map(str, b))))
    


Measured memory_bytes: 5688
// E.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

typedef long long LL;
typedef pair<int, int> II;

int main(int argc, char* argv[]) {
	cout.precision(20);
#ifdef _MSC_VER
	while (true)
#endif
	{
		int r = -1, c, k;
		cin >> r >> c >> k;
		if (r < 0) return 0;
		map<II, LL> m;
		for (LL i = 0; i < k; ++i) {
			int a, b, c;
			cin >> a >> b >> c;
			m[II(a, b)] = c;
		}
		vector<vector<vector<LL>>> dp(2, vector<vector<LL>>(4, vector<LL>(c + 1)));
		for (int i = 1; i <= r; ++i) {
			int curr = i & 1, prev = curr ^ 1;
			for (int j = 1; j <= c; ++j) {
				for (int k = 0; k <= 3; ++k) {
					dp[curr][k][j] = dp[curr][k][j - 1];
				}
				LL& zero = dp[curr][0][j];
				for (int k = 0; k <= 3; ++k) {
					zero = max(zero, dp[prev][k][j]);
				}
				II key(i, j);
				if (m.find(key) != m.end()) {
					for (int k = 3; k > 0; --k) {
						dp[curr][k][j] = max(dp[curr][k][j], dp[curr][k - 1][j] + m[II(i, j)]);
					}
				}
			}
		}
		LL ans = 0;
		for (int k = 0; k <= 3; ++k) {
			ans = max(ans, dp[r & 1][k][c]);
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 16404
N = int(input())
M = 10**6 + 1

counts = [0 for _ in range(M)]
for a in map(int, input().split()):
  counts[a] += 1

integers = [0,0] + [1 for _ in range(M-2)]
max_count = 0
for i in range(M):
  if integers[i] >= 1:
    count = 0
    for j in range(i,M,i):
      count += counts[j]
      integers[j] = 0
    max_count = max(max_count,count)

if max_count == N:
  answer = 'not coprime'
elif max_count >= 2:
  answer = 'setwise coprime'
else:
  answer = 'pairwise coprime'

print(answer)

Measured memory_bytes: 206108
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


int main(){
  int t,s=0;

  for(int i=0;i<3;i++){
    s*=10;
    cin >> t;
    s += t;
  }
  
  if(s%4 == 0){
    puts("YES");
  }else{
    puts("NO");
  }
  
  return 0;
}


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

namespace AtCoderExamCS
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();

            if (S == "ABC")
                Console.WriteLine("ARC");
            else
                Console.WriteLine("ABC");
        }
    }
}


Measured memory_bytes: 25680
#include <iostream>
#include <fstream>
#include <sstream>

#include <vector>
#include <set>
#include <bitset>
#include <map>
#include <deque>
#include <string>

#include <algorithm>
#include <numeric>

#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>

#define pb push_back
#define pbk pop_back
#define mp make_pair
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define foreach(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); ++i)
#define len(a) ((int) (a).size())

#ifdef CUTEBMAING
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

using namespace std;

typedef long long int64;
typedef long double ld;
typedef unsigned long long lint;

const int inf = (1 << 30) - 1;
const int64 linf = (1ll << 62) - 1;
const int N = 3001;

int n, k;
vector<int> g[N];
int dp[N][N];
int sz[N], h[N];

inline void dfs(int v, int p = -1) {
    sz[v] = 1;
    h[v] = 0;
    for (int to : g[v]) {
        if (to == p) {
            continue;
        }
        dfs(to, v);
        sz[v] += sz[to];
        h[v] = max(h[v], h[to] + 1);
    }
    if (p != -1 && len(g[v]) == 1) {
        for (int i = 1; i <= k; i++) {
            dp[v][i] = 0;
        }
        dp[v][0] = sz[v];
        return ;
    }
    dp[v][0] = sz[v];
    for (int i = 0; i <= k; i++) {
        int sum = 0, mn = inf;
        int mx = min(k - i, i);
        for (int to : g[v]) {
            if (to == p) {
                continue;
            }
            sum += dp[to][mx - 1 + 1];
            mn = min(mn, dp[to][i - 1 + 1] - dp[to][mx - 1 + 1]);
        }
        dp[v][i + 1] = min(dp[v][i], sum + mn);
    }
}

int main() {
#ifdef XCODE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cin >> n >> k;
    for (int i = 0; i < n - 1; i++) {
        int a, b; scanf("%d%d", &a, &b), a--, b--;
        g[a].pb(b), g[b].pb(a);
    }
    int ans = inf;
    for (int it = 0; it < 50; it++) {
        int root = rand() % n;
        dfs(root);
        ans = min(ans, dp[root][k + 1]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 24064
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int n, m;
	
	int a, b, c, d;
	
	string s, t;
	
	int N;
	
	cin>>N;
	
	cout<<(N-2)*180<<endl;
	
	return 0;
}

Measured memory_bytes: 256
s = input()
frag = 0
for i in range(len(s)):
    if(i % 2 == 0):
        if(s[i] == 'L'):
            frag = 1
    else:
        if(s[i] == 'R'):
            frag = 1
if(frag == 0):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
import fractions
N = int(input())
A = list(map(int, input().split()))

DP_first = [0] * N
DP_last = [0] * N

DP_first[0] = A[0]
DP_last[0] = A[-1]

for i in range(1, N):
    DP_first[i] = fractions.gcd(DP_first[i-1], A[i])
    DP_last[i] = fractions.gcd(DP_last[i-1], A[-1-i])

ans = max(DP_first[N-2], DP_last[N-2])
for i in range(1, N-1):
    ans = max(ans, fractions.gcd(DP_first[i-1], DP_last[N-2-i]))
print(ans)


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

using namespace std;

int main()
{
	int a, b, c, d, e, x, y;
	cin >> x >> y;
	//xは頭数、yは足
	a = x * 2;
	b = x * 4;
	c = y % 2;
	if (c == 0) d = 0;
	else d = 1;
	if (d == 1) cout << "No";
	else {
		if (a <= y) {
		if (b >= y) cout << "Yes";
		else cout << "No";
	}
	else cout << "No";
	}
	return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
#include <stack>
#include<set>
#include<cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cstdio>
#include <string.h>
#include<iterator>
#include <map>
using namespace std;
// bool cmp(long long a, long long b){
//     return a > b;
// }
int  arr[3500];
string str[10];
char str_arr[5][5];
int matr[25][25], saved_matr[5][5], ish_matr[5][5];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    long long t, ch, i, curr, p = 1, x, y, weight, j, k = 0, n, m = 1, ch1, ans = 0;
    long long a, b;
    int fl, fl1, fl2, fl3;
    string s, s1;
//    cin >> t;
    long long f, size_f, size_s, weight1, weight2;
    long long sum, k_min, k_max;
//    for (auto test_case = 0; test_case < t; test_case++) {
//    }
    long long d;
    cin >> n;
    long long* arr = new long long[n];
    sum = 0;
    for (i = 0; i < n; i++){
        cin >> arr[i];
        sum += arr[i];
    }
    ans = 0;
    for (i = 0; i < n; i++){
        sum = sum - arr[i];
        ch = sum;
        ch = ch % ((long long) 1e9 + 7);
        ch = ch * arr[i];
        ch = ch % ((long long) 1e9 + 7);
        ans += ch;
        ans = ans % ((long long) 1e9 + 7);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 5148
int main(void) {
		int d;
		scanf("%d",&d);

		int i;
		unsigned long long int num = 0;
		for ( i = 1; i < d+1; i++) {
			if (i % 3 == 0 && i % 5 == 0);
			else if (i % 3 == 0);
			else if (i % 5 == 0);
			else num = num+i;
		}
		printf("%lld\n", num);
}

Measured memory_bytes: 1708
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;

int main()
{
    string str;
    size_t q;
    cin >> str >> q;

    for (size_t i = 0; i < q; i++) {
        string op;
        size_t a, b;
        cin >> op >> a >> b;

        if (op == "print") {
            cout << str.substr(a, b - a + 1) + "\n";

        } else if (op == "reverse") {
            reverse(str.begin() + a, str.begin() + b + 1);

        } else {
            string p;
            cin >> p;

            str.replace(a, p.size(), p);
        }
    }
}



Measured memory_bytes: 3200