akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <map>
#define int long long

using namespace std;

const int mod=1000000007;

char str[12][100];

signed main()
{
    int n;
    scanf("%lld",&n);
    for(int i=0; i<2; i++)
    {
        scanf("%s",str[i]);
    }
    bool flag=false;
    int f=0;
    int t=1;
    for(int i=0; i<n; i++)
    {
        if(str[0][i]==str[0][i+1])
        {
            if(f==0)
            {
                t*=3;
                t*=2;
                f=1;
            }
            else
            {
                if(flag)
                {
                    t*=2;
                    t*=1;
                }
                else
                {
                    t*=3;
                }
            }
            flag=false;
            i++;
        }
        else
        {
            if(str[0][i]==str[1][i])
            {
                if(f==0)
                {
                    t*=3;
                    f=1;
                }
                else
                {
                    if(flag) t*=2;
                    else t*=1;
                }
                flag=true;
            }
        }
        t%=mod;
    }
    cout<<t<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()
Q = int(input())
k_list = list(map(int, input().split()))

M_cum = [0] * (N+1)
for i in range(1, N+1):
    M_cum[i] = M_cum[i-1] + (S[i-1] == 'M')

for q in range(Q):
    k = k_list[q]
    ans = 0
    lose_D = [0] * N
    current_D = 0
    current_DM = 0
    for i in range(N):
        if lose_D[i] == 1:
            current_D -= 1
            current_DM -= (M_cum[i] - M_cum[i-k+1])
        if S[i] == 'D':
            current_D += 1
            if i + k < N:
                lose_D[i+k] = 1
        elif S[i] == 'M':
            current_DM += current_D
        elif S[i] == 'C':
            ans += current_DM
    print(ans)


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

int main(){
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    int ans = 0;
    for(int i = 0; i <= A; i++){
        for(int j = 0; j <= B; j++){
            for(int k = 0; k <= C; k++){
                if(i * 500 + j * 100 + k * 50 == X){
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

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

    if(a == b && b == c){
        if(a % 2 == 0 && b % 2 == 0 && c % 2 == 0){
            cout << -1 << endl;
        }else{
            cout << 0 << endl;
        }
    }else{
        ll count = 0;
        while(a % 2 == 0 && b % 2 == 0 && c % 2 == 0){
            count++;
            ll a1, b1, c1;
            a1 = b / 2 + c / 2;
            b1 = a / 2 + c / 2;
            c1 = a / 2 + b / 2;

            a = a1;
            b = b1;
            c = c1;
        }
        cout << count << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long  gcd( long long  a ,long long   b)
{
   if(b==0) return a;
   a%=b;
   return gcd(b,a);
}
long long findGCD(vector<long long >v)
{
    long long result = v.front();
    for (long long  i = 1; i < v.size(); i++)
        result = gcd(v[i], result);

    return result;
}
int main()
{
	long long n,X,x;
	cin>>n>>X;
	vector<long long >v;
	for(int i=0;i<n;i++)
    {
        cin>>x;
        v.push_back(abs(X-x));
    }
    if(findGCD(v)>1)
        cout<<findGCD(v)<<endl;
    else
        cout<<"1"<<endl;

return 0;
}


Measured memory_bytes: 1908
import sys

n = int(input())
p = list(map(int, input().split()))

pp = [i for i in range(1, n+1)]
cnt = 0

for i in range(n):
  if p[i] != pp[i]:
    cnt += 1
  if cnt > 2:
    print('NO')
    sys.exit()

print('YES')

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

int main(){
    int n,x,y;
    cin>>n>>x>>y;
    x--;
    y--;

    vector<int> cnt(n,0);
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            cnt[min(abs(j-i),min(abs(x-i)+1+abs(j-y),abs(y-i)+1+abs(j-x)))]++;
        }
    }
    for(int i=1;i<n;i++) cout<<cnt[i]<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>
int main(){
	int a, b, h, m;
	std::cin >> a >> b >> h >> m;

	double alpha = (double)h * 2. * M_PI / 12. + 5. * 2. * M_PI * (double)m / 3600.;
	double beta = (double)m * 2. * M_PI / 60.;
	double xa = (double)a * cos(alpha);
	double ya = (double)a * sin(alpha);
	double xb = (double)b * cos(beta);
	double yb = (double)b * sin(beta);

	double d = sqrt((xa - xb) * (xa - xb) + (ya - yb) * (ya - yb));

	std::cout << std::fixed << std::setprecision(15) << d << std::endl;

	return 0;
}


Measured memory_bytes: 4160
#include <iostream>
#include <algorithm>
#include <string>
#define rep(a,i,n) for(int i=(a);i<(n);i++)

using namespace std;

int main(){
	int n,tmp=0;
	cin >> n;
	string s[n];
	rep(0,i,n){
		cin >> s[i];
	}
	sort(s,s+n);
	rep(0,i,n-1){
		if(s[i] == s[i+1])
			tmp++;
	}
	cout << n-tmp << endl;
}

Measured memory_bytes: 9828
#include <stdio.h>

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


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

int main() {
	int N = 0;
	int M = 0;
	int a[10000] = { 0 };
	int b[10000] = { 0 };
	int n = 0;
	string fire;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < N - 1; i++) {
		for (int j = 0; j < N-i; j++) {
			if (a[j] < a[j + 1]) {
				n = a[j];
				a[j] = a[j + 1];
				a[j + 1] = n;
			}
		}
	}
	for (int i = 1; i < N+1; i++) {
		if (i % 2 == 0) {
			M -= a[i-1];
		}
		else {
			M += a[i-1];
		}
	}
	cout << M;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define int long long
  #define all(v) v.begin(),v.end()
  #define rep(i,a,b) for(int i = a; i <=b; i++)
  #define rep2(i,a,b) for(int i = a; i>=b; i--)
  
  #define f first
  #define s second
  #define PB push_back
  #define MP make_pair
  #pragma comment(linker, "/STACK:2000000")
  #pragma comment(linker, "/HEAP:2000000")
  #define db long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  #define MOD 1000000007
  bool fun(int n)
  {
    int ans=0;
    while(n)
    {
      ans++;
      n/=10;
    }
    return bool(ans%2);

  }
  int32_t main()
  {        
    IOS  
    int n;
    cin>>n;
    int arr[n+1];
    rep(i,1,n)
    {
      cin>>arr[i];
    }
    rep2(i,n,2)
    {
      if(arr[i]<arr[i-1])
      {
        if(arr[i-1]-arr[i]>1)
        {
          cout<<"No";
          return 0;
        }
        else
        {
          arr[i-1]--;
        }

      }
    }

    cout<<"Yes";
    return 0;
} 

Measured memory_bytes: 1024
N = int(input())
A = list(map(int,input().split()))
check = []
every = 0

for a in A:
    if a < 400:
        check.append(1)
    elif a < 800:
        check.append(2)
    elif a < 1200:
        check.append(3)
    elif a < 1600:
        check.append(4)
    elif a < 2000:
        check.append(5)
    elif a < 2400:
        check.append(6)
    elif a < 2800:
        check.append(7)
    elif a < 3200:
        check.append(8)
    else:
        every += 1
length = len(set(check))
if length == 0:
    length = 1
    every -= 1

print(length,length+every)

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

int N;
vector<int> h;
queue<int> zero;

int resMin(int a, int b){      //配列hにおける番号a以上b未満の範囲の最小値
  int mi = h[a];
  for(int i = a+1; i < b; i++)
    mi = min(mi, h[i]);

  return mi;
}

int main(){
  int count = 0;
  cin >> N;
  
  for(int i = 0; i < N; i++){
    int val;
    cin >> val;
    h.push_back(val);

    if(val == 0)
      zero.push(i);                     //0の位置を取得
  }

 while(zero.size() != N){       //下げていった高さ0の花の数がNに等しくない限り
    int b = -1; int e;                     //一回の作業で少なくとも0は一つは増える
    while(!zero.empty()){      
      e = zero.front();
      int min = resMin(b+1, e);       //b+1以上e未満の番号の範囲での最小値

      for(int i = b+1; i < e; i++)
        h[i] -= min;                                   //当該範囲の値すべてから当該範囲における最小値を引く

      zero.pop();                          //0の位置情報を削除(処理が終わったので)
      b = e;
      count += min;                             //引いた分だけ水やりを行っていたということ
    }
    
    int min = resMin(b+1, N);        //最後の0の位置から配列の末尾までの処理は別途
    for(int i = b+1; i < N; i++)
      h[i] -= min;
    count += min;
  

    for(int i = 0; i < N; i++){      //処理後の0の位置を再び取得
      if(h[i] == 0)
        zero.push(i);
    }
  }

  cout << count << endl;
  return 0;
        
}

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

# define ll long long

int operate(int a, int b, char op) {
	if(op == '+') {
		return a + b;
	}
	return a - b;
}

string getFormula(int a, int b, int c, int d, string s) {
	if(s.length() == 3) {
		int first = operate(a, b, s.at(0));
		int second = operate(first, c, s.at(1));
		int sum = operate(second, d, s.at(2));
		if(sum == 7) {
			return s;
		}
		else {
			return "";
		}
	}
	string firstFor = getFormula(a, b, c, d, s + "+");
	string secondFor = getFormula(a, b, c, d, s + "-");
	if(firstFor == "") {
		return secondFor;
	}
	return firstFor;
}

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

	int a = n.at(0) - '0';
	int b = n.at(1) - '0';
	int c = n.at(2) - '0';
	int d = n.at(3) - '0';

	string output = getFormula(a, b, c, d, "");

	string last = "";
	for(int i = 0; i < 4; i++) {
		last += n.at(i);
		if(i != 3) {
			last += output.at(i);
		}
	}
	cout << last << "=7";
	
	return 0;
}

Measured memory_bytes: 256
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}
var mod = 1e9+7;

console.log(main());
function main(){
  var n = o.a();
  var m = o.a();
  var a = o.r(m);
  var dp = xArray(0,n+1);
  dp[0] = 1;
  var x = 0;
  if(a[x] === 1)x++; else dp[1] = 1;
  for(var i = 2; i <= n; i++){
    if(a[x] === i)x++;
    else dp[i] = (dp[i-1]+dp[i-2])%mod;
  }
  return dp[n];
}

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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

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

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

  map<int,int> mp;
  FOR(j,2,n+1){
    int k = j;
    FOR(i,2,sqrt(j)+1){
      while(k%i == 0){
	mp[i]++;
	k /= i;
      }
    }
    if(k != 1) mp[k]++;
  }
  dump(mp);

  int res = 0;
  int a, b;
  a = b = 0;
  for(auto x : mp){
    if(2 <= x.second) a++;
    if(4 <= x.second) b++;
  }
  dump(a,b);
  res += b*(b-1)*(a-2)/2;

  a = b = 0;
  for(auto x : mp){
    if(4 <= x.second) a++;
    if(14 <= x.second) b++;
  }
  res += b*(a-1);
  
  a = b = 0;
  for(auto x : mp){
    if(2 <= x.second) a++;
    if(24 <= x.second) b++;
  }
  res += b*(a-1);

  a = 0;
  for(auto x : mp){
    if(74 <= x.second) a++;
  }
  res += a;

  cout << res << endl;
}

Measured memory_bytes: 256
use strict;
use warnings;
use utf8;

# 11:23 - 

my ($N) = split /\s/, <STDIN>;

my @d;
for (1 .. $N) {
    my ($x) = split /\s/, <STDIN>;
    push @d, $x;
}

@d = sort {$b <=> $a} @d;

my @ret;
my $max = 101;
foreach my $d (@d) {
    if ($d < $max) {
        push @ret, $d;
        $max = $d;
    }
}

use Data::Dumper;
print Dumper \@d if $ENV{X};
printf "%s\n", scalar @ret;


Measured memory_bytes: 1920
N, Y = map(int, input().split())

ans = [-1,-1,-1]
for i in range(N+1):
    for j in range(N+1):
        # tmp_sum = 10000 * i + 5000 * j
        # x = Y - tmp_sum
        # if x >= 0:
        #     k = int(x//1000)
        #     if i + j + k == N:
        #         ans = [i, j, k]
        k = N - i - j
        if k >= 0:
            if 10000 * i + 5000 * j + 1000 * k == Y:
                ans = [i, j, k]


print(" ".join([str(i) for i in ans]))


Measured memory_bytes: 41068
#include <iostream>

using namespace std;
long long a[100000],f[3000][3000];
int n;
long long qhd(int tt,int i,int j){
    if (i==j) {
        if (tt==1) return a[i];
        else return 0;
    }
    else{
    if (tt==1){
        if (f[i][j]==0){
            f[i][j]=max(qhd(tt^1,i+1,j)+a[i],qhd(tt^1,i,j-1)+a[j]);
        }
        return f[i][j];
    } else {
        if (f[i][j]==0){
            f[i][j]=min(qhd(tt^1,i+1,j),qhd(tt^1,i,j-1));
        }
        return f[i][j];
        }
    }
}
int main()
{
    long long sum=0,o;
    cin>>n;
    for (int i=0;i<n;++i){ cin>>a[i]; sum+=a[i];}
    o=qhd(1,0,n-1);
    cout<<2*o-sum;
}


Measured memory_bytes: 70144
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

ll n,x,ans=0;

template <class T>
void gcd(T a,T b) {
  if(a<b) swap(a,b);
	if (b==0){
    ans-=a;
	}else{
    ans+=a/b*b*2;
    gcd(b,a%b);
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n>>x;
  ans=n;
  gcd(x,n-x);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long int ll;
const int N = 1000000;
const int INF = 1 << 30;
#define rep(i,n) for(int i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
string YN(bool b) { return(b ? "YES" : "NO"); }
string yn(bool b) { return(b ? "Yes" : "No"); }
ll h, w, v[110][110],ct=0;
int main(){
	ll n,n2, ct = 1;
	cin >> n;
	n2 = n;
	while (n2 >= 10){++ct; n2 /= 10;}
	if (n % (ll)pow((ll)10, ct - 1) == pow(10, ct - 1) - 1)cout << 9 * (ct - 1) + n / (ll)pow((ll)10, ct - 1) << endl;
	else cout << 9 * (ct - 1) + n / (ll)pow((ll)10, ct - 1)-1 << endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
string s;
cin >> s;
sort(all(s));
if (s=="abc") cout << "Yes" << endl;
else cout << "No" << endl;
}


Measured memory_bytes: 256
def main():
    H1, M1, H2, M2, K = (int(i) for i in input().split())
    h = H2 - H1
    m = M2 - M1
    ans = h*60 + m - K
    if ans > 0:
        print(ans)
    else:
        print(0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61796
# coding:utf-8

import sys
from collections import Counter


input = sys.stdin.readline


def inpl(): return list(map(int, input().split()))


# Counterを使ったD - Candy Distributionの解法
def solve(N, M, A):
    # 累積和S (mod M)を求める
    S = [0]
    for i in range(N):
        S.append((S[-1] + A[i]) % M)

    ans = 0
    # 各要素の個数を数える
    for v in Counter(S).values():
        # v個から2個選ぶ組み合わせ
        ans += v * (v - 1) // 2

    return ans


N, M = inpl()
A = inpl()
print(solve(N, M, A))


Measured memory_bytes: 17284
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void push(int);
int pop();

int top,S[1000];

int main(){
  int x,y;
  top=0;
  char a[100];

  while(scanf("%s",a)!=EOF){
    
    if(a[0]=='+'){
      x = pop();
      y = pop();
      push(x+y);
    }else if(a[0]=='-'){
      y = pop();
      x = pop();
      push(x-y);
    }else if(a[0]=='*'){
      x = pop();
      y = pop();
      push(x*y);
    }else{
      push(atoi(a));
    }
  }
  printf("%d\n",pop());
  return 0;
}

void push(int c){
  S[++top]=c;
}

int pop(){
  top--;
  return S[top+1];
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
#include <fstream>
#include <iostream>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define maxim INT_MAX
#define fi first
#define se second
#define INF 1e16
#define mod 1000000007
/* 1. If you can't keep solution in mind, then visualize it on a paper.
 * 2. Try to identify the type of problem - DP, Greedy, Graph, Constructive,
 * 	  Prefix/Suffix, Difference Array, BIT/Segment Tree, etc.
 * 3. Look at the problems from different perspectives - reverse the problem,
 * 	  add instead of delete (maybe?)
 * 4. Divide difficult solutions into cases and/or sequences.
 * 5. Use math rules to solve Nested Summation.
 * 6. Optimisation problems are generally solved with DP, greedy, binary search or brute-force.
 * 7. Try fixing a solution then proving we can't do better or worse than that.
 * ------------------------------------------------------------------
 */
int main()
{
   ll n,m;
   cin>>n>>m;
   ll dp[n+1][m+1];
   memset(dp,0,sizeof(dp));
   char ar[n][m];
   for(ll i=0;i<n;i++)
    cin>>ar[i];
   for(ll i=1;i<=m;i++)
   {
       if(ar[0][i-1]!='#')
       dp[1][i]=1;
       else
        break;
   }
   for(ll i=1;i<=m;i++)
   {
       if(ar[i-1][0]!='#')
       dp[i][1]=1;
       else
        break;
   }
   for(ll i=2;i<=n;i++)
   {
       for(ll j=2;j<=m;j++)
       {
           if(ar[i-1][j-1]!='#')
           {
               dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
           }
       }
   }
   cout<<dp[n][m]<<endl;
}


Measured memory_bytes: 12428
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define se second
#define fi first
#define rep(i, l, r) for (ll i = (ll)(l); i < (ll)(r); i++)
#define print(v) for (const auto itr : v){cout << itr << ' ';} cout << endl;
#define mod 1000000007
#define inf 1e18
using namespace std;
const ll INF = 1e18L + 5;
const ll maxn = 1e5*2+5, maxn1=202;
ll ceel(ll a, ll b)
{
   if (a % b == 0)
       return a / b;
   return a / b + 1;
}
ll modneg(ll a,ll m)
{
    a = a % m;
    if(a<0)
        a=a+m;
    return a;
}
ll powermod(ll x, unsigned ll y, ll p){ll res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); };

int main()
{

ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n,i,j;
double s,r;
cin>>r;
s=22.0/7.0;
s=s*2.0*r;
cout<<fixed << setprecision(6) << s;
return 0;
}


Measured memory_bytes: 3756
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
static inline char GET(void)
{
  static char buf[1<<22],*s1=buf,*s2=buf;
  return s1==s2&&(s2=(s1=buf)+fread(buf,1,1<<22,stdin),s1==s2)?EOF:*s1++;
}
static inline void PUT(char c)
{
  static char buf[1<<15],*ptr=buf;
  if(ptr==buf+strlen(buf)||c==0){fwrite(buf,1,ptr-buf,stdout),ptr=buf;}*ptr++=c;
}
static inline int IN(void)
{
  int x=0,f=0,c=GET();while(c<48||c>57){f^=c==45,c=GET();}
  while(c>47&&c<58){x=x*10+c-48,c=GET();}return f?-x:x;
}
static inline void OUT(int a)
{
  if(a<0)PUT('-'),a=-a;
  int d[40],i=0;do{d[i++]=a%10;}while(a/=10);
  while(i--){PUT(d[i]+48);}PUT('\n');
}
static inline int Max(int x,int y){return x>y?x:y;}
int main(void)
{
  int H=IN(),W=IN(),M=IN(),row[H],col[W],bombY[M],bombX[M],
      idh=0,idw=0,hmax=0,wmax=0,obj=0;
  memset(row,0,sizeof(row));memset(col,0,sizeof(col));
  rep(i,M)
  {
    bombY[i]=IN()-1,bombX[i]=IN()-1;
    row[bombY[i]]++;col[bombX[i]]++;
    hmax=Max(hmax,row[bombY[i]]);wmax=Max(wmax,col[bombX[i]]);
  }
  rep(i,H){if(hmax==row[i]){idh++;}}rep(j,W){if(wmax==col[j]){idw++;}}
  rep(i,M){obj+=(row[bombY[i]]==hmax&&col[bombX[i]]==wmax);}
  return OUT(hmax+wmax-(1l*obj==1l*idh*idw)),0;
}

Measured memory_bytes: 10104
import java.util.*;

//update 2020/1/1 23:01

public class Main{

  static Scanner sc = new Scanner(System.in);
  static StringBuilder sb = new StringBuilder();

  public static void main(String[] args) {

    int n = nextInt();
    int m = nextInt();
    int[] a = new int[n];
    int sum = 0;
    for(int i=0;i<n;i++){
      a[i] = nextInt();
      sum += a[i];
    }

    Arrays.sort(a);

    for(int i=0;i<n/2;i++){
      int tmp = a[i];
      a[i] = a[n-i-1];
      a[n-i-1] = tmp;
    }

    if(a[m-1]*4*m>=sum){
      System.out.println("Yes");
    }
    else{
      System.out.println("No");
    }


    //System.out.println();

  }
  /*
    static String toSmall(String s){
      char c = s.charAt(0);
      //if(Character.isUpperCase(c)){
      if(c<=90){
        c += 32;
      }
      return String.valueOf(c);
    }
    static String toBig(String s){
      char c = s.charAt(0);
      //if(Character.isLowerCase(c)){
      if(c>=97){
        c -= 32;
      }
      return String.valueOf(c);
    }
  */

  static String toSmall(String s){
    return s.toLowerCase();
  }

  static String toBig(String s){
    return s.toUpperCase();
  }

  static String next(){
    return sc.next();
  }

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

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

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

  static String[] splitString(String s){
    return s.split("");
  }

  static char[] splitChar(String s){
    return s.toCharArray();
  }

  static int charToInt(char a){
    return a - 48;
  }

////////////////////////////////////////////
  public static int max(int[] a){
    int lng = a.length;
    int max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
  public static long max(long[] a){
    int lng = a.length;
    long max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
////////////////////////////////////////////

////////////////////////////////////////////
  public static int min(int[] a){
    int lng = a.length;
    int min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
  public static long min(long[] a){
    int lng = a.length;
    long min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
////////////////////////////////////////////

}


Measured memory_bytes: 23124
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const int INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()

string s, t;
const int STR_MAX = 3001;
int dp[STR_MAX][STR_MAX];

int main() {
    cin >> s >> t;
    rep(i, s.size()) {
        rep(j, t.size()) {
            if(s[i] == t[j]) {
                dp[i + 1][j + 1] = dp[i][j] + 1;
            }else {
                dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
            }
        }
    }
    string ans = "";
    int i = s.size(), j = t.size();
    while(i > 0 && j > 0) {
        if(dp[i - 1][j] == dp[i][j]) --i;
        else if(dp[i][j - 1] == dp[i][j]) --j;
        else ans = s[i - 1] + ans, --i, --j;
    }
    cout << ans << endl;
}


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

int main()
{
	int x;
	int a[6] = { 500, 100, 50, 10, 5, 1 };

	cin >> x;

	while (x > 0) {
		int n = 1000 - x, m = n / 500;

		for(int i = 0; i < 5; i++)
			m += (n % a[i]) / a[i + 1];

		cout << m << endl;

		cin >> x;
	}

	return 0;
}



Measured memory_bytes: 3084
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
    int n,x=0,y=0,a=0,b=0,t=0,s1=0,s2=0,tl=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>t>>a>>b;
        tl=t-tl;
        if(x>=a) s1=x-a;
        else s1=a-x;
        if(y>=b) s2=y-b;
        else s2=b-y;
//        cout<<s1<<s2;
        if((tl-s1-s2)%2!=0||(tl-s1-s2<0)) {cout<<"No";return 0;}
        x=a;
        y=b;
        tl=t;
    }
    cout<<"Yes";
//    system("Pause");
    return 0;
}


Measured memory_bytes: 256
r,g,b,n=map(int,input().split())
ans=0
for i in range(n+1):
  if(r*i>n):
    break
  for j in range(n+1):
    t=r*i+g*j
    if(t>n):
      break
    if((n-t)%b==0):
      ans+=1
print(ans)

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

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

typedef long long ll;

int main() {
    int MAX_M = 1000003;
    int s; cin>>s;
    int a[MAX_M];
    rep(i,MAX_M) a[i]=0;
    
    a[s]=1;
    
    int ans;
    
    rep(i,MAX_M){
        if(s % 2 == 1)s = 3*s +1;
        else s/=2;
        
        ++a[s];
        if(a[s]==2){
            ans = i+2;
            break;
        }
    }
    cout<<ans<<endl;
	return 0;
}

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

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

int gcd(int x, int y) {
	if(y == 0) return x;
	else return gcd(y, x % y);
}

int main() {
	long long n, m; cin >> n >> m;
	string s, t; cin >> s >> t;
	long long l = n / gcd(n, m) * m;

	long long a = l / n, b = l / m;
	long long c = a / gcd(a, b) * b;

	long long i = 0;
	bool ok = true;
	while (i < l)
	{
		if(s[i / a] != t[i / b]) ok = false;
		i += c;
	}

	if(ok) cout << l << endl;
	else cout << "-1" << endl;
	return 0;
}


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

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input = br.readLine();

        int[][][] house = new int[4][3][10];

//      ???????????¨????????¨?±?????????°???0
        for(int i = 0; i < 4; i++){
            for(int j = 0; j < 3; j++){
                for(int k = 0; k < 10; k++){
                    house[i][j][k] = 0;
                }
            }
        }

//      ????????????????????±?????°n
        int n = Integer.parseInt(input);

        for(int i = 0 ; i < n; i++){
            input = br.readLine();
            String[] strArray = input.split(" ");

            int building = Integer.parseInt(strArray[0]) -1;    //?£?
            int floor = Integer.parseInt(strArray[1]) -1;       //???
            int room = Integer.parseInt(strArray[2]) -1;        //?????????
            int resident = Integer.parseInt(strArray[3]);      //?????°

            house[building][floor][room] += resident;
        }

//      ??????
        for(int i = 0; i < 4; i++){
//          ?£??????????
            if(i != 0){
                System.out.println("####################");
            }
                for(int l = 0; l < 3; l++){
                    for(int k = 0; k < 10; k++){
                        System.out.print(" ");
                        System.out.print(house[i][l][k]);
                    }
                    System.out.println();
                }
        }
    }
}

Measured memory_bytes: 24836
#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::fastout;
use proconio::input;
use proconio::marker::Usize1;
// use std::cmp::max;
// use std::cmp::min;
// use std::collections::HashMap;
// use std::collections::VecDeque;

// 自力で解こうとしたがうまくいかなかったので答えを見た
// 2次元累積和を使うO(Q + N^2)解法

#[fastout]
fn main() {
    input! {
        N: usize,
        M: usize,
        Q: usize,
        LRs: [(Usize1, Usize1); M],
        PQs: [(Usize1, Usize1); Q],
    }

    // O(10^5)のループの内側でクエリに回答する
    // つまり、クエリへの回答はO(1)でできる必要がある (← 注: これ嘘です。10^7までは食えるので今回はO(NQ)までいけます)
    // ある「領域」に属する個数の総和を高速で求める → 累積和
    // ここで、領域は幅を持っている → 2次元累積和

    // imos[l][r] : 「[0, l),[0, r) の区間に含まれる電車の数」
    let mut acc: Vec<Vec<i64>> = vec![vec![0i64; N + 1]; N + 1];

    for &(l, r) in LRs.iter() {
        acc[l + 1][r + 1] += 1;
    }

    // 横方向の和
    for l in 0..N + 1 {
        for r in 1..N + 1 {
            acc[l][r] += acc[l][r - 1];
        }
    }

    // 縦方向の和
    for r in 0..N + 1 {
        for l in 1..N + 1 {
            acc[l][r] += acc[l - 1][r];
        }
    }

    for &(p, q) in PQs.iter() {
        // ループの中はほぼO(1)じゃないと間に合わない (← 注: これ嘘です。10^7までは食えるので今回はO(NQ)までいけます)
        // 区間、O(1)と来れば累積和でしょう

        let ans = acc[q + 1][q + 1] - acc[q + 1][p] - acc[p][q + 1] + acc[p][p];
        println!("{}", ans);
    }
}


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

int main(){
	int k,a,b;
	cin >> k >> a >> b;
	bool ok = false;
	for (int i = a; i <= b; ++i) {
		if(i % k == 0) ok = true;
	}
	if(ok){
		cout << "OK" << endl;
	}else{
		cout << "NG" << endl;
	}
    return 0;
}



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

//素数判定
bool isPrime(int num){
  if (num < 2) return false;
  else if (num == 2) return true;
  else if (num % 2 == 0) return false;
  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2){
    if (num % i == 0) return false;
  }
  return true;
}

int main(){
  ll n,m;
  cin >> n >> m;
  
  vector<bool> ok(n);
  vector<int> pena(n);
  rep(i,n) ok[i] = false;
  rep(i,n) pena[i] = 0;
  
  int penalty = 0;
  int answer = 0;
  rep(i,m){
    int p; string s;
    cin >> p >> s;
    if(!ok[p-1] && s == "WA"){
      pena[p-1]++;
    }
    if(!ok[p-1] && s == "AC"){
      penalty += pena[p-1]; //ACが出ない限りペナルティ数は数えても意味無し
      answer++;
      ok[p-1] = true;
    }
  }
  
  cout << answer << " " << penalty << endl;
}

Measured memory_bytes: 3864
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#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>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;

ll dp[1010][1010];

int main(int argc, char const *argv[]) {
    int h,w;
    cin >> h >> w;
    vector<vector<char>> a(h, vector<char>(w));
    REP(i,h) REP(j,w) cin >> a[i][j];
    memset(dp, 0, sizeof(dp));
    REP(i,h) {
        if (a[i][0] == '.') dp[i][0] = 1;
        else break;
    }
    REP(j,w) {
        if (a[0][j] == '.') dp[0][j] = 1;
        else break;
    }

    for(int i = 1; i < h; ++i) {
        for (int j = 1; j < w; ++j) {
            if (a[i][j] == '#') dp[i][j] = 0;
            else dp[i][j] = (dp[i-1][j]+dp[i][j-1])%MOD;
        }
    }

    cout << dp[h-1][w-1] << endl;
    return 0;
}

Measured memory_bytes: 9216
#include<iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <tuple>
#include <cmath>
#include <queue>
#include <map>


using namespace std;


int main()
{
  long n;
  cin >> n;
  long res = n;

  for (int i = 0; i < n+1; i++) {
    int temp = 0;
    int t6 = i;
    while (t6 > 0) {
      temp += t6 % 6;
      t6 /= 6;
    }
    int t9 = n - i;
    while (t9 > 0) {
      temp += t9 % 9;
      t9 /= 9;
    }
    if (res > temp)res = temp;
  }

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{

    int n, m;
    cin >> n >> m;
    vector<int> a(n, -1);
    rep(i, m)
    {
        int s, c;
        cin >> s >> c;
        s--;
        if (a[s] == -1 || a[s] == c)
        {
            a[s] = c;
        }
        else
        {
            cout << -1 << endl;
            return 0;
        }
    }
    if (a[0] == 0 && n != 1)
    {
        cout << -1 << endl;
        return 0;
    }
    if (a[0] == -1 && n == 1)
    {
        a[0] = 0;
    }
    if (a[0] == -1)
    {
        a[0] = 1;
    }
    int ans = 0;
    rep(i, n)
    {
        if (a[i] == -1)
        {
            a[i] = 0;
        }
        ans += a[i] * pow(10, n - i - 1);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define NL            "\n"
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
int main()
{
    _SAD()
    int a,b;
    cin>>a>>b;
    cout<<max(a-b,max(a+b,a*b))<<NL;
    return 0;
}



Measured memory_bytes: 256
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer

object Main extends App {
  import scala.io.StdIn._


  val Array(w, h) = readLine.trim.split(' ').map(_.toInt)
  val rows = readLine.trim.split(' ').map(_.toInt)
  val columns = readLine.trim.split(' ').map(_.toInt)
  if (rows.sum == columns.sum){
    val (source, drain, nodes) = makeGraph(rows, columns)
    val maxFlow = calMaxFlow(nodes, source, drain)
    println(
      if (rows.sum == maxFlow) 1
      else 0
    )
  }else println(0)
  def makeGraph(row: Array[Int], column: Array[Int]): (Int, Int, Array[Array[Edge]]) = {
    val result = Array.tabulate(row.length + column.length + 2){_ ⇒ ArrayBuffer[Edge]()}
    val source = result.length - 2
    val drain = result.length - 1
    for (r ← row.indices){
      result(r).append(Edge(source, result(source).length,  0))
      result(source).append(Edge(r, 0, row(r)))
    }
    for (c ← column.indices.map(_ + row.length)) {
      result(c).append(Edge(drain, result(drain).length, column(c - row.length)))
      result(drain).append(Edge(c, 0, 0))
      for (r ← row.indices){
        result(c).append(Edge(r, result(r).length, 0))
        result(r).append(Edge(c, result(c).length - 1, 1))
      }
    }
    (source, drain, result.map(_.toArray))
  }
  def calMaxFlow(nodes: Array[Array[Edge]], source: Int, drain: Int): Int = {
    val depth = Array.tabulate(nodes.length){_ ⇒ -1}
    val searching = Array.tabulate(nodes.length){_ ⇒ 0}
    def bfs(): Unit = {
      depth.indices.foreach(i ⇒ depth(i) = -1)
      val queue = mutable.Queue[Int]()
      depth(source) = 0
      queue.enqueue(source)
      while (queue.nonEmpty){
        val current = queue.dequeue()
        for (Edge(next, _, flow) ← nodes(current) if flow > 0 && depth(next) == -1){
          depth(next) = depth(current) + 1
          queue.enqueue(next)
        }
      }
    }
    def dfs(current: Int): Boolean = {
      if (current == drain) true
      else {
        var i = searching(current)
        var found = false
        while(i < nodes(current).length && !found) {
          if (nodes(current)(i).flow > 0 && depth(nodes(current)(i).to) > depth(current)){
            found = dfs(nodes(current)(i).to)
            if (found){
              val Edge(to, pair, _) = nodes(current)(i)
              nodes(current)(i).flow -= 1
              nodes(to)(pair).flow += 1
            }
          }
          if (!found) i += 1
        }
        searching(current) = i
        found
      }
    }
    var count = 0
    var canPush = true
    while(canPush){
      bfs()
      searching.indices.foreach(i ⇒ searching(i) = 0)
      canPush = false
      while(dfs(source)){
        canPush = true
        count += 1
      }
    }
    count
  }
  case class Edge(to: Int, pair: Int, var flow: Int)
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def also(@inline func: T ⇒ Unit): T = {
      func(value)
      value
    }
    @inline
    def let[A](@inline func: T ⇒ A): A = func(value)
  }
}


Measured memory_bytes: 174580
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 100100100100100100;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main(){
    ll A,B,C;
    cin >> A >> B >> C;
    if((A < C && C < B) || (B < C && C < A)) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vi v; v.pb(1);
    int tmp=1;
    rep(i,6){
        tmp*=6;
        v.pb(tmp);
    }
    tmp=1;
    rep(i,5){
        tmp*=9;
        v.pb(tmp);
    }
    int sz=v.size();
    vi dp(n+1,INT_MAX);
    dp[0] = 0;
    rep(i,sz)rep(j,n+1){
        if (j>=v[i]) chmin(dp[j],dp[j-v[i]]+1);
    }
    cout<<dp[n]<<endl;
    return 0;
}


Measured memory_bytes: 640
/// Bismillahir Rahmanir Rahim
/* Mohammad Morsalin
   Dept of ICE, NSTU
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define int long long
#define f0(n) for(int i=0;i<n;i++)
#define ms(x) memset(x,0,sizeof(x))
#define ms2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pi pair<int,int>
#define tc(t) int t;cin>>t;while(t--)
#define bits(n) __builtin_popcount(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define ins insert
#define ALL(v) v.begin(),v.end()
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define fi first
#define se second
#define PI acos(-1)
#define sz(a) (int)a.size();
#define IOS ios::sync_with_stdio(false);
using namespace std;
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const long long MOD = 1000000007;
double sq(double x) {return x*x;}
template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}

bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}
signed main()
{
    IOS
    int x;
    cin>>x;
    if(x>=400 && x<600)cout << 8 << endl;
    if(x>=600 && x<800)cout << 7 << endl;
    if(x>=800 && x<1000)cout << 6 << endl;
    if(x>=1000 && x<1200)cout << 5 << endl;
    if(x>=1200 && x<1400)cout << 4 << endl;
    if(x>=1400 && x<1600)cout << 3 << endl;
    if(x>=1600 && x<1800)cout << 2 << endl;
    if(x>=1800 && x<2000)cout << 1 << endl;
    return 0;
}
///Alhamdulillah


Measured memory_bytes: 3652
r, c = map(int, input().split())
lis = [[] for a in range(r+1)]
for x in range(r):
    lis[x] = list(map(int, input().split()))
    lis[x].append(sum(lis[x]))
lis[r] = [0 for a in range(c+1)]
for y in range(c+1):
    for z in range(r):
        lis[r][y] += lis[z][y]
for x in lis:
    for z,y in enumerate(x):
        if z == c:
            print(y)
        else:
            print(y, end = " ")




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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> VECLL;
typedef vector<P> VECP;
typedef priority_queue<P,VECP,greater<P> > PQP;
typedef priority_queue<ll, VECLL, greater<ll> > PQll;

#define rep(i,a,n) for(ll i = a;i < n;i++)   
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

int main(){
    ll n;
    cin >> n;
    vector<ll> vec;
    ll n_cnt = 0,p_cnt = 0;

    rep(i,0,n){
        ll a;
        cin >> a;
        vec.push_back(a);

        if(a < 0) n_cnt++;
        else p_cnt++;
    }
    sort(vec.begin(),vec.end(),greater<ll>());

    if(n_cnt == n){
        n_cnt--; p_cnt++;
    }
    else if(p_cnt == n){
        p_cnt--; n_cnt++;
    }

    ll ans = 0;
    rep(i,0,n) ans += ((i < p_cnt)?vec[i]:-vec[i]);
    cout << ans << endl; 

    if(p_cnt == 1){
        ll temp = vec[0];
        rep(i,0,n-1){
            cout << temp << " " << vec[i+1] << endl;
            temp -= vec[i+1];
        }
    }
    else{
        cout << vec[n-1] << " " << vec[0] << endl;
        ll temp = vec[n-1] - vec[0];
        rep(i,0,p_cnt-2){
            cout << temp << " " << vec[1+i] << endl;
            temp -= vec[1+i]; 
        }
        cout << vec[p_cnt-1] << " " << temp << endl;
        temp = vec[p_cnt-1] - temp;
        rep(i,0,n_cnt-1){
            cout << temp << " " << vec[n-2-i] << endl;
            temp -= vec[n-2-i];
        }
    }

}




Measured memory_bytes: 4300
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N;
int64 dp[MAXN][3];
int64 A[MAXN];
char op[MAXN][5];
void update(int64 &x,int64 y) {
    x = max(x,y);
}
void Solve() {
    read(N);
    for(int i = 1 ; i <= N ; ++i) {
	read(A[i]);
	if(i != N) scanf("%s",op[i] + 1);
    }
    dp[1][0] = A[1];
    dp[1][1] = -1e18;
    dp[1][2] = -1e18;
    for(int i = 2 ; i <= N ; ++i) {
	for(int j = 0 ; j < 3 ; ++j) dp[i][j] = -1e18;
	for(int j = 0 ; j < 3 ; ++j) {
	    int t = (op[i - 1][1] == '-');
	    int k = (t ^ j) & 1;
	    int64 d = A[i];
	    if(k) d = -A[i];
	    if(t && j < 2) update(dp[i][j + 1],dp[i - 1][j] + d);
	    for(int h = 0 ; h <= j ; ++h) update(dp[i][h],dp[i - 1][j] + d);
	}
    }
    out(dp[N][0]);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 3840
import math
n = int(input())
# 4, 7
f = []
s = []
tmp = 0
ans = 0
a = math.floor(n/4)
b = math.floor(n/7)
cnt = 0
for i in range(a):
  f.append(4)
if (n % 4) == 0:
  cnt = 1
for i in range(0, len(f)):
  ans = (n-4*i) % 7
  if ans == 0:
    cnt = 1
    break
  ans = 0
if cnt == 1:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9132
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    if(a != b && b == c) cout << a << endl;
    else if(a == b && b != c) cout << c << endl;
    else if(c == a && b != a) cout << b << endl;
	return 0;
}



Measured memory_bytes: 384