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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int n;
    int a[100009] = {};
    int dp[100009][2] = {};
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];

    dp[0][0] = 0;
    dp[0][1] = -INF;
    for (int i = 0; i < n; i++)
    {
        dp[i + 1][0] = max(dp[i][0] + a[i], dp[i][1] - a[i]);
        dp[i + 1][1] = max(dp[i][0] - a[i], dp[i][1] + a[i]);
    }
    cout << dp[n][0] << endl;
}


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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) x.begin(), x.end()
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)

const static int MOD = 1000000000 + 7;
const static llong INF = 1LL << 60;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

vector<bool> visited;
vector<vector<int> > g;
vector<int> distance_from_zero, distance_from_N;

void dfs1(int s, int d) {
    if (visited[s] == true) return;

    visited[s] = true;
    distance_from_zero[s] = d;
    rep(i, g[s].size()) {
        dfs1(g[s][i], d + 1);
    }

    return;
}

void dfs2(int s, int d) {
    if (visited[s] == true) return;

    visited[s] = true;
    distance_from_N[s] = d;
    rep(i, g[s].size()) {
        dfs2(g[s][i], d + 1);
    }

    return;
}

signed main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    g.resize(n);
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        g[a - 1].push_back(b - 1);
        g[b - 1].push_back(a - 1);
    }

    visited.resize(n, false);
    distance_from_zero.resize(n, 0);
    dfs1(0, 0);

    rep(i, n) visited[i] = false;
    distance_from_N.resize(n, 0);
    dfs2(n - 1, 0);

    int f_cnt = 0, s_cnt = 0; 
    rep(i, n) {
        if (i == 0 || i == n - 1) continue;
        if (distance_from_zero[i] <= distance_from_N[i]) ++f_cnt;
        else ++s_cnt;
    }

    if (f_cnt > s_cnt) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;

    return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  string S;
  cin>>S;
  for(auto c:S)if(c=='7'){
    cout<<"Yes"<<endl;
    return 0;
  }
  cout<<"No"<<endl;
  return 0;
}


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

#define EB emplace_back
#define int long long
#define F first
#define S second
#define N 500005
#define all(x) x.begin(),x.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define rt return;
using namespace std;

void test_case(){
  
  
  int n; cin >> n;
  cout << !n;
  
}

int32_t main(){
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int tt = 1; 
  //cin >> tt;
  while(tt--){
    test_case();
    cout << '\n';
  }
  return 0;
}


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

int main () {
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  cout << ((abs(c-a) <= d || (abs(a-b) <= d && abs(b-c) <= d)) ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
//グローバル変数定義
var N = 0;
var A = 0;
var B = 0;
var C = 0;
var T = [];	//N本の竹の長さを配列BBに格納する

function rec(cur, a, b, c){
  
  if(cur == N){
    var mp = Math.abs(a-A) + Math.abs(b-B) + Math.abs(c-C) - 30;
	if(Math.min(a,b,c)<=0){
      return Infinity;
    }
	return mp;
  }
  
  var ret0 = rec(cur+1,a,b,c);
  var ret1 = rec(cur+1,a+T[cur],b,c)+10;
  var ret2 = rec(cur+1,a,b+T[cur],c)+10;
  var ret3 = rec(cur+1,a,b,c+T[cur])+10;

  var tmp = Math.min(ret0,ret1,ret2,ret3);
  return tmp;
}
function Main(input){
  input = input.split("\n");
  inputStr = input[0].split(" ");
  N = Number.parseInt(inputStr[0]);
  A = Number.parseInt(inputStr[1]);
  B = Number.parseInt(inputStr[2]);
  C = Number.parseInt(inputStr[3]);

  //N本の竹の長さを配列BBに格納する
  for( var i=0 ; i<N ; i++ ){
    T.push(Number.parseInt(input[i+1].split(" ")));
  }
  var tmp = rec(0, 0, 0, 0);
  console.log(tmp);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()

int main(){
    ll N, A, B;
    cin >> N >> A >> B;

    cout << min(N*A, B) << endl;
}


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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved

int main(){
    int n;
    cin>>n;
    long long a[n+1];
    rep2(i,n){
        cin>>a[i];
    }
    
    a[0]=-1;
    for(int i=1;i<=n;i++){
        if(a[i]>a[i-1]+1){
            cout<<"-1"<<endl;
            return 0;
        }        
    }
    long long ans=0;

    for(int i=2;i<=n;i++){
        if(a[i-1]+1==a[i]){
            ans++;
            //cout<<"?";
        }
        else{
            ans+=a[i];
            //cout<<"!";
        }
    }
    cout<<ans<<endl;
    return 0;

}
/*


*/


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
#define lint long long int
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
*/



int main() {
	int N;
	cin >> N;
	vector<lint>A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	vector<lint>S(N);
	S[0] = A[0];
	for (int i = 1; i < N; i++) {
		S[i] = S[i - 1] + A[i];
	}
	/*for (int i = 0; i < N; i++) {
		cout << S[i] << ' ';
	}
	cout << endl;*/
	vector<lint>SS(N);
	lint sum = S[N - 1];
	for (int i = 0; i < N; i++) {
		SS[i] = abs(S[i] - (sum - S[i]));
	}
	/*for (int i = 0; i < N; i++) {
		cout << SS[i] << ' ';
	}
	cout << endl;*/
	sort(SS.begin(), SS.end());
	cout << SS[0] << endl;
}


Measured memory_bytes: 5504
import java.util.*


fun main(args: Array<String>) {
    val sieve = SieveOfEratosthenes(55555L)
    val N = readLine()!!.toInt()

    println(sieve.primes.filter { it % 5 == 1L }.take(N).joinToString(" "))
}

class SieveOfEratosthenes(n: Long) {
    private val isPrime = Array(n.toInt() + 1) { true }

    /**
     * A list of primes less than or equal to `n`.
     */
    val primes: List<Long>

    init {
        isPrime[0] = false
        isPrime[1] = false
        val primeList = ArrayList<Long>()

        for (i in 2..n.toInt()) {
            if (!isPrime[i]) {
                continue
            }

            primeList.add(i.toLong())
            for (j in i * 2 .. n.toInt() step i) {
                isPrime[j] = false
            }
        }

        primes = Collections.unmodifiableList(primeList)
    }

    /**
     * @return `true` if `i` is prime.
     */
    fun get(i: Long): Boolean {
        return isPrime[i.toInt()]
    }
}



Measured memory_bytes: 33712
#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 Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

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

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

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

const int N = 16;

int n, m, sumw;
int dp[N][1 << N], sum[1 << N], G[N][N], num[1 << N];

#define lowbit(x) (x & -x)

#define Get(i, v, k) for(register int sta = k, v = __builtin_ctz(sta), i; i = 1 << v, sta; v = __builtin_ctz(sta ^= i))

int main () {

	File(); Set(dp, 0);

	n = read(); m = read();

	For (i, 0, n - 1) num[1 << i] = i;
	For (i, 1, m) {
		int u = read() - 1, v = read() - 1, w = read(); 
		G[u][v] = G[v][u] = w; sumw += w;
	}

	int maxsta = (1 << n) - 1;
	For (i, 1, maxsta) {
		int u = __builtin_ctz(i);
		sum[i] = sum[i ^ (1 << u)];
		Get(j, v, i) sum[i] += G[u][v];
	}

	Set(dp, -0x3f);
	for (int i = 1; i <= maxsta; i += 2) {
		dp[0][i] = sum[i];
		For (S, 0, n - 1) if (dp[S][i] >= 0) {
			int rest = maxsta ^ i;
			for (register int sub =	rest; sub; (-- sub) &= rest)
				dp[S][i | sub] = max(dp[S][i | sub], dp[S][i] + sum[sub | (1 << S)]);
			Get(j, v, rest) if (G[S][v])
				chkmax(dp[v][i | j], dp[S][i] + G[S][v]);
		}
	}

	printf ("%d\n", sumw - dp[n - 1][maxsta]);

	return 0;
}

Measured memory_bytes: 4480
#include <bits//stdc++.h>
using namespace std;
#define rep(i,n,k) for(int i=n;i<k;i++)
#define int long long
#define P make_pair
#define F first
#define S second
signed main(void){
    int n,m,ans,p,q;
    ans=0;
    string s,t,u;
    cin>>s;
    rep(i,0,s.size())cout<<"x";
    cout<<endl;
    return 0;


}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define NIL NULL
struct node{
  struct node *right,*left,*parent;
  int key;
};
typedef struct node *Node;
Node root;
Node treeMinimum(Node x){
  while(x->left!=NIL) x=x->left;
  return x;
}
Node treeSuccessor(Node x){
  if(x->right!=NIL) return treeMinimum(x->right);
  Node y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}
void deleteTree(Node x){
  Node y,z;
  if(x->left==NIL||x->right==NIL)y=x;
  else y=treeSuccessor(x);
  if(y->left!=NIL) z=y->left;
  else z=y->right;
  if(z!=NIL) z->parent=y->parent;
  if(y->parent==NIL) root=z;
  else{
    if(y==y->parent->left) y->parent->left=z;
    else y->parent->right=z;
  }
  if(y!=x){
    x->key=y->key;
  }
  free(y);
}
  
Node findTree(Node x,int k){
  if(x==NIL||x->key==k) return x;
  if(x->key>k) return findTree(x->left,k);
  else return findTree(x->right,k);
}
void insert(int k){
  Node y=NIL;
  Node x=root;
  Node z;
  z=malloc(sizeof(struct node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;
  while(x!=NIL){
    y=x;
    if(z->key<x->key) x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL) root=z;
  else if(z->key<y->key) y->left=z;
  else y->right=z;
}
void inorder(Node x){
  if(x->left!=NIL) inorder(x->left);
  printf(" %d",x->key);
  if(x->right!=NIL) inorder(x->right);
   
}
void preorder(Node x){
  if(x!=NIL){
    printf(" %d",x->key);
  }
  if(x->left!=NIL) preorder(x->left);
  if(x->right!=NIL)  preorder(x->right);
}
int main(){
  int n,i,x;
  char c[20];
  Node f;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",c);
    if(c[0]=='f'){
      scanf("%d",&x);
      f=findTree(root,x);
      if(f!=NIL) printf("yes\n");
      else printf("no\n");
    }
    if(c[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }
    else if(c[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if(c[0]=='d'){
      scanf("%d",&x);
      deleteTree(findTree(root,x));
    }
  }
  return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  if (a + b == 15) cout << "+" << endl;
  else if (a * b == 15) cout << "*" << endl;
  else cout << "x" << endl;

  return 0;
}


Measured memory_bytes: 256
///******* In the name of Allah *******///

#include<bits/stdc++.h>
using namespace std;

int main()
{
   int a,b,c,m,n,i,j,k,l,x,ans,cnt = 0;
   char aa[1013],bb[1013],cc[1013];
   cin>>n;
   for(i=1;i<=n;i++)
   {
      cin>>aa[i];
   }
   for(i=1;i<=n-2;i++)
   {
      if(aa[i]=='A' && aa[i+1]=='B' && aa[i+2]=='C')
      {
        cnt++;
      }
   }
   cout<<cnt<<endl;
   

    return 0;
}


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

using namespace std;

int main() {
	int i, n, k, q;

	scanf("%d %d %d", &n, &k, &q);

	int part[n];
	
	for(i = 0; i < n; i++) {
	    part[i] = k - q;
	}

	for(i = 0; i < q; i++) {
		int a;
		scanf("%d", &a);
		a--;

    	part[a]++;
	}

	for(i = 0; i < n; i++) {
		printf("%s\n", part[i] > 0 ? "Yes" : "No");
	}
}

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

int main () {
  int N, prev = 0, C = 0;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  for (int i = 0; i < N; i++) {
    if(A.at(i) == prev) {
    }
    else {
      C++;
      prev = A.at(i);
    }
  }
  cout << C;
  }

Measured memory_bytes: 256
import numpy as np
import numba
import math

@numba.njit
def main():
    dpt = np.array([math.inf] * (10**3*N + 1))
    dpt[0] = 0
    for i in range(N):
        for j in range(len(dpt)-1, items[i][1]-1, -1):
            dpt[j] = min(dpt[j], dpt[j-items[i][1]]+items[i][0])

    for i in range(len(dpt)-1, -1, -1):
        if dpt[i] <= W:
            break
    print(i)

if __name__ == '__main__':
    N, W = map(int, input().split())
    items = np.array([list(map(int, input().split())) for i in range(N)])
    main()

Measured memory_bytes: 114088
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int N,M;
vector<int> e[100001];
int ans[100001];
queue<P> que;

void bfs(int now,int parent){
    repr(x,e[now]){
        if(x==parent) continue;
        if(x!=0) continue;
    }
}

int main(){
    cin>>N>>M;
    repn(i,M){
        int a,b;
        cin>>a>>b;
        e[a].push_back(b);
        e[b].push_back(a);
    }

    que.push(P(1,0));
    while(!que.empty()){
        P p=que.front();
        que.pop();
        int now=p.first, parent=p.second;
        rep(i,e[now].size()){
            if(e[now][i]==parent){
                continue;
            }
            if(ans[e[now][i]]!=0){
                continue;
            }
            que.push(P(e[now][i],now));
            ans[e[now][i]]=now;
        }
    }

    cout<<"Yes"<<endl;
    repn(i,N-1) cout<<ans[i+1]<<endl;
}

Measured memory_bytes: 10512
#include <iostream>

using namespace std;

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

  int a, b;
  cin >> a >> b;

  int ans = 0;
  for (int i = a; i <= b; ++i) {
    const int hi = i / 1000;

    const int low = i % 100;
    const int flip = low / 10 + 10 * (low % 10);
    ans += hi == flip;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int h = scan.nextInt();
        int w = scan.nextInt();
        
        System.out.println((n-h+1)*(n-w+1));
    }
}


Measured memory_bytes: 22740
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 110;

struct Eratosthenes {
    ll n;
    vector<ll> f;  // f[i] : iを割りきる最小の素因数
    vector<ll> primes;  // primes[i] : i番目(iは0-index)の素数
    Eratosthenes(ll n = 1): n(n), f(n+1) {
        f[0] = f[1] = -1;
        for(ll i = 2; i <= n; ++i) {
            if(f[i]) {
                continue;
            } 
            primes.pb(i);
            f[i] = i;
            for(ll j = i*i; j <= n; j += i) {
                if(!f[j]) {
                    f[j] = i;
                } 
            }
        }
    }
    bool isPrime(ll x) {  // xが素数ならtrueを返す
         return f[x] == x;
    }
    vector<ll> factorList(ll x) {  // xの素因数を重複も許して昇順に列挙したvectorを返す(x = 720 = (2^4)*(3^2)*(5^1)なら{2,2,2,2,3,3,5}のように)
        vector<ll> res;
        while(x != 1) {
            res.pb(f[x]);
            x /= f[x];
        }
        return res;
    }
    vector<P> factor(ll x) {  // (xのi番目の素因数, その素因数の個数)のvectorを返す(x = 720 = (2^4)*(3^2)*(5^1)なら{(2, 4), (3, 2), (5, 1)}のように)
        vector<ll> fL = factorList(x);
        if(fL.size() == 0) {
            return {};
        } 
        vector<P> res(1, make_pair(fL[0], 0));
        for(auto p : fL) {
            if(res.back().first == p) {
                res.back().second++;
            } 
            else {
                res.emplace_back(p, 1);
            }
        }
        return res;
    }
};

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

    Eratosthenes era(MAX_N);
    map<ll, ll> mp;
    exrep(x, 2, n) {
        auto f = era.factor(x);
        for(auto p : f) {
            mp[p.first] += p.second;
        }
    }

    ll cnt74 = 0, cnt24 = 0, cnt14 = 0, cnt4 = 0, cnt2 = 0;
    for(auto p : mp) {
        if(p.second >= 74) {
            cnt74++;
        }
        if(p.second >= 24) {
            cnt24++;
        }
        if(p.second >= 14) {
            cnt14++;
        }
        if(p.second >= 4) {
            cnt4++;
        }
        if(p.second >= 2) {
            cnt2++;
        }
    }
    
    ll ans = cnt74 + cnt24*(cnt2-1) + cnt14*(cnt4-1) + cnt4*(cnt4-1)*(cnt2-2)/2;
    out(ans);
    re0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <map>
#include <climits>

using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;

int main()
{
  string s;
  cin >> s;
  if(s[2] == s[3] && s[4] == s[5])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#define int long long
using namespace std;

int n;
int cnt[100004];

signed main() {
	int i;
	
	cin >> n;
	for (i = 0; i < n; i++) {
		int a;
		cin >> a;
		cnt[a]++;
	}
	
	int ans = cnt[0] + cnt[1];
	for (i = 1; i <= 100000; i++) {
		ans = max(ans, cnt[i - 1] + cnt[i] + cnt[i + 1]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m,x;
    cin>>n>>m>>x;
    vector<int> c(n);
    auto a=vector(n,vector(m,0));
    ll ans{LLONG_MAX},tmp;
    fr(i,n){
        cin>>c[i];
        fr(j,m) cin>>a[i][j];
    }
    fr(b,(1<<n)){
        tmp=0;
        vector<int> X(m);
        fr(i,n) if((b>>i)&1){
            tmp+=c[i];
            fr(j,m) X[j]+=a[i][j];
        }
        bool f{true};
        fr(j,m) if(X[j]<x) f=false;
        if(!f) continue;
        chmin(ans,tmp);
    }
    cout<<(ans==LLONG_MAX?-1ll:ans)<<endl;
}

Measured memory_bytes: 3680
while True:
    N,M=map(int,input().split())
    if N==0 and M==0:
        break
    l = [0]*M
    for i in range(N):
        d,v=map(int,input().split())
        if l[d-1]<v:
            l[d-1]=v
    total = 0
    for i in range(M):
        total += l[i]

    print(total)


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

public class Main {
    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        long n = fs.nextLong();
        long rem;
        long quo;
        long min_walk = 10000000000000l;
        for(long i=1; i<=(long)Math.sqrt(n)+1; i++) {
            rem = n%i;
            quo = n/i;

            if(rem == 0) {
                long walk = i+quo-2;
                if(walk < min_walk) {
                    min_walk = walk;
                }
            }
        }
        System.out.println(min_walk);
    }
}
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
 
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
 
    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }
 
    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
 
    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }
 
    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
 
    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
 
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
 
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 22996
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String[] N = sc.next().split("");
		long res = 0;
		long num = 0;
		for (String s : N) {
			if (s.equals("W")) {
				res += num;
			} else {
				num++;
			}
		}
		System.out.println(res);

	}
}


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

using namespace std;

int main(){
	int A,B;
	
	cin >> A >> B;
	
	if(A<=5)	cout << "0" << endl;
	else if(A>=13) cout << B << endl;
	else	cout << (B/2) << endl;
	
	return 0;
}

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

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

using namespace std;

int main() {
    int n;
    int a[100];

    cin >> n;
    REP(i, n) {
        cin >> a[i];
    }

    int min = a[0];
    int max = a[0];

    FOR(i, 1, n) {
        if (min > a[i]) {
            min = a[i];
        }
        if (max < a[i]) {
            max = a[i];
        }
    }

    cout << max - min << endl;


    return 0;
}

Measured memory_bytes: 256
H,W = map(int, input().split())
S = [list(input()) for _ in range(H)]
answer = []
for i in range(H):
    row = []
    for j in range(W):
        if S[i][j] == "#":
            row.append("#")
            continue
        count = 0
        if i-1 != -1:
            for k in range(3):
                if j+k-1 != -1 and j+k-1 != W:
                    count += 1 if S[i-1][j+k-1] == "#" else 0
        for k in range(0,3,2):
            if j+k-1 != -1 and j+k-1 != W:
                count += 1 if S[i][j+k-1] == "#" else 0
        if i+1 != H:
            for k in range(3):
                if j+k-1 != -1 and j+k-1 != W:
                    count += 1 if S[i+1][j+k-1] == "#" else 0
        row.append(count)
    answer.append(row)
for i in answer:
    print(*i, sep="")

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
bool check(string s);

int main(){
  string s;
  cin >> s;
  //関数を作っちゃう
  if (check(s)){
    cout << "AC" << endl;
  }
  else {
    cout << "WA" << endl;
  }
  return 0;
}
  //おかしいの見つけたら即座にfalseを返して最後のcheckまで耐えられたら0を返す
bool check(string s){
    if(s[0]!='A') return false;
    int c=0;
    for (int i=2;i<s.length()-1;++i){
      if (s[i]=='C') c++;
    }
    if (c!=1) return false;
    
    int upper=0;
    for (int i=0;i<s.length();++i){
      if (s[i]>='A'&&s[i]<='Z'){
        upper++;
      }
    }
    if (upper!=2) return false;
    return true;
}
    


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

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

  if (m < n) {
    cout << "a < b" << endl;
  } else if (m > n) {
    cout << "a > b" << endl;
  } else if (m == n) {
    cout << "a == b" << endl;
  }
}

Measured memory_bytes: 3088
n,m=map(int,input().split())
sp=[None for i in range(m)]
for i in range(m):
  l,r=map(int,input().split())
  sp[i]=[l,r]
sp.sort(key=lambda x:x[1])
sp.sort(key=lambda x:x[0])
s=[sp[0]]
for i in sp:
  if i[0]!=s[-1][0]:
    s.append(i)
ans=1
c=s[0]
if len(s)==1:print(1)
else:
  for i in range(1,len(s)):
    if c[1]<=s[i][0]:
      ans+=1
      c=s[i]
    if c[1]>s[i][1]:
      c=s[i]
    else:
      c[0]=s[i][0]
  print(ans)

Measured memory_bytes: 23032
fn main() {
    let numbers: Vec<char> = read().chars().collect();

    let mut count = 0;
    for n in 0..3 {
        if numbers[n] == '1' {
            count = count + 1;
        }
    }

    println!("{}", count);
}

fn read() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s);
    s.to_string()
}

Measured memory_bytes: 4352
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>	
#include <cmath>
#include <string>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define Cout(s) cout<<s<<endl
using namespace std;
typedef long long ll;
string Yes(bool b) { if (b) { return "Yes"; } else { return "No"; } }
string YES(bool b) { if (b) { return "YES"; } else { return "NO"; } }
//================================================
ll a = 1, b = 0, c, d, n, k = 0, ans = 0;
string s, t;

int main()
{
	cin >> n >> s;
	vector<int> R, G, B;
	rep(i, n) {
		if (s[i] == 'R')R.push_back(i);
		else if (s[i] == 'G')G.push_back(i);
		else B.push_back(i);
	}
	int sum = 0;
	for (int i = 1; i <(n-3)/2+2 ; i++) {
		rep(j, n - 2 * i) {
			if (s[j] != s[j + i] && s[j + i * 2] != s[j] && s[j + i] != s[j + i * 2])
				sum++;
		}
	}
	cout << R.size() * G.size() * B.size() - sum << endl;	

	return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <stdlib.h>
#include <sstream>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
using namespace std;
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define M 1000000007
//#define FILE_A_IN
using vvi=vector<vector<int>>;

int n, m, q;
void dfs(vector<vector<int>>& va, vector<int> vt, int next, int& ans) {
    if(vt.size() == n) {
        int s = 0;
        for (auto e : va) {
            if(vt[e[1]-1] - vt[e[0]-1] == e[2]) {
                s += e[3];
            }
        }
        ans = max(s, ans);
        return;
    }
    for (int i = next; i < m+1; ++i) {
        vt.push_back(i);
        dfs(va, vt, i, ans);
        vt.pop_back();
    }
}
void solve() {
    int ans = 0;
    cin >> n >> m >> q;
    vvi va;
    for (int i = 0; i < q; ++i) {
        vector<int> vt(4);
        for (int j = 0; j < 4; j++) {
            cin >> vt[j];
        }
        va.push_back(vt);
    }
    vector<int> vt;
    dfs(va, vt, 1, ans);
    cout << ans << endl;
}
int main() {
#ifdef FILE_A_IN
    freopen("a.in", "r", stdin);
#endif
    fio;
        solve();
    return 0;
}

Measured memory_bytes: 3664
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<deque>//double-ended-queue
using namespace std;
int main()
{ 
    int n,m;
    cin>>n>>m;
    long long int a[n];
    long long int sum=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum=sum+a[i];
    }
    sort(a,a+n);
    reverse(a,a+n);
    //操作用キュー
    deque<long long int> q;
    for(int i=0;i<n;i++){
        q.push_back(a[i]);
    }
    //キュー配列
    vector<deque<long long int> > v;
    v.push_back(q);

    int num=1;
    long long int max;
    int memory;
    for(int i=0;i<m;i++){
        //初期段階
        if(num==1){
            q.clear();
            q.push_back(v[0][0]/2);
            sum=sum-v[0][0]+v[0][0]/2;
            v[0].pop_front();
            v.push_back(q);
            num++;
        }
        //queueの個数が2個以上
        else{
            //queue先頭の最大値判定
            max=-1;
            for(int j=0;j<num;j++){
                if (!v[j].empty()){
                    if(v[j][0]>max){
                        max=v[j][0];
                        memory=j;
                    }
                }
            }
            //最大値のqueueについて割引券を使用
            v[memory].pop_front();
            if(v.size()==memory+1){
                if(num<30){
                q.clear();
                q.push_back(max/2);
                v.push_back(q);
                sum=sum-max+max/2;
                num++;
                }
                else{
                sum=sum-max;
                v[0].push_back(0);
                }
            }
            else{
                v[memory+1].push_back(max/2);
                sum=sum-max+max/2;
            }
        }        
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 2688
h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
p = [(0,1),(1,0),(-1,0),(0,-1)]
mx = 0
for i in range(h):
    for j in range(w):
        if s[i][j] != '#':
            start = (i,j)
            n1 ={start}
            corse = {}
            corse[start]=1
            cnt = 1
            while n1 != set():
                n2 = set()
                for k in n1:
                    for l in p:
                        nk = (k[0]+l[0],k[1]+l[1])
                        if 0<=nk[0]<h and 0<=nk[1]<w:
                         if s[nk[0]][nk[1]] != '#' and corse.get(nk) == None:
                            corse[nk] = 1
                            mx = max(cnt,mx)
                            n2.add(nk)
                cnt += 1
                n1 = n2
print(mx)


Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <limits>
#include <numeric>
#include <vector>

#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
bool compare_by_b(pair<int, long long> a, pair<int, long long> b) {
    if(a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}
int main() {
    int H, W;
    cin >> H >> W;
    int a[510][510];
    rep(i, 1, H + 1) {
        rep(r, 1, W + 1) { cin >> a[i][r]; }
    }
    vector<vector<int>> ans;
    int n = 0;
    rep(i, 1, H + 1) {
        if(i % 2 == 1) {
            rep(r, 1, W + 1) {
                if(a[i][r] % 2 == 1) {
                    if(r != W) {
                        vector<int> ans1;
                        ans1.push_back(i);
                        ans1.push_back(r);
                        ans1.push_back(i);
                        ans1.push_back(r + 1);
                        ans.push_back(ans1);
                        n++;
                        a[i][r + 1]++;
                    } else {
                        if(i != H) {
                            vector<int> ans1;
                            ans1.push_back(i);
                            ans1.push_back(r);
                            ans1.push_back(i + 1);
                            ans1.push_back(W);
                            ans.push_back(ans1);
                            n++;
                            a[i + 1][W]++;
                        }
                    }
                }
            }
        } else {
            rep(r, 1, W + 1) {
                int t = W - r + 1;
                if(a[i][t] % 2 == 1) {
                    if(t != 1) {
                        vector<int> ans1;
                        ans1.push_back(i);
                        ans1.push_back(t);
                        ans1.push_back(i);
                        ans1.push_back(t - 1);
                        ans.push_back(ans1);
                        n++;
                        a[i][t - 1]++;
                    } else {
                        if(i != H) {
                            vector<int> ans1;
                            ans1.push_back(i);
                            ans1.push_back(t);
                            ans1.push_back(i + 1);
                            ans1.push_back(1);
                            ans.push_back(ans1);
                            n++;
                            a[i + 1][1]++;
                        }
                    }
                }
            }
        }
    }
    cout << n << endl;
    rep(i, 0, n) {
        cout << ans[i][0] << " " << ans[i][1] << " " << ans[i][2] << " "
             << ans[i][3] << endl;
    }
}

Measured memory_bytes: 10032
#include<bits/stdc++.h>
#define LL long long
#define N 100005
using namespace std;
const int mo=1e9+7;
const LL e[3][3]={{2,2,1},{1,1,1},{1,0,1}};
int n,m,X[N];
LL A[3],B[3],C[3],G[3][3],H[3][3],z[3][3],f[N];
void mult(LL u[3][3],LL v[3][3])
{
	int i,j,k;
	for(i=0;i<3;i++)
		for(j=0;j<3;j++){
			z[i][j]=0;
			for(k=0;k<3;k++)
				z[i][j]+=u[i][k]*v[k][j];
		  }
	for(i=0;i<3;i++)
		for(j=0;j<3;j++)
			u[i][j]=z[i][j]%mo;
}
int main()
{
	int i,j,k,p;
	scanf("%d %d",&n,&m);
	for(i=1;i<=m;i++)
		scanf("%d",&X[i]);
	X[0]=0,X[++m]=n,f[0]=B[0]=1;
	for(i=1;i<=m;i++){
		p=X[i]-X[i-1];
		for(j=0;j<3;j++)
			for(k=0;k<3;k++)
				H[j][k]=e[j][k],G[j][k]=(j==k);
		while(p){
			if(p&1) mult(G,H);
			p>>=1 , mult(H,H);
		  }
		C[0]=(A[0]*G[0][0]+A[1]*G[1][0]+A[2]*G[2][0])%mo;
		C[1]=(A[0]*G[0][1]+A[1]*G[1][1]+A[2]*G[2][1])%mo;
		C[2]=(A[0]*G[0][2]+A[1]*G[1][2]+A[2]*G[2][2])%mo;
		A[0]=C[0],A[1]=C[1],A[2]=C[2];
		C[0]=(B[0]*G[0][0]+B[1]*G[1][0]+B[2]*G[2][0])%mo;
		C[1]=(B[0]*G[0][1]+B[1]*G[1][1]+B[2]*G[2][1])%mo;
		C[2]=(B[0]*G[0][2]+B[1]*G[1][2]+B[2]*G[2][2])%mo;
		B[0]=C[0],B[1]=C[1],B[2]=C[2];
		f[i]=(B[2]-A[2]+mo)%mo,(A[0]+=f[i])%=mo;
	  }
	cout<<f[m];
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int MOD = 1000000007;
int INF = numeric_limits<int>::max() / 2;


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

  int N;
  cin >> N;
  int A[N];
  rep(i,N) cin >> A[i];
  int sum[N];
  sum[1] = abs(A[1] - A[0]);
  sum[2] = min(abs(A[0] - A[2]), sum[1]+abs(A[1] - A[2]));
  for(int i=3;i<N;i++){
    sum[i] = min(sum[i-2] + abs(A[i]-A[i-2]), sum[i-1] + abs(A[i]-A[i-1]));
  }
  cout << sum[N-1] << endl;
}

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

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int a[] = new int[4];

        int m = n;
        for (int i = 3; i >= 0; i--) {
            a[i] = m % 10;
            m /= 10;
        }

        int sign = 0;
        for (int i = 0; i < 8; i++) {
            int calc = a[0];
            for (int j = 1; j < 4; j++) {
                calc += (((i >> (j - 1)) & 1) == 0 ? +a[j] : -a[j]);

            }

            if (calc == 7) {
                sign = i;
                break;
            }
        }

        System.out.print(a[0]);
        for (int i = 1; i < 4; i++) {
            if (((sign >> (i - 1)) & 1) == 0) {
                System.out.print('+');
            } else {
                System.out.print('-');
            }
            System.out.print(a[i]);
        }
        System.out.println("=7");
    }
}

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

using namespace std;

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

  vector<int> a(n);
  int s = 1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] & 1) continue;
    s *= 2;
  }

  cout << (int)pow(3, n) - s << endl;

  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <string>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

vector<set<int> > graph;
vector<int> visited;
int sz;

void dfs(int u) {
	if (!visited[u]) {
		visited[u] = 1;
		++sz;
	}

	for (auto v : graph[u]) {
		if (!visited[v]) {
			dfs(v);
		}
	}
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

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

	graph = vector<set<int> > (n + 1, set<int> ());
	int u, v;
	for (int i = 0; i < m; ++i) {	
		cin >> u >> v;
		graph[u].insert(v);
		graph[v].insert(u);
	}

	visited = vector<int> (n + 1);
	int groups = 0;
	for (int i = 1; i <= n; ++i) {
		sz = 0;
		if (!visited[i]) {
			dfs(i);
		}

		groups = max(groups, sz);
	}

	cout << groups << "\n";

	return 0;

}

Measured memory_bytes: 38128
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>

using std::cin;
using std::cout;
using std::endl;

using std::vector;

using std::abs;
using std::min;
using std::max;

int main() {
    int n, z, w;
    cin >> n >> z >> w;

    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    a.push_back(z);
    a.push_back(w);

    vector<vector<vector<int>>> dp(
        2, vector<vector<int>>(n, vector<int>(n + 2, 0)));

    for (int t = 0; t <= 1; t++) {
        for (int j = 0; j < n + 2; j++) {
            dp[t][n - 1][j] = abs(a[n - 1] - a[j]);
        }
    }

    for (int i = n - 2; i >= 0; i--) {
        for (int t = 0; t <= 1; t++) {
            int tmp_max = dp[1][i+1][i];
            for (int k = i; k < n - 1; k++) {
                tmp_max= max(tmp_max, dp[1][k+1][k]);
            }
            int tmp_min = dp[0][i+1][i];
            for (int k = i; k < n - 1; k++) {
                tmp_min = min(tmp_min, dp[0][k+1][k]);
            }
            for (int j = 0; j < n + 2; j++) {
                int m;
                if (t == 0) {
                    m = max(tmp_max, abs(a[n - 1] - a[j]));
                } else {
                    m = min(tmp_min, abs(a[n - 1] - a[j]));
                }
                dp[t][i][j] = m;
            }
        }
    }

    cout << dp[0][0][n+1] << endl;
    return 0;
}


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

int main(){
        double a;
        double sum;
        while(cin >> a){
                sum = 0;
                for(int i = 1; i <= 10; i++){
                        sum += a;
                        if(i % 2 == 0){
                                a /= 3;
                        } else{
                                a *= 2;
                        }
                cout << setprecision(10);
                }
                cout << sum << endl;
        }
        return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  ll n;
  bool b=true;
  cin >> n;
  ll nowx=0,nowy=0,nowt=0;
  rep(i,n){
    ll t,x,y;
    cin >> t >> x >> y;
    if(!(abs(x-nowx)+abs(y-nowy)<=t-nowt&&((t-nowt)-abs(x-nowx)-abs(y-nowy))%2==0)){
      b=false;
    }
    nowx=x;nowy=y;nowt=t;
  }
  if(b){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

using namespace std;

//�����Ȃ�P�A�����Ȃ�O���o��
int is_integer(double a){
  int  b = a;
  if(a-b==0){
    return 1;
  }
  else{
    return 0;
  }}
int main(){
long long int A,B;
  cin >>A>>B;
  double ans;
  ans=(double)(B*B-A*A)/(2*(B-A));
  if(is_integer(ans)==1)
    cout<<(long long int)ans<<endl;
  else
    cout<<"IMPOSSIBLE"<<endl;
    



  
  return 0;
}


Measured memory_bytes: 256
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

n, m = map(int, input().split())
s = input()
t = input()
d = dict()
f = True

g = lcm(n, m)
nn = g // n
mm = g // m

for i in range(n):
    d[1 + nn * i] = s[i]

for i in range(m):
    if 1+mm*i in d:
        if d[1+mm * i] != t[i]:
            f = False
if f:
    print(g)
else:
    print(-1)

Measured memory_bytes: 81516
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a, b, n;
  in(n);
  vector<ll> c(n), d(n, 0);
  a = 0;
  rep(i, n){
    in(b);
    c[i] = b - 1;
  }
  b = 0;
  while(true){
    if(d[b] == 1){
      out(-1);
      memi;
      return 0;
    }
    else{
      d[b] = 1;
      a++;
      b = c[b];
    }
    if(b == 1)
      break;
  }
  out(a);
  memi;
}

Measured memory_bytes: 1920
h,w,m=list(map(int,input().split()))
s=[]
t=[]

for i in range(m):
  H,W=list(map(int,input().split()))
  s.append(H)
  t.append(W)
  
from collections import Counter
u=Counter(s)
v=Counter(t)
max_u=max(u.values())
max_u_set = set([kv[0] for kv in u.items() if kv[1]==max_u])
max_v=max(v.values())
max_v_set = set([kv[0] for kv in v.items() if kv[1]==max_v])
check=len(max_u_set)*len(max_v_set)

ans=0
for i in range(m):
  if u[s[i]]==max_u and v[t[i]]==max_v:
    ans=ans+1

if check-ans==0:
  print(max_u+max_v-1)
else:
  print(max_u+max_v)
    

Measured memory_bytes: 182500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF = 1e18+18;
const ll MAX = 100005;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;


int main(){
    int A, B, C;
    cin>>A>>B>>C;
    if(A==B){
        Yes(!(B==C));
    }
    else{
        Yes(B==C||A==C);
    }
    
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using ll = long long;
using namespace std;

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  for (int i = 1; i <= n; i++) {
    ans *= i;
    ans %= (ll)1e9+7;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = INT32_MAX;
const ll INFL = INT64_MAX;
const int mod = 1e9;

template <typename T>
void print_vec(vector<T> v) {
  for (T i : v) cout << i << " ";
  cout << endl;
}

int main() {
  string s;
  cin >> s;
  sort(s.begin(), s.end());
  if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256