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

#define For(i, l, r) for (register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for (register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Rep(i, r) for (register int i = (0), i##end = (int)(r); i < i##end; ++i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl

using namespace std;

template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, T b) { return b > a ? a = b, 1 : 0; }

inline int read() {
	int x(0), sgn(1); char ch(getchar());
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') sgn = -1;
	for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
	return x * sgn;
}

void File() {
#ifdef zjp_shadow
	freopen ("C.in", "r", stdin);
	freopen ("C.out", "w", stdout);
#endif
}

const int N = 110;

int n, dp[N][N]; bool app[N][N];

int main () {

	File();

	n = read();

	app[0][0] = true;
	For (i, 1, n) {
		int s = read();
		Rep (j, 10) if (app[i - 1][j]) {
			app[i][(j + s) % 10] = true;
			chkmax(dp[i][(j + s) % 10], dp[i - 1][j] + s);

			app[i][j] = true;
			chkmax(dp[i][j], dp[i - 1][j]);
		}
	}

	int ans = 0;
	For (i, 1, 9)
		chkmax(ans, dp[n][i]);
	printf ("%d\n", ans);

    return 0;

}

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

int main() {
    int a,b,c,d,e;
    cin >>a >> b;
      c = a+b;
      d=a-b;
      e = a*b;
    int ans = max (c,d);
    int ma = max (ans,e);
    cout << ma << endl;
    }




Measured memory_bytes: 256
A="1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"
A=list(map(int, A.split(", ")))
K=int(input())
print(A[K-1])

Measured memory_bytes: 2940
#include <bits/stdc++.h>
typedef long long ll;
#define MOD 1000000007
#define INF -99999999 
using namespace std;

int main()
{
    int N; cin >> N;
    for (int i = 0; i < 50000; i++)
    {
        if((int)(1.08*i) == N){
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl;
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0;
#define HERE cout<<"    "<<"HERE"<<en

int main(){
  int n,m;
  cin>>n>>m;
  
  int clear=0;
  vector<int> v;
  for(int i=0; i<m; i++){
    int a,b;
    cin>>a>>b;
    if(a>=n) {
      clear++;
      continue;
    }
    v.push_back(n-a);
  }
  
  int ans=0;
  sort(v.begin(), v.end());
  for(int i=0; i<m-1-clear; i++){
    ans+=v[i];
  }
  
  cout<<ans<<en
}




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

int main()
{
    vector<int> num;
    
    for(int i = 0; i < 4; i++)
    {
        char tmp;
        tmp = getchar();
        int tmpn = tmp - '0';
        num.push_back(tmpn);
    }

    int sum = num.at(0);
    int judge = 10000;
    int bits;
    for(bits = 0; bits < (1 << 3); bits++)
    {
        for(int i = 0; i < 3; i++)
        {
            if(bits & (1 << i))
            {
                sum += num.at(i+1);
                //cout << sum << endl;
            }
            else 
            {
                sum -= num.at(i+1);
                //cout << sum << endl;
            }
        }
        //cout << sum << endl;

        if(sum == 7)
        {
            judge = bits;
            break;
        }
        sum = num.at(0);
    }
    //cout << judge << endl;

    for(int i = 0; i < 7; i++)
    {
        if(i % 2 == 0)
        {
            cout << num.at(i/2);
        }
        else
        {
            if(bits & (1 << i/2))
            {
                cout << "+";
            }
            else 
            {
                cout << "-";
            }
        }
        
    }
    cout << "=7" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>

using namespace std;
using ll = long long;

int main()
{
    int n;
    cin >> n;
    vector<string> s(n);
    map<char, int> t;
    for(int i = 0; i < n; i++){
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
    }
    int ans = 0;
    for(int i = 'a'-'0'; i <= 'z'-'0'; i++){
        char now = i + '0';
        //cout << "now = " << now << endl;
        int num = 0;
        for(int j = 0; j < n; j++){
            int tmp = 0;
            for(int k = 0; k < s[j].size(); k++){
                if(s[j][k] == now){
                    tmp++;
                }
            }
            if(tmp == 0){
                num = 0;
                break;
            }
            if(j == 0){
                num = tmp;
            }else{
                num = min(num, tmp);
            }
        }
        t[now] += num;
    }

    for(int i = 'a'-'0'; i <= 'z'-'0'; i++){
        //cout << "t[i]: " << t[i+'0'] << endl;
        for(int j = 0; j < t[i+'0']; j++){
            char now = i + '0';
            cout << now;
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;

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

	vector<ll> ans;
	vector<ll>::iterator it;

	for (int i = 0; i < N; i++) {
		cin >> tmp;
		if (i % 2 == 0) {
			ans.push_back(tmp);
		}
		else {
			it = ans.begin();
			it = ans.insert(it, tmp);
		}
	}

	if (N % 2 == 0) {
		for (ll i = 0; i < N; i++) {
			cout << ans[i] << " ";
		}
	}
	else
	{
		for (ll i = N - 1; i >= 0; i--) {
			cout << ans[i] << " ";
		}

	}
	return 0;
}

Measured memory_bytes: 5296
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.trim()
        .split_whitespace()
        .map(|e| e.trim().parse().ok().unwrap())
        .collect()
}

fn main() {
    let n: usize = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).ok();
        buf.trim().parse().ok().unwrap()
    };

    let a: Vec<Vec<usize>> = (0..2).map(|_| read_vec()).collect();

    let max: usize = (0..n)
        .map(|e| a[0][0..e + 1].iter().sum::<usize>() + a[1][e..].iter().sum::<usize>())
        .max()
        .unwrap();
    println!("{}", max);
}


Measured memory_bytes: 4352
import sys
def judge(s):
    if len(s)%2 == 1:
        return False
    half = len(s)//2
    for i in range(half):
        if s[i] != s[i+half]:
            return False
    return True

S = input()
for i in range(1,len(S)):
    if judge(S[:-i]):
        print(len(S[:-i]))
        sys.exit()
print(0)


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

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

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

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N; 
  cin >> N;

  vector<int> B(N-1);
  REP(i, N-1) cin >> B[i];

  int ans = B[0]+B[N-2];
  REP(i, N-2) ans += min(B[i], B[i+1]);

  cout << ans << "\n";

  return 0;
}

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

int main() {
  int a, b, x;
  cin >> a >> b >> x;
  bool flag = true;
  if (a > x) {
    flag = false;
  }
  if ((a+b) <= x) {
    flag = false;
  }

  if (flag) {
    cout << "YES";
  }
  else {
    cout << "NO";
  }
  cout << endl;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD 1000000007
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N;
i64 C[55][55];
i64 dp[55][55][55]; // # unused / current + / current -

int main()
{
	scanf("%d", &N);

	C[0][0] = 1;
	for (int i = 1; i <= 50; ++i) {
		C[i][0] = 1;
		for (int j = 1; j <= 50; ++j) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;
	}

	dp[0][1][0] = 1;

	for (int i = 0; i < N; ++i) {
		for (int j = 0; j <= N; ++j) {
			for (int k = 0; k <= N; ++k) {
				//if (dp[i][j][k] > 0) printf("%d %d %d: %lld\n", i, j, k, dp[i][j][k]);
				if (i + j + k > N || j + k == 0) continue;
				for (int j2 = 0; j2 <= N; ++j2) {
					for (int k2 = 0; k2 <= N; ++k2) {
						if (j2 - k2 > j || k2 - j2 > k) continue;

						int p = j - j2 + k2;
						int q = j + k - p;

						ADD(dp[i + p + q][j2][k2], dp[i][j][k] * C[N - i][p] % MOD * C[N - i - p][q]);
					}
				}
			}
		}
	}

	printf("%lld\n", dp[N][0][0]);
	return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <numeric>
#include <vector>
#include <algorithm>
#include <map>
#include<queue>
#include <sstream>
#include <set>
typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}
using namespace std;
int main(){
    ll N,Q;
    string S;
    cin >> N >> Q >> S;

    vector<ll> AC(N);
    AC[0]=0;    
    for(ll i=1;i<=N;i++){
        if(S[i-1]=='A'&&S[i]=='C') AC[i] = AC[i-1]+1;
        else AC[i] = AC[i-1];

        
    }

    REP(i,Q){
        int a,b;
        cin >> a >> b;

        cout << AC[b-1] - AC[a-1] << endl;
    }
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>

int main() {
	int N;
	std::vector<int> v, c;
	std::cin >> N;
	int M = 0;
	for (int i = 0; i < N; i++) {
		int b;
		std::cin >> b;
		v.push_back(b);
	}
	for (int i = 0; i < N; i++) {
		int b;
		std::cin >> b;
		c.push_back(b);
	}
	for (int i = 0; i < N; i++) {
		int a = v.at(i) - c.at(i);
		if (a > 0) {
			M += a;
		}
	}
	std::cout << M;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from collections import deque

def solve(N: int, u: int, v: int, A: "List[int]", B: "List[int]"):
    matrix = [[] for _ in range(N+1)]
    for i in range(N-1):
        matrix[A[i]].append(B[i])
        matrix[B[i]].append(A[i])

    takahashi_dist = [-1]*(N+1)
    aoki_dist = [-1]*(N+1)

    queue_takahashi = deque([(u,0)])

    while queue_takahashi:
        node,dist = queue_takahashi.popleft()
        takahashi_dist[node] = dist

        for nd in matrix[node]:
            if takahashi_dist[nd] == -1:
                queue_takahashi.append((nd,dist+1))
    

    queue_aoki = deque([(v,0)])
    while queue_aoki:
        node,dist = queue_aoki.popleft()
        aoki_dist[node] = dist

        for nd in matrix[node]:
            if aoki_dist[nd] == -1:
                queue_aoki.append((nd,dist+1))

    answer = 0
    for j in range(1,N+1):
        if aoki_dist[j] > takahashi_dist[j]:
            answer = max(answer,aoki_dist[j]-1)
    print(answer)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    u = int(next(tokens))  # type: int
    v = int(next(tokens))  # type: int
    A = [int()] * (N - 1)  # type: "List[int]"
    B = [int()] * (N - 1)  # type: "List[int]"
    for i in range(N - 1):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, u, v, A, B)

if __name__ == '__main__':
    main()


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

using namespace std;

const int N = 3e5 + 50;

int n, m, a[N];

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

    cin >> n >> m;
    long long sum = 0;
    for (int x, i = 1; i <= m; i++)
        cin >> x, sum += x;

    cout << (n <= sum ? "Yes" : "No");
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
	     int a = sc.nextInt();
	     int b = sc.nextInt();
	     int c = sc.nextInt();
	     
	     if(a<b&&b<c){
	    	 System.out.println("Yes");
	     }
	     else{
	    	 System.out.println("No");
	     }
	}

}


Measured memory_bytes: 26196
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <queue>
#include <fstream>
#include <algorithm>


using namespace std;

typedef long long ll;

const int maxn=1e5+10;
int a[maxn];
int main()
{
  int n;
  scanf("%d",&n);
  for(int i=0;i<n;i++)
  {
    scanf("%d",&a[i]);
    a[i]--;
  }
  int res=0;
  for(int i=0;i<n;i++)
    if(a[i]==i)
    {
      if(i+1<n&&a[i+1]==i+1)
      {
        res+=1;
        swap(a[i],a[i+1]);
      }
      else
      {
        if(i>0)
        {
          swap(a[i-1],a[i]);
          res++;
        }
        else if(i+1<n)
        {
          swap(a[i],a[i+1]);
          res++;
        }
      }
    }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main() {
	int l, r, f;
	cin >> f >> l >> r;
	//if (r - l + 1 >= f||r%f<l%f)cout << "OK";
	//else cout << "NG";
	int num = 0;
	while (num<=r) {
		num += f;
		if (num >= l && num <= r) {
			cout << "OK";
			return 0;
		}
	}
	cout << "NG";
	return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()

using namespace std;

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}

/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*/

int main() {
	int N,M, X; cin >> N >> M>>X;
	VLL m(M);
	int sum = 0, ans = 0,ans0=0;
	for (int i = 0;i < M;i++) cin >> m[i];
	//sort(all(m));
	for(int i = X-1;i>0;i--) {
		for(int j=0;j<M;j++){
			if (i == m[j]) ans++;
		}
	}
	for (int i = X ;i < N;i++) {
		for (int j = 0;j < M;j++) {
			if (i == m[j]) ans0++;
		}
	}
	if (ans < ans0)cout << ans << endl;
	else cout << ans0 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
using namespace std;
#define MAX 10000
#define INFTY 100000000
#define WHITE 1
#define GRAY 0
#define BLACK -1

vector<pair<int,int> > Adj[MAX];
priority_queue<pair<int,int> >Queue;
int d[MAX];
int c[MAX];

void init(int n) {
    int i;
    
    for(i = 0; i < n; i++){
        d[i] = INFTY;
        c[i] = WHITE;
    }
    
    d[0] = 0;
    c[0] = GRAY;  
    Queue.push(make_pair(0,0));
}

void sssp(int n){
    int u, i, v, tmp;
    
    init(n);
    
    while(!Queue.empty()){
        pair<int,int> f = Queue.top();
        Queue.pop();
        u = f.second;
        c[u] = BLACK;
        
        if(d[u] < f.first * -1) continue;
        for(i = 0; i < Adj[u].size(); i++){
            v = Adj[u][i].first;
            if(c[v] == BLACK) continue;
            if(d[v] > d[u] + Adj[u][i].second){
                d[v] = d[u] + Adj[u][i].second;
                tmp = d[v] * -1;
                Queue.push(make_pair(tmp, v));
                c[v] = GRAY;
            }
        }
    }
    
    for(i = 0; i < n; i++){
        cout << i << " " << ( d[i] == INFTY ? -1 : d[i] ) << endl;
    }
}

int main(){
    int n, m, l, a, b, i, j;
    
    cin >> n;
    
    for(i = 0; i < n; i++){
        cin >> l >> m;
        for(j = 0; j < m; j++){
            cin >> a >> b;
            Adj[l].push_back(make_pair(a, b));
        }
    }
    
    sssp(n);
    
    return 0;
}


Measured memory_bytes: 7984
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
struct dijkstra {
    vector<vector<pair<lli, lli>>> e;
    int n;
    lli inf = 1e18;
    dijkstra(int n) : n(n)
    {
        e.resize(n);
    }
    void add(int a, int b, lli c)
    {
        e[a].push_back(make_pair(b, c));
    }
    void biadd(int a, int b, lli c)
    {
        add(a, b, c);
        add(b, a, c);
    }
    vector<lli> get(int s)
    {
        vector<lli> dist(n, inf);
        dist[s] = 0;
        using p = pair<lli, lli>;
        priority_queue<p, vector<p>, greater<p>> que;
        que.push(make_pair(0, s));
        while (!que.empty()) {
            lli d = que.top().first;
            lli cur = que.top().second;
            que.pop();
            if (dist[cur] < d)
                continue;
            dist[cur] = d;
            for (auto s : e[cur]) {
                lli wei = s.second;
                lli to = s.first;
                if (dist[to] > dist[cur] + wei) {
                    dist[to] = dist[cur] + wei;
                    que.push(make_pair(dist[cur] + wei, to));
                }
            }
        }
        return dist;
    }
    vector<lli> count(int s, lli mod)
    {
        auto sd = get(s);
        vector<bool> used(n, false);
        vector<lli> dp(n, 0);
        dp[s] = 1;

        using p = pair<lli, lli>;
        priority_queue<p, vector<p>, greater<p>> que;
        que.push(make_pair(0, s));
        while (!que.empty()) {
            lli d = que.top().first;
            lli cur = que.top().second;
            que.pop();
            if (used[cur])
                continue;
            used[cur] = true;
            for (auto ed : e[cur]) {
                lli wei = ed.second;
                lli to = ed.first;
                if (sd[to] == sd[cur] + wei) {
                    dp[to] = (dp[cur] + dp[to]) % mod;
                    que.push(make_pair(d + wei, to));
                }
            }
        }
        return dp;
    }
};
int main()
{
    int n, m, s, t;
    cin >> n >> m;
    dijkstra dij(n);
    cin >> s >> t;
    s--, t--;
    int u, v, d;
    rep(i, m)
    {
        cin >> u >> v >> d;
        u--, v--;
        dij.biadd(u, v, d);
    }
    auto ds = dij.get(s);
    auto dt = dij.get(t);
    lli mod = 1e9 + 7;
    auto ps = dij.count(s, mod);
    auto pt = dij.count(t, mod);

    lli ans = ps[t] * pt[s];
    rep(i, n)
    {
        lli tmp = 0;
        if (ds[i] * 2 == ds[t]) {
            tmp = (ps[i] * pt[i]) % mod;
            tmp = (tmp * tmp) % mod;
        } else {
            for (auto ed : dij.e[i]) {
                if (ds[i] * 2 < ds[t] and (ds[i] + ed.second) * 2 > ds[t] and ds[i] + ed.second + dt[ed.first] == ds[t]) {
                    tmp += (ps[i] * pt[ed.first]) % mod * (ps[i] * pt[ed.first] % mod);
                    tmp %= mod;
                }
            }
        }
        ans = (ans - (tmp % mod) + mod) % mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 19560
#include<stdio.h>
int main(void)
{
	int i,j,wide,height;
	int h[10000],w[10000];
	i = 1;
	while(1){
		scanf("%d %d",&h[i],&w[i]);
		if(h[i] == 0 && w[i] == 0){
			break;
		}
		i++;
	}
	for(j = 1;j < i;j++){
		for(height = 1;height <= h[j];height++){
			for(wide = 1;wide <= w[j];wide++){
        if(wide % 2 == 0){
          if(height % 2 == 0){
            printf("#");
          }else{
            printf(".");
          }
        }else{
          if(height % 2 == 0){
            printf(".");
          }else{
            printf("#");
          }
        }
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
  
vector<int> a(n);
  
for(int i=0;i<n;i++) cin>>a[i];
  
int ans=1;
int mode=0;
  
for(int i=1;i<n;i++)
{
if(mode==0)
{
if(a[i]==a[i-1]) continue;
if(a[i]>a[i-1])
	mode=1;
else mode=-1;
		}
		else if(mode==1)
		{
			if(a[i]<a[i-1])
			{
				mode=0;
				ans++;
			}
		}
		else
		{
			if(a[i]>a[i-1])
			{
				mode=0;
				ans++;
			}
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3768
#include<bits/stdc++.h>
using namespace std;
using p = pair<int,int>;
int main(){
	int n;
	cin >> n;

	auto x = vector<int>(n);
	auto y = vector<int>(n);
	auto h = vector<long long>(n);
	
	for (int i = 0; i < n; i++)
	{
      	cin >> x[i] >> y[i] >> h[i];
	}

	long long cxx=-1,cyy=-1,hh=-1;
	bool flag= false;
	for (int cx = 0; cx <= 100; cx++)
	{
		for (int cy = 0; cy <= 100; cy++)
		{	
			long long hb;
			for (size_t i = 0; i < n; i++)
			{
			  if(h[i]==0) continue;
          	  hb= abs(x[i]-cx)+abs(y[i]-cy)+h[i];
			}
			 
			for (int i = 0; i < n; i++)
			{
              	if(hb<1) break; 
				if(max(hb-abs(x[i]-cx)-abs(y[i]-cy),(long long)0)!=h[i]) break;
				if(i == n-1){
					cxx = cx;
					cyy = cy;
					hh = hb;
					flag = true;
				}
			}
			if(flag) break;
		}
		if(flag) break;
	}
	
	cout << cxx <<" "<<cyy <<" "<<hh;
	
	
}


Measured memory_bytes: 256
#include <cstdlib>
#include <cstdio>
int n;
inline int query(int pos)
{
	printf("%d\n", pos % n);
	fflush(stdout);
	static char str[15];
	scanf("%s", str);
	if (str[0] == 'V')
		exit(0);
	return str[0] == 'M';
}
void solve(int l, int r, int x, int y)
{
	int m = l + r >> 1, res = query(m);
	if ((x == res) == (m - l & 1))
		solve(l, m, x, res);
	else
		solve(m, r, res, y);
}
int main()
{
	scanf("%d", &n);
	int x = query(0), y = query(n / 2);
	if ((x == y) == (n / 2 & 1))
		solve(0, n / 2, x, y);
	else
		solve(n / 2, n, y, x);
	return 0;
}


Measured memory_bytes: 760
x = input().split()

u = 100
y = 0
is_minus = False
for i in range(int(x[0])):
    if abs(i+int(x[1])) < u:
        u = abs(i + int(x[1]))
        if (i + int(x[1])) < 0:
            is_minus = True
        else:
            is_minus = False
    y += i + int(x[1])

if is_minus:
    print(y + u)
else:
    print(y-u)

Measured memory_bytes: 3064
#include <iostream>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <stack>
#include <cstdio>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#include <iterator>
#include <sstream>
#define popcount(x) __builtin_popcount(x)
#define oddparity(x) __builtin_parity(x)
#define clz(x) __builtin_clz(x)
#define ctz(x) __builtin_ctz(x)
#define sf scanf
#define pf printf
#define ll long long int
using namespace std;

int i, a[26];
string s;

int main()
{
    cin >> s;
    for (i = 0; i < s.size(); i++) {
        a[s[i]-'a']++;
    }
    for (i = 0; i < 26; i++) {
        if (a[i] > 1) {
            pf("no\n");
            return 0;
        }
    }
    pf("yes\n");
    return 0;
}

Measured memory_bytes: 256
def check(sum1,k,arr,m):
    count=0
    for i in arr:
        if(i >= k):
            count+=1
    if(count >= m):
        return True
    return False
inp=list(map(int,input().strip().split()))[:2]
n,m=inp[0],inp[1]
arr=list(map(int,input().strip().split()))[:n]
sum1=sum(arr)
k=sum1/(4*m)
a=check(sum1,k,arr,m)
if(a):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
h, w = map(int, input().split())

s = []
for _ in range(h):
    s.append(list(input()))
    
direction = [[0, 1], [0, -1], [1, 0], [-1, 0]]
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            for dy, dx in direction:
                y = i + dy
                x = j + dx
                try:
                    if s[y][x] == "#":
                        break
                except IndexError:
                    pass
            else:
                print("No")
                exit()
print("Yes")

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

int main() {
    int N,K,X,Y;
    int total=0;

    cin>>N>>K>>X>>Y;
    for(int i=1;i<=N;i++){
        if(i<=K){
            total+=X;
        }
        else{
            total+=Y;
        }
    }
    cout<<total<<endl;
    
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(v)    begin(v), end(v)
#define in        []{lint n; cin>>n; return n;}()


#define LCS longest_common_subsequence
int longest_common_subsequence( const string S, const string T ) {
    vector<vector<int>> dp( S.size()+1, vector<int>(T.size()+1, 0) );

    rep( s, S.size() ) {
    rep( t, T.size() ) {
        dp[s+1][t+1] = S[s] == T[t] ?
            dp[s][t] + 1 :
            max( dp[s][t+1], dp[s+1][t] );
    }
    }

    return dp[S.size()][T.size()];
}

int main() { cin.tie(0); ios::sync_with_stdio(false);
    int N = in;
    rep( _, N ) {
        string S, T; cin >> S >> T;
        cout << LCS( S, T ) << "\n";
    }
}



Measured memory_bytes: 6920
data class Task(val size: Int, val deadline: Int)
fun main() {
    val n = readLine()!!.trim().toInt()
    val tasks = List(n){
        val (a, b) = readLine()!!.trim().split(' ').map(String::toInt)
        Task(a, b)
    }.sortedBy(Task::deadline)
    println(tasks.fold(0 as Int?){currentTime, task -> currentTime?.let{task.size + it}?.takeIf{ it <= task.deadline}}?.let{"Yes"} ?: "No")
}

Measured memory_bytes: 77456
N = int(input())
nums = list(map(int, input().split()))
count = 0
max_count = 0
right = 0
while True:
    if right == N-1:
        break
    
    if nums[right+1] <= nums[right]:
        count += 1    
    else:
        count = 0
        
    if max_count < count:
        max_count = count
        
    right += 1
    
print(max_count)

Measured memory_bytes: 15020
import numpy as np

n,k = map(int,input().split())
a_list = np.array(list(map(int,input().split())))
a_list = np.sort(a_list)

zero = a_list[a_list == 0]
pos = a_list[a_list > 0]
neg = a_list[a_list < 0]

def count(x): #積がx以下になるペアの個数を返す(一旦重複は考えない)
    ans = 0
    if x >= 0:
        ans += n * len(zero)
    # a_list * pos < xだから，a_list < x/posになる個数をcountしている(pos側を固定)
    ans += np.searchsorted(a_list,x // pos, side='right').sum()
    # a_list < x // negとなる者を全ての組み合わせから抜く
    ans += (n - np.searchsorted(a_list, (-x - 1) // (-neg), side='right')).sum()
    # 同じもの2つは選べない
    ans -= np.count_nonzero(a_list * a_list <= x)
    return ans // 2

left = -10 ** 18
right = 10 ** 18
while left + 1 < right:
    x = (left + right) // 2
    if count(x) >= k:
        right = x
    else:
        left = x

print(right)

Measured memory_bytes: 32292
n = int(input())
p = list(map(int,input().split()))

ans = 0
for i in range(n):
    if(i == 0):
        pass
    elif (i == n - 1):
        pass
    else:
        a = p[i - 1]
        b = p[i]
        c = p[i + 1]
        lst = [a, b ,c]
        lst.sort()
        if (lst[1] == b):
            ans = ans + 1
print(ans)


Measured memory_bytes: 9132
// kartikay26
#include <bits/stdc++.h>
using namespace std;
#define debug(x...) 
#ifdef LOCAL
#include "prettyprint.hpp"
#endif
void print(){cout << endl;} void prints(){}
template<typename T=int> T get(){T x; cin >> x; return x;}
template<typename T> void get(T* x, int n){for (int i = 0; i < n; ++i) { cin >> x[i]; }}
template<typename T> void get(T& x, int n){for (int i = 0; i < n; ++i) { cin >> x[i]; }}
template<typename T, typename... A> void print(T x,A... r){cout << x << " ";print(r...);}
template<typename T, typename... A> void prints(T x,A... r){cout << x << " ";prints(r...);}
typedef long long int ll; typedef double db; typedef vector<ll> vi; typedef pair<ll, ll> pii;
#define int ll
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define clear(x) memset(x, 0, sizeof(x))
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

const int mod = 1e9+7;
const int N = 1e6+1;

int32_t main(){
	fast_io();

	int n, m;
	cin >> n >> m;

	vi adj[n+1];

	for (int i = 0; i < m; ++i) {
		int x, y; cin >> x >> y;
		adj[x].push_back(y);
	}

	vi lpath(n+1, -1);

	function<int(int)> f = [&](int x){
		if (lpath[x] != -1) return lpath[x];
		int ans = 0;
		for(auto y : adj[x]){
			ans = max(ans, 1 + f(y));
		}
		return lpath[x] = ans;
	};

	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		ans = max(ans, f(i));
	}

	print(ans);
	
	return 0;
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  vector<int> a(N);
  rep(i,N)
  {
    cin >> a[i];
  }
  int count = 0;
  rep(i,N-1)
  {
    if(a[i]==a[i+1])
    {
      a[i+1] = -1;
      count ++;
    }
  }
  cout << count << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;

int N;
ll A[3000];
const ll INF = 1145141919810893;
ll dp[3000][3000];//dp[i][j]:=[i, j]が残ってる時の、X-Yの値
//本来ならば、太郎が回ってきた時の太郎にとってのベストのX-Y, 次郎が回ってきたときの次郎にとってのベストのX-Y
//を二通り考えるけど、この場合は[i, j]の偶奇により[i, j]の局面で誰が操作するのか決まってるので一つのみ用意する

ll memo(int l, int r) {
	if (dp[l][r] != INF)return dp[l][r];
	
	bool teban;//falseなら太郎　trueなら次郎
	if ((N - (r - l + 1)) % 2 == 0)teban = false;
	else teban = true;

	if (l == r) {
		if (!teban)
			return dp[l][r] = A[l];
		else
			return dp[l][r] = -A[l];
	}

	if (!teban) {
		//X-Yを最大化
		return dp[l][r] = max(memo(l + 1, r) + A[l], memo(l, r - 1) + A[r]);
	}
	else {
		//X-Yを最小化
		return dp[l][r] = min(memo(l + 1, r) - A[l], memo(l, r - 1) - A[r]);
	}
}

int main() {
	cin >> N;
	for (int i = 0; i < N; i++)cin >> A[i];
	for (int i = 0; i < N; i++)for (int j = 0; j < N; j++)dp[i][j] = INF;
	cout << memo(0, N - 1) << endl;

	return 0;
}

Measured memory_bytes: 70784
text = input()
rule = 'ATCG'

max_len = 0
text_len = 0
for char in text:
    if char in rule:
        text_len += 1
    else:
        if text_len > max_len:
            max_len = text_len
        text_len = 0
if text_len > max_len:
    max_len = text_len
print(max_len)


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 4000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

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

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

	string ans = "No";

	ll N = s.size();

	rep(i, N) {
		for (ll j = i + 1; j < N; j++) {
			if (s[i] == 'C'&&s[j] == 'F') { ans = "Yes"; }
		}
	}

	cout << ans << endl;

	system("PAUSE");
}


Measured memory_bytes: 504
n, l = map(int, input().split())
s = (l + l + n - 1) * n // 2
Ps = [l] * n
for i in range(n):
  Ps[i] += i
if 0 in Ps:
  print(s)
elif Ps[n - 1] < 0:
  print(s - Ps[n - 1])
else:
  print(s - Ps[0])

Measured memory_bytes: 61940
#include <iostream>
#include <set>
#include <cmath>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main() {
  int cnt[100001] = {};
  int n; cin >> n;
  int ans = 0;
  REP(i, n) {
    int in; cin >> in;
    if (in > 100000) ans++;
    else cnt[in]++;
  }
  for (int i = 1; i <= 100000; ++i) {
    if (cnt[i]) {
      if (cnt[i] < i) ans += cnt[i];
      else ans += cnt[i] - i;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

static int c, colors[101], i, sum;

int main(void) {
    for (i = 0; i < 3; ++i) {
        scanf("%d", &c);
        ++colors[c];
    }
    for (i = 0; i < 101; ++i)
        if (colors[i])
            ++sum;
    printf("%d\n", sum);
    return 0;
}


Measured memory_bytes: 128
import math
Input = input().split()
N = float(Input[0])
K = float(Input[1])

result = float(0)
p = float(1/N)
i = 0

if N >= K:
    result = result + (N - K + 1) * p
    N = K - 1

while K > 1:
    K = K / 2
    x = float(math.ceil(K))
    i += 1
    if N >= x:
        q = 0.5**i
        result = result + (N - x + 1) * q * p
        N = x - 1

print(result)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void){
	int i,j,a,c,d,cnt,sum=0,b[10001];
	scanf("%d",&a);
	for(i=0;i<a;i++)
		scanf("%d",&b[i]);
	scanf("%d",&c);
	for(i=0;i<c;i++){
		cnt=0;
		scanf("%d",&d);
		b[a]=d;
		for(j=0;j<=a;j++){
			if(b[j]==d)
				cnt++;
		}
		if(cnt>=2)
			sum++;
	}
	printf("%d\n",sum);
	return 0;
}
		
		
	



		

Measured memory_bytes: 636
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

s = input()
n = int(input())
front = ''
end = ''
front_flag = True # Trueの場合frontがfront Falseの場合endがfront
for i in range(n):
    q = input()
    if len(q) == 1:
        front_flag = not front_flag
    else:
        _, f, c = q.split()
        if f == '1':
            if front_flag:
                front += c
            else:
                end += c
        else:
            if not front_flag:
                front += c
            else:
                end += c

if front_flag:
    s = front[::-1] + s + end
else:
    s = end[::-1] + s[::-1] + front

print(s)

Measured memory_bytes: 4412
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <random>
#include <fstream>
#include <time.h>
// #define int long long
#define debug(x) cerr << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double EPS = 1e-9;


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

  // int n,k;
  // cin>>n>>k;
  // cout << n-k+1 << endl;
  int r,g,b,n;
  cin>>r>>g>>b>>n;
  ll ans = 0;
  rep(i,n/r + 1) {
    rep(j, n/g + 1) {
      if((n - i*r - j*g) >= 0 && (n - i*r - j*g) % b == 0) {
        ans++;
      }
    }
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

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;
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

int N,A[305],xo;
int solve(){
	int add=A[0]+A[1];
	int sai=0;
	rep(i,N)sai^=A[i];
	if(sai==0){
		return 0;
	}
	for(int i=N-1;i>1;i--){
		xo^=A[i];
	}
	if(xo>add||(add-xo)%2||(add-xo)/2>A[0])return -1;
	else {
		int must=(add-xo)/2;
		int ans=must;
		for(int i=60;i>=0;i--){
			if((must>>i&1ll)==0&&(xo>>i&1ll)&&ans+(1ll<<i)<=A[0]){
				ans+=1ll<<i;
			}
		}
		if(ans==0)return -1;
		else return A[0]-ans;
	}
}
signed main(){
	cin>>N;
	rep(i,N)cin>>A[i];
	int i=solve();
	if(((A[0]-i)^(A[1]+i))!=xo)i=-1;
	cout<<i<<endl;
}


Measured memory_bytes: 3548
import os
import sys
from io import BytesIO, IOBase


def main():
    h, w, m = map(int, input().split())
    row = [0] * h
    col = [0] * w
    d = set()
    ma = 0
    for i in range(m):
        x, y = map(int, input().split())
        row[x - 1] += 1
        col[y - 1] += 1
        d.add((x, y))
    e=max(row)
    f=row.index(e)
    g=max(col)
    z=col.index(g)
    for i in range(w):
        ma=max(ma,e+col[i]-(1 if (f+1,i+1) in d else 0))
    for i in range(h):
        ma=max(ma,g+row[i]-(1 if (i+1,z+1) in d else 0))
    print(ma)
# region fastio
BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == "__main__":
    main()

Measured memory_bytes: 124680
//AtCoder 
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

int main() {
    ll a,b; cin>>a>>b;
    ll dif=b-a;
    ll ans=0;
    for(ll i=1;i<=dif;++i){
        ans+=i;
    }
    ans=ans-b;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n,m;
  cin>>n>>m;
  int a[n][m];
  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
      cin>>a[i][j];

  int ans=0;
  for(int i=0;i<n;i++){
    if(i) for(int j=0;j<m;j++) a[i][j]=!a[i][j];
    if(m==1){
      ans+=a[i][0];
      continue;
    }
    int tmp=0,res=0;
    for(int j=1;j<m-1;j++) a[i][j]=!a[i][j];
    for(int j=0;j<m;j++) tmp+=a[i][j];
    for(int j=0;j<m;j++){
      tmp-=a[i][j];
      tmp+=!a[i][j];
      res=max(res,tmp);
      tmp+=a[i][j];
      tmp-=!a[i][j];
    }
    ans+=res;
    //cout<<tmp<<" "<<res<<endl;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3184
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cctype>
#include <set>
#include <numeric>
using namespace std;

struct Term {
    char op;
    set<int> operand;
    Term(char c, set<int> si) : op(c), operand(si) { }
};

template<class T> struct Parser {
    typedef string::const_iterator State;

    T solve(const string &S) {
        State begin = S.begin();
        return expr(begin);
    }

    // expr ::= factor | factor + factor | factor - factor
    //         | factor * factor | factor / factor
    T expr(State &begin) {
        vector<Term> terms;
        terms.emplace_back('@', factor(begin));
        for (;;) {
            if (*begin == '+') {
                ++begin;
                terms.emplace_back('+', factor(begin));
            } else if (*begin == '-') {
                ++begin;
                terms.emplace_back('-', factor(begin));
            } else if (*begin == '*') {
                ++begin;
                terms.emplace_back('*', factor(begin));
            } else if (*begin == '/') {
                ++begin;
                terms.emplace_back('/', factor(begin));
            } else {
                break;
            }
        }
        return dp(terms);
    }

    T dp(vector<Term> &terms) {
        int n = terms.size();
        vector<vector<T>> dp(n, vector<T>(n));
        for (int i = 0; i < n; i++) {
            dp[i][0] = terms[i].operand;
        }
        for (int len = 1; len < n; len++) {
            for (int i = 0; i + len < n; i++) {     // [i, i + len]
                T &res = dp[i][len];
                for (int j = i + 1; j <= i + len; j++) {   // [i, j - 1] + [j, i + len]
                    T tmp = f(dp[i][j - i - 1], terms[j].op, dp[j][len + i - j]);
                    merge(res, tmp);
                }
            }
        }
        return dp[0][n - 1];
    }

    T f(T left, char op, T right) {
        T res;
        for (int a : left) for (int b : right) {
            if (op == '+') res.insert(a + b);
            else if (op == '-') res.insert(a - b);
            else if (op == '*') res.insert(a * b);
            else if (op == '/' && b != 0) res.insert(a / b);
        }
        return res;
    }

    T merge(T &res, T tmp) {
        for (int e : tmp) res.insert(e);
        return res;
    }

    // expr ::= ( term ) | num
    T factor(State &begin) {
        if (*begin == '(') {
            begin++; // skip '('
            T ret = expr(begin);
            begin++; // skip ')'
            return ret;
        } else {
            return number(begin);
        }
    }

    // num ::= digit | num digit
    T number(State &begin) {
        int ret = 0;
        while (isdigit(*begin)) {
            ret *= 10;
            ret += *begin - '0';
            begin++;
        }
        return {ret};
    }
};

int main() {
    string S;
    while (cin >> S && S != "#") {
        Parser<set<int>> ps;
        cout << ps.solve(S).size() << endl;
    }
    return 0;
}


Measured memory_bytes: 3340
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    A = [list(map(int, readline().split())) for _ in range(2)]
    B = np.array(A[0]).cumsum()
    C = np.array(A[1][::-1]).cumsum()[::-1]
    print((B+C).max())

if __name__ == '__main__':
    main()

Measured memory_bytes: 12488
S = list(input())
K = int(input())
 
ans = 0
#２つ並べて一般性を確かめる
S2 = S*2

for i in range(1,len(S2)):
    if S2[i-1]== S2[i]:
        S2[i] = '@'
        #2回目以降はk-1回任意の@へ直す
        if i>=len(S2)//2:
            ans+= K-1
        else:
            ans+=1
            
if len(set(S)) ==1 and len(S)%2 !=0:
   ans = len(S)*(K//2)+(K%2==1)*(len(S)//2)
print(ans) 

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

int main(){
  int h[300],w[300],i,j,k=0,num=0,num_=0;
  while(1){
    scanf("%d%d",&h[k],&w[k]);
    if(h[k]==0&&w[k]==0){
      break;
    }
    k++;
  }
  k=0;
  while(1){
    if(h[k]==0&&w[k]==0){
      break;
    }
    for(i=0;i<h[k];i++){
      for(j=0;j<w[k];j++){
        if(num_%2==0){
	  if(num%2==0){
            printf("#");
	  }else{
            printf(".");
	  }
	}else{
          if(num%2==0){
            printf(".");
	  }else{
            printf("#");
	  }
	}
	num++;
      }
      num_++;
      num = 0;
      printf("\n");
    }
    num_ =0;
    printf("\n");
    k++;
  }
  return 0;
}



Measured memory_bytes: 2056
import sys
input = sys.stdin.readline
x, k, d = map(int, input().split())

sho, amari = abs(x)//d, abs(x)%d
if k <= sho:
  print((abs(x)-(k*d)))
  sys.exit()
else:
  x = amari
  k = k-sho
  
if x == abs(x-d):
  print(x)
elif x < abs(x-d):
  if k%2==0:
    print(x)
  else:
    print(abs(x-d))
else:
  if k%2==1:
    print(abs(x-d))
  else:
    print(x)

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

typedef long long ll;
const int MOD = 1e9 + 7;
typedef vector<ll> vll;

static int speedUp = []() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    return 0;
}();

int main() {
    int n;
    cin >> n;
    vll nums(n);
    for (int i = 0; i < n; ++i) {
        cin >> nums[i];
    }
    vll sign(n);
    sign[0] = -1;
    sign[n - 1] = (n % 2 == 1) ? -1 : 1;
    int minus = 1;
    for (int i = 1; i < n - 1; ++i) {
        sign[i] = 2 * minus;
        minus = -minus;
    }
    sort(nums.begin(), nums.end());
    sort(sign.begin(), sign.end());
    ll ans = 0;
    ll ans1 = 0;
    for (int i = 0; i < n; ++i) {
        ans1 += nums[i] * sign[i];
    }
    sign[0] = 1;
    sign[n - 1] = (n % 2 == 1) ? 1 : -1;
    minus = -1;
    for (int i = 1; i < n - 1; ++i) {
        sign[i] = 2 * minus;
        minus = -minus;
    }
    sort(sign.begin(), sign.end());
    ll ans2 = 0;
    for (int i = 0; i < n; ++i) {
        ans2 += nums[i] * sign[i];
    }
    ans = max(ans1, ans2);
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 1792