akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define p pair<int,int>
#define P pair<ll,ll>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define db double
#define zero(a) memset(a,0,sizeof(a))
#define inff(a,n) fill(a,a+n+1,inf)
#define all(a) a.begin(),a.end()
#define sz(a) int((a).size())
#define read(x) scanf("%d",&x)
#define read2(x,y) scanf("%d%d",&x,&y)
#define write(x) printf("%d\n",x)

const int maxn=1e6;
const ll inf=1e9;
const int base1=31,base2=127;

int flag,sum1,sum2,flag1,flag2,ok,ans,ans1,ans2,a[maxn],b[maxn];

string s,s1,s2,t;

int main()
{
    cin>>s;
    int ans,n=s.size();
    for(int i=0;i<n;i++)
    {
        if(i+7==n-1&&s[i]=='F'&&s[i+1]=='E'&&s[i+2]=='S'&&s[i+3]=='T'&&s[i+4]=='I'&&s[i+5]=='V'&&s[i+6]=='A'&&s[i+7]=='L')
        {
            ans=i;
            break;
        }
    }
    for(int i=0;i<ans;i++)cout<<s[i];
    return 0;
}

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>;


int main() {
    int n, k;
    cin >> n >> k;
    vector<int> cnt(n);

    for(int i = 0; i < k; i++){
        int d;
        cin >> d;
        for(int j = 0; j < d; j++){
            int sunuke;
            cin >> sunuke;
            cnt[sunuke-1]++;
        }
    }

    int ans = 0;
    rep(i, n){
        if(cnt[i] == 0){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3628
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//大小比較(大)
long long int big(long long int a, long long int b) {
	if (a >= b) {
		return a;
	}
	else {
		return b;
	}
}

//大小比較(小)
long long int small(long long int a, long long int b) {
	if (a >= b) {
		return b;
	}
	else {
		return a;
	}
}

main() {
	long long int a=0,b=0,c=0,n, m, k = 0;
	char str[5];
	scanf("%s", str);

	if (str[0] == 'a') { a++; }

	if (str[1] == 'a') { a++; }
	
	if (str[2] == 'a') { a++; }
	
	if (str[0] == 'b') { b++; }

	if (str[1] == 'b') { b++; }

	if (str[2] == 'b') { b++; }

	if (str[0] == 'c') { c++; }

	if (str[1] == 'c') { c++; }

	if (str[2] == 'c') { c++; }

	if (a == 1 && b == 1 && c == 1) { printf("Yes"); }
	else { printf("No"); }
	
	
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);

    int n,x,y;
    cin >> n >> x >> y;
    map<int,int> arr[n];

    // construction of naive map
    for (int i=0;i<=n-1;i++)
    {
        for (int j=0;j<=n-1;j++)
        {
            arr[i].insert(make_pair(j,abs(i-j)));
        }
    }

    // indexing of x-y pair
    for (int i=0;i<=n-1;i++)
    {
        int alpha=arr[x-1][i];
        int beta=arr[y-1][i];
        arr[x-1][i]=min(alpha,beta+1);
    }
    
    for (int i=0;i<=n-1;i++)
    {
        int alpha=arr[x-1][i];
        int beta=arr[y-1][i];
        arr[y-1][i]=min(alpha+1,beta);
    }

    // recalculationg naive map
    for (int i=0;i<=n-1;i++)
    {
        for (int j=0;j<=n-1;j++)
        {
            int alpha=arr[i][j];
            int beta=arr[i][x-1]+arr[x-1][j];
            int gamma=arr[i][y-1]+arr[y-1][j];
            arr[i][j]=min(min(alpha,beta),gamma);
        }
    }

    int counter[n][n];
    for (int i=0;i<=n-1;i++)
    {
        for (int j=0;j<=n-1;j++)
        {
            counter[i][j]=0;
        }
    }

    for (int i=0;i<=n-1;i++)
    {
        for (int j=0;j<=n-1;j++)
        {
            int value=arr[i][j];
            counter[i][value-1]++;
        }
    }

    for (int value=0;value<=n-2;value++)
    {
        int ans=0;
        for (int i=0;i<=n-1;i++)
        {
            ans=ans+counter[i][value];
        }
        cout << ans/2 << endl;
    }

    return 0;
}


Measured memory_bytes: 203520
n = int(input())
raw = list(map(int,input().split()))
a = 0
for i in range(n):
  a += (-1) ** i * raw[i]
ans = [a]
for i in range(n-1):
  ans.append(2*raw[i]-ans[-1])
print(' '.join(list(map(str,ans))))

Measured memory_bytes: 19144
#include <bits/stdc++.h>
using namespace std;
int INF = 1000000007;

int main(){
  int A[3];
  cin >> A[0] >> A[1] >> A[2];
  sort(A, A+3);
  int N, M;
  N = A[2] - A[1];
  M = A[2] - A[0];
  if((M + N) % 2 == 0){
    cout << (N+M)/2 << endl;
  }
  else{
    cout << (N+M+3)/2 << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


signed main(){
  string a, b, c; cin>>a>>b>>c;
  cout << a[0] << b[1] << c[2] << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define fi first
#define sc second
#define pii pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define msi map<string,int>
#define si set<int>
#define all(v) v.begin(),v.end()
#define sz(v)  int((v).size())
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define dep(i,a,b)    for(int i=a;i>=b;i--)
#define isinarr(i,n) ((i>=0)?((i<n)?1:0):0)
#define fastio  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ppb pop_back
#define lb lower_bound
#define ub upper_bound
#define present(container, element) (container.find(element) != container.end())      //set,map etc.
#define cpresent(container, element) (find(all(container),element) != container.end())    //vector
#define hell 1000000007
#define PI 3.14159265
#define mp make_pair
#define inparr(a,n) rep(i,0,n)cin>>a[i];
#define strwspaces(s) getline(cin,s)
#define give(x,y) cout<<x<<" "<<y<<endl;
#define setp(n) cout<<fixed<<setprecision(n);
#define    endl '\n'
#define inp(n) int n;cin>>n;

using namespace std;

int i,j,k,l;

void solve()
{
    int a[6];
    rep(i,1,6)
    {
      cin>>a[i];
      if(a[i]==0)
        cout<<i<<endl;
    }
} 



signed main()
{
    fastio
    int t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 3604
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}


int main() {

    vector<long long> facts;

    for (int i = 1; i * 7 + 1 < 300000; i++) facts.push_back(i * 7 + 1);
    for (int i = 0; i * 7 + 6 < 300000; i++) facts.push_back(i * 7 + 6);
    sort(facts.begin(), facts.end());

    vector<long long> primes;
    for (int i = 0; i < facts.size(); i++) {
        bool good = true;
        for (int j = 0; facts[j] * facts[j] <= facts[i]; j++) if (facts[i] % facts[j] == 0) good = false;
        if (good)primes.push_back(facts[i]);
    }
  // SHOW_VECTOR(primes);

    while (true) {

        long long N;
        cin >> N;

        if (N == 1) break;

        vector<long long> ans;
        for (int i = 0; i< primes.size(); i++) {
            if (N % primes[i] == 0) {
                ans.push_back(primes[i]);
            }
        }

        cout << N << ":";
        for (int i = 0; i < ans.size(); i++) cout<< " " << ans[i] ;
        cout << endl;

    }

    return 0;
}












































































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

using namespace std;

#define int long long

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b >= c - 1)
        cout << b + c;
    else
        cout << b + (a + b + 1);
}


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

int main() {
    int N; cin >> N;
    int ans = 0;
    REP(i, 0, N) {
        int a; cin >> a;
        ans += (a - 1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
    String a = sc.next();
      if(a.charAt(2) == a.charAt(3) && a.charAt(4) ==a.charAt(5))
        System.out.println("Yes");
      else
        System.out.println("No");
    }
      
      
}

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

#define int long long
#define pb push_back
#define mod 1000000007
#define w(x) int x;cin>>x; while(x-->0)

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void mysol()
{
    int n, k; cin >> n >> k;
    int arr[n];
    for (int &a : arr)
        cin >> a;
    vector<int> dp(n, INT_MAX);
    dp[0] = 0;
    dp[1] = abs(arr[1] - arr[0]);
    // cout << dp[1] << ' ';
    for (int i = 2; i < n; i++)
    {
        for (int j = (i - k > 0 ? i - k : 0); j < i; j++)
            dp[i] = min(dp[i], dp[j] + abs(arr[j] - arr[i]));
        // cout << dp[i] << ' ';
    }
    cout << dp[n - 1];

}

int32_t main()
{
    fast();
    // w(t)
    {
        mysol();
    }
    return 0;
}



Measured memory_bytes: 1920
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp make_pair
#define fi first
#define se second
#define pt(num) cout << num << "\n"
#define mCalc(a, s, b) (a)=((a)s(b))%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;



int main(void) {
    string s;
    cin >> s;
    
    if(s.size()%2==0) {
        if(s[0]==s[s.size()-1]) puts("First");
        else puts("Second");
    }else {
        if(s[0]==s[s.size()-1]) puts("Second");
        else puts("First");
    }
    
    
    
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    ll h, w;
    cin >> h >> w;

    ll res;
    if (h == 1 || w == 1) res = 1;
    else res = (h * w + 1) / 2;

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
/**
 * 単一始点最短経路
 * https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/all/GRL_1_A
 * ダイクストラ法
 * */

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

#define INF 1LL<<60 //使いやすい無限(ll)

/* 詳細なグラフ定義 */
using Node = long long; //頂点
using Distance = long long; //距離
using Weight = long long; //重み
using Edge = pair<Node, Weight>; //辺
using Graph = vector<vector<Edge>>; //隣接リスト

ll V,E,r;
Graph G;
vector<Distance> dist;

void dijkstra(Node start){
  priority_queue<
    pair<Distance, Node>,
    vector<pair<Distance, Node>>,
    greater<pair<Distance, Node>>
    //Distanceの小さいものから取り出す
  >que;
  
  dist.resize(V, INF);
  dist[r] = 0;
  que.push({0, start}); //距離0の頂点rを入れる

  while(!que.empty()){
    Distance nowDist;
    Node nowNode;
    tie(nowDist, nowNode) = que.top(); que.pop();
    if(nowDist > dist[nowNode])continue;

    for(Edge next: G[nowNode]){
      Node nextDir = next.first;
      Weight nextWeight = next.second;

      if(dist[nextDir] <= dist[nowNode]+nextWeight)continue;
      dist[nextDir] = dist[nowNode] + nextWeight;
      que.push({dist[nextDir], nextDir});
    }
  }
}

int main(){
  cin>>V>>E>>r;
  G.resize(V);

  for(int i=0; i<E; i++){
    int s,t,d;
    cin>>s>>t>>d;
    G[s].push_back({t, d});
  }

  dijkstra(r);

  for(ll x: dist){
    if(x==INF){
      cout<<"INF"<<endl;
    }else{
      cout<<x<<endl;
    }
  }
}


Measured memory_bytes: 19380
N = int(input())
L = list(map(int,input().split()))
for i in range(N):
    L[i] = L[i] - (i+1)
L = sorted(L)
#print(L)
ans = 0
n=len(L)
med = int(L[(n+1)//2-1])
#print(med)
for i in range(N):
    ans+=abs(L[i]-med)
print(ans)



Measured memory_bytes: 88148
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
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)
#define all(x) begin(perm),end(perm)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
    vector<vector<int>> bingo(3,vector<int>(3));
    rep(i,3)rep(j,3)cin>>bingo[i][j];
    int n; cin>>n;
    vector<vector<int>> result(3,vector<int>(3,0));
    rep(k,n){
        int tmp; cin>>tmp;
        rep(i,3)rep(j,3){
            if(bingo[i][j] == tmp)result[i][j] = 1;
        }
    }
    bool ans = false;
    rep(i,3){
        if(result[1][i] == 1&&result[2][i] == 1&&result[0][i] == 1)ans = true;
    }
     rep(i,3){
        if(result[i][0] == 1&&result[i][1] == 1&&result[i][2] == 1)ans = true;
    }
    if(result[0][0] == 1&&result[1][1] == 1&&result[2][2] == 1)ans = true;
    if(result[0][2] == 1&&result[1][1] == 1&&result[2][0] == 1)ans = true;
    cout<<((ans)?"Yes":"No")<<endl;
}


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

const ll mod = 1000000007;
const int INF = 1001001001;

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<ll> a(n);
	vector<ll> sum(n + 1);
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < n; i++){
		sum[i + 1] = sum[i] + a[i];
	}
	ll ans = 0;
	for(int i = 0; i < n - 1; i++){
		//cout << a[i] << " " << sum[n] - sum[i + 1] << endl;
		ans += a[i] * ((sum[n] - sum[i + 1]) % mod);
		ans = ans % mod;
	}
	cout << ans << endl;
} 

Measured memory_bytes: 6356
#include<bits/stdc++.h>
using namespace std;
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define F first
#define S second
#define pb emplace_back
#define mt make_tuple
#define gcd __gcd
#define PI 3.141592653589
// Input
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define llin(a) cin >> a
#define inl(a) scanf("%lld",&a)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
// Output
#define pr(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d\n",a,b)
#define pr3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out(a) printf("%d\n",a)
#define outl(a) printf("%lld\n",a)
#define llpr(a) cout << a << " "
#define llout(a) cout << a << "\n"
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
// Iterator
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
// Debug
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define what(x) cerr << #x << " : " << x << "\n"
#define ck printf("continue\n")
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
	cerr << *it << " = " << a << "\n";
	err(++it, args...);
}
// Data Type
#define ll long long int
#define ii pair<int,int>
#define pli pair<ll,int>
#define triple tuple<int,int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define M 1000000007
#define N 1000  //check the limits, man
const ll INF = 1e12;
int main()
{
    string str;
    llin(str);
    int i,n,k;
    n=str.size();
    k=0;
    rep(i,n-1)
        if(str[i]!=str[i+1])k++;
    out(k);
}




Measured memory_bytes: 512
# https://atcoder.jp/contests/arc026/tasks/arc026_2
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  d,g=LI()
  l=[LI() for _ in range(d)]

  ans=inf
  for i in range(2**d):
    sm=0
    cnt=0
    _l=[0]*d
    for j in range(d):
      if i&(1<<j):
        cnt+=l[j][0]
        sm+=l[j][0]*(j+1)*100+l[j][1]
        _l[j]=1

    if sm<g:
      while True:
        for k in range(d)[::-1]:
          if _l[k]==0:
            _l[k]=2 # for debug
            if sm+(k+1)*100*(l[k][0]-1)>=g:
              _cnt=(g-sm+(k+1)*100-1)//((k+1)*100)
              cnt+=_cnt
              sm+=_cnt*(k+1)*100
              break
            else:
              cnt+=l[k][0]-1
              sm+=(k+1)*100*(l[k][0]-1)

        break

    if sm>=g:
      ans=min(ans,cnt)

    # print(cnt,sm,_l)

  return ans

# main()
print(main())


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

using namespace std;

#define int long long
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

typedef pair<int,int> PI;
typedef pair<int,pair<int,int>> PII;
static const int INF=1010000000000000017LL;
static const double eps=1e-12;
static const double pi=3.14159265358979323846;
static const int dx[4]={1,-1,0,0};
static const int dy[4]={0,0,1,-1};
static const int ddx[8]={1,-1,0,0,1,1,-1,-1};
static const int ddy[8]={0,0,1,-1,1,-1,1,-1};

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

int N,M,Q;
int A[55],B[55],C[55],D[55];
vector<int> tmp;
vector<vector<int>> v;

void dfs(int n,int p){
    if(n==N){
        v.push_back(tmp);
        return ;
    }
    for(int i=p;i<=M;++i){
        tmp.push_back(i);
        dfs(n+1,i);
        tmp.pop_back();
    }
}

signed main(){
    cin>>N>>M>>Q;
    for(int i=0;i<Q;++i){
        cin>>A[i]>>B[i]>>C[i]>>D[i];
        A[i]--,B[i]--;
    }
    dfs(0,1);
    int ans=0;
    for(auto u:v){
        int res=0;
        for(int i=0;i<Q;++i){
            //cout << u[i] << " ";
            if(u[B[i]]-u[A[i]]==C[i])res+=D[i];
        }
        //cout << endl;
        //cout << res << endl;
        chmax(ans,res);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 13956
N = int(input())
ANS=[]

for i in range(N):
    S,P = input().split()
    ANS += [[i,S,int(P)]]

ANS= sorted(ANS,reverse=True, key=lambda x: x[2])
ANS= sorted(ANS, key=lambda x: x[1])

for i in range(N):
    print(ANS[i][0]+1)


Measured memory_bytes: 3060
#include<stdio.h>
int main(){
  int i,j;
  int n;
  scanf("%d",&n);
  double x[4][n],y[4][n];
  for(i=0;i<n;i++){
    for(j=0;j<4;j++){
      scanf("%lf%lf",&x[j][i],&y[j][i]);
    }
  }
  for(i=0;i<n;i++){
    if((x[1][i]-x[0][i])*(y[3][i]-y[2][i])==(y[1][i]-y[0][i])*(x[3][i]-x[2][i])){
      puts("YES");
    }else{
      puts("NO");
    }
  }
  return 0;
}

Measured memory_bytes: 0
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>
#include <cstdint>
#include <complex>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef unsigned long long		SQWORD;

/*-----------------------------------------------------------------------------
　幾何学ライブラリ
 -------------------------------------------------------------------------------*/
/* 基本要素 */
typedef double D;      // 座標値の型。doubleかlong doubleを想定
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;
const D EPS = 1e-9;    // 許容誤差。問題によって変える
#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)
namespace std {
  bool operator<(const P a, const P b) {
    return a.X != b.X ? a.X < b.X : a.Y < b.Y;
  }
}

/*-----------------------------------------------------------------------------
　メイン
 -------------------------------------------------------------------------------*/
int main()
{
	int N;
	cin >> N;
	string S = "ABD";
	if (N < 1000) S = "ABC";

	cout << S << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int A = sc.nextInt();
		int B = sc.nextInt();

		sc.close();

		for (int i = 1; i < 110000; i++) {
			if ((int) (i * 0.08) == A && (int) (i * 0.1) == B) {
				out.println(i);
				return;
			}
		}
		out.println(-1);

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}
}


Measured memory_bytes: 24148
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

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());
    }
}

public class Main {
    static int MOD = 1000000007;

    public static class Mas {
        int x;
        int y;
        int step;

        Mas(int x, int y, int step) {
            this.x = x;
            this.y = y;
            this.step = step;
        }
    }

    private static final int[] vX = { 1, 0, 0, -1 };
    private static final int[] vY = { 0, 1, -1, 0 };

    public static void main(String[] args) {

        FastScanner fs = new FastScanner();
        int n = fs.nextInt();
        int m = fs.nextInt();
        System.out.println((n - 1) * (m - 1));

    }

}


Measured memory_bytes: 21204
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    N,K = LMIIS()
    S = input()
    people = [0]
    

    count = 0
    pre = S[0]
    for c in S:
        if pre == c:
            count += 1
        else:
            pre = c
            people.append(count)
            count = 1
    people.append(count)
    
    while len(people) > 2 and K > 0:
        fusion = people[-1] + people[-2] + people[-3]
        for _ in range(3):
            people.pop()
        people.append(fusion)
        K -= 1
    print(sum(people)-len(people)+people.count(0))
        



        
            






if __name__ == '__main__':
    main()

Measured memory_bytes: 45424
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const signed INF_=1001001001; const int INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
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;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N=IN,M=IN;
    vector<vector<int>> A(N,vector<int>(M));
    cin>>A;

    vector<int> use(M,true);
    function<int()> rec=[&]()->int {
        if(count(ALL(use),true)==1) return N;
        
        vector<int> num(M,0);
        REP(i,N) {
            REP(j,M) {
                if(use[A[i][j]-1]) {
                    num[A[i][j]-1]++;
                    break;
                }
            }
        }
        int mx=(*max_element(ALL(num)));
        REP(i,M) if(num[i]==mx) use[i]=false;
        return min(mx,rec());
    };
    cout<<rec()<<endl;
    return 0;
}


Measured memory_bytes: 1664
import copy

# Union-Find
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]


def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return False
    if par[x] > par[y]:
        x, y = y, x
    par[y] = x
    return True


def same(x, y):
    return find(x) == find(y)


def size(x):
    return -par[find(x)]


N, M = map(int, input().split())
Road = [tuple(map(int, input().split())) for _ in range(M)]
ans = 0
for i in range(M):
    Roadi = copy.deepcopy(Road)
    par = [-1] * N
    for j, r in enumerate(Road):
        if i == j:
            continue
        ra, rb = r
        ra -= 1
        rb -= 1
        unite(ra, rb)
    if par.count(-1) > 1:
        ans += 1

print(ans)

Measured memory_bytes: 3444
#include<stdio.h>
#define Q 8
int Search(int *,int);

int main(){
  int queens[Q];
  int n,k,i,j;
  scanf("%d",&n);
  for(i=0;i<Q;i++)queens[i]=-1;
  while(n--){
    scanf("%d %d",&i,&j);
    queens[i]=j;
  }
  Search(&queens[0],0);

  for(i=0;i<Q;i++){
    for(j=0;j<Q;j++){
      if(queens[i] == j)printf("Q");
      else printf(".");
    }
    printf("\n");
  }

  return 0;
}

int Search(int *queens,int k){
  int i,j;
  int check[Q];
  if(k == Q)return 1;
  if(queens[k] != -1){
    if(0 == Search(queens,k+1))return 0;
    else return 1;
  }
  for(i=0;i<Q;i++)check[i]=0;
  for(i=0;i<Q;i++)if(queens[i] != -1){
      check[queens[i]] = 1;
      for(j=0;j<Q;j++)if( k+j == queens[i]+i || k - j == i - queens[i] )check[j]=1;
    }
  //printf("%d check:",k);
  //for(i=0;i<Q;i++)printf(" %d",check[i]);
  //printf("\n");
  for(i=0;i<Q;i++)if(check[i] == 0){
      queens[k]=i;
      if(1 == Search(queens,k+1))return 1;
    }
  queens[k]=-1;
  return 0;
}
    
      
  

    
      
      
    
			    



Measured memory_bytes: 2112
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdlib.h>
#include<stack>
#include<set>
#include<string.h>
#include<map>
#include<vector>
#define pb push_back
#define ins insert 
#define mp make_pair
#define fi first
#define se second
#define ll long long 
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define M 10000000000000000
using namespace std;
int main(){
    //double start_time = clock();
    ll n,k,q;
    cin>>n>>k;
    ll a[n],dp[n]={0};
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
        dp[i]=M;
    }
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for (ll i = 2; i < n; ++i)
        {
            q=0;
            for (ll j = i-1;j>=0 && j>=i-k; --j)
            {
                dp[i] = min(dp[i],dp[j]+abs(a[j]-a[i]));
            }
        }
    //double end_time = clock();
    //printf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000);
    cout<<dp[n-1];
    return 0;
}

Measured memory_bytes: 1792
n = int(input())
m = n
s = ''

if m == 0 :
   print('0')

while m != 0 :

   if m%2 == 0 :
      s = '0' + s
      m = m / (-2)
   else :
      s = '1' + s
      m = (m-1) / (-2)

print(s)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,count=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int a,b;
		cin>>a>>b;
		if(a==b)
		{
			count++;
			if(count==3)
			{
				cout<<"Yes";
				return 0;	
			}
				
		}
		else
			count=0;
	}
	cout<<"No";
	return 0;
}

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

using namespace std;

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

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

    vector< vector<int> > ans(h, vector<int>(w));
    int cur = 0;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            while (a[cur] == 0) ++cur;
            if (i & 1) {
                ans[i][j] = cur + 1;
                --a[cur];
            } else {
                ans[i][w - 1 - j] = cur + 1;
                --a[cur];
            }
        }
    }

    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cout << ans[i][j] << " ";
        }
        cout << "\n";
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rem(i, m, n) for (int i = m; i < (n); i++)
#define eps (1e-7)
#define inf (1e9)
#define pi (acos(-1))
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

    int h, w;
    cin >> h >> w;
    vector<vector<char>> a(h + 2, vector<char>(w + 2, '#'));
    rep(i, h) rep(j, w) cin >> a[i + 1][j + 1];

    rep(i, h + 2)
    {
        rep(j, w + 2) cout << a[i][j];
        cout << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
s = input()
length = len(s)
for i in range((length-1)**2-1):
  t = ['-']*(length-1)
  for j in range(length-1):
    if (i>>j)&1:
      t[j] = '+'
  a = ''
  for se,te in zip(s,t+['']):
    a += se + te
  if eval(a)==7:
    print(a+'=7')
    break


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define LOWER(a,x) lower_bound(ALL(a), x) - a.begin() - 1;
#define COUNT(a,x)  upper_bound(ALL(a), x) - lower_bound(ALL(a), x);
#define MCOUNT(a,x,y) upper_bound(ALL(a), y) - lower_bound(ALL(a), x);
#define SCAN(x) scanf("%lld",&x);
#define INF 5555555555555555555
#define MOD 1000000007
#define pb push_back
#define F first
#define S second
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = 0, mi = 0;
string s;
bool flag, ok;
ll dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111



int main(void) {
  cin >> n;
  vll a;
  FOR(i, 0, n) {
	cin >> tmp;
	sum += tmp;
	a.pb(tmp);
  }

  sort(ALL(a));

  if (sum % 10 == 0) {
	FOR(i, 0, n) {
	  if ((sum - a[i]) % 10 != 0) {
		sum -= a[i];
		break;
	  }
	}
  }
  if (sum % 10 == 0) sum = 0;
  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Map;
import java.util.Scanner;
import java.util.HashMap;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CandyDistribution solver = new CandyDistribution();
        solver.solve(1, in, out);
        out.close();
    }

    static class CandyDistribution {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            long m = in.nextLong();

            long sum = 0;
            Map<Long, Long> mod = new HashMap<>();
            mod.put(0L, 1L);

            for (int i = 1; i <= n; i++) {
                long a = Long.parseLong(in.next());
                sum += +a;
                mod.put(sum % m, mod.getOrDefault(sum % m, 0L) + 1);
            }

            long result = 0;
            for (long key : new ArrayList<>(mod.keySet())) {
                long v = mod.get(key);
                result += v * (v - 1) / 2;
            }
            ;
            out.println(result);

        }

    }
}



Measured memory_bytes: 63028
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;

// ===============================================================

ll gcd(ll a, ll b) //最大公約数
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}

ll lcm(ll a, ll b) //最小公倍数
{
	return a * b / gcd(a, b);
}

ll box(double a) //doubleの切り捨て
{
	ll b = a;
	return b;
}

ll fff(double a) //doubleの四捨五入
{
	ll b = a + 0.5;
	return b;
}

ll sum(ll n) { //整数sまでの合計
	if (n == 0) {
		return 0;
	}

	int s = sum(n - 1);
	return s + n;
}

bool prime(ll num)//素数判定、primeならtrue,違うならfalse
{
	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, x;
	cin >> n >> x;
	vl a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	if (n == 1) {
		cout << abs(a[0] - x) << endl;
	}
	else {
		sort(a.begin(), a.end());
		ll count;
		vl b(n);
		ll junbi = 0;
		for (int i = 0; i < n - 1; i++) {
			if (x < a[n - 1] && x>a[0]) {
				if (a[i]<x && a[i + 1]>x) {
					b[i] = x - a[i];
					b[i + 1] = a[i + 1] - x;
					junbi++;
				}
			}
			else {
				if (x < a[n - 1]) {
					b[0] = a[0] - x;
					junbi++;
				}
				else {
					b[n - 1] = x - a[n - 1];
				}
			}
			b[i + junbi] = a[i + 1] - a[i];
		}
		count = b[0];
		for (int i = 0; i < n; i++) {
			count = gcd(count, b[i]);
		}
		cout << count << endl;
	}
}

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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++) 
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.x << ", " << a.y << ")";
}

template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "]";
}

mt19937 rnd(time(NULL));

const int INF = int(1e9);
const li INF64 = li(1e18);
const int MOD = INF + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);

const int N = 100 * 1000 + 13;

int n;
int a[N][3];

bool read () {
	if (scanf("%d", &n) != 1)
		return false;
	forn(i, n) forn(j, 3)
		scanf("%d", &a[i][j]);
	return true;
}

int dp[N][3];

void solve(){
	forn(i, n + 1) forn(j, 3) dp[i][j] = -INF;
	dp[0][0] = dp[0][1] = dp[0][2] = 0;
	forn(i, n) forn(j, 3) forn(k, 3) if (j != k){
		dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + a[i][k]);
	}
	printf("%d\n", max({dp[n][0], dp[n][1], dp[n][2]}));
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	
	int tt = clock();
	
#endif
	
	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;

	while(read()) {	
		solve();
		
#ifdef _DEBUG
	cerr << "TIME = " << clock() - tt << endl;
	tt = clock();
#endif

	}
}

Measured memory_bytes: 2560
<?php
  $n = trim(fgets(STDIN));
  $u = explode(" ",trim(fgets(STDIN)));
  sort($u);
  $worth = ($u[0]+$u[1])/2;
  for($i=2; $i<$n; $i++){
    $worth = ($u[$i]+$worth)/2;
  }
  echo $worth."\n";

Measured memory_bytes: 4604
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
typedef long long ll;

int main(void){
    int n, d[100010];
    cin >> n;
    for (int i = 0; i < n; i++) cin >> d[i];
    sort(d, d + n);
    
    cout << d[n / 2] - d[n / 2 - 1] << endl;
    
}


Measured memory_bytes: 640
main = do
    line <- getLine
    putStrLn (format (date (read line)))

date :: Int -> [Int]
date second = [h, m, s]
    where s = mod second 60
          m = mod (div second 60) 60
          h = div second (60 * 60)

format :: [Int] -> String
format [h, m, s] = (show h) ++ ":" ++ (show m) ++ ":" ++ (show s)



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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

template<unsigned M>
struct mint{
	unsigned val;
	mint(unsigned x):val((x%M+M)%M){}
	mint inv()const{
		unsigned x=1;
		for(unsigned a=val,b=M,u=0;b;){
			ll t=a/b;
			swap(a-=b*t,b);
			swap(x-=u*t,u);
		}
		return mint(x+M);
	}
	mint& operator+=(const mint& x)&{if((val+=x.val)>=M) val-=M; return *this;}
	mint& operator-=(const mint& x)&{if((val+=M-x.val)>=M) val-=M; return *this;}
	mint& operator*=(const mint& x)&{val=(ll)val*x.val%M; return *this;}
	mint& operator/=(const mint& x)&{val=(ll)val*x.inv().val%M; return *this;}
};

template<unsigned M> bool operator==(const mint<M>& a,const mint<M>& b){return a.val==b.val;}
template<unsigned M> bool operator!=(const mint<M>& a,const mint<M>& b){return a.val!=b.val;}
template<unsigned M> mint<M> operator+(mint<M> a,const mint<M>& b){a+=b; return a;}
template<unsigned M> mint<M> operator-(mint<M> a,const mint<M>& b){a-=b; return a;}
template<unsigned M> mint<M> operator*(mint<M> a,const mint<M>& b){a*=b; return a;}
template<unsigned M> mint<M> operator/(mint<M> a,const mint<M>& b){a/=b; return a;}
template<unsigned M> ostream& operator<<(ostream& os,const mint<M>& x){return os<<x.val;}

int main()
{
	for(int a,b;cin>>a>>b&&a|b;){
		if(a>b)
			swap(a,b);
		if(b-a>1)
			cout<<0<<endl;
		else{
			mint<MOD> res=1;
			rep(i,a) res*=a-i;
			rep(i,b) res*=b-i;
			if(a==b) res*=2;
			cout<<res<<endl;
		}
	}
}


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

int mp[100005];

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

  int n;cin>>n;
  std::vector<int> v(n);
  for(int i=0;i<n;i++){
    cin>>v[i];
    int p = n - v[i] - 1;
    mp[p]++;
    if (v[i]%2==n%2 || v[i]>n || mp[p]>2 || (v[i] == 0 && mp[p]>1) ){
      cout<<0<<endl;
      return 0;
    }
  }
  ll mod = pow(10,9)+7;
  ll res=1;
  for(int i=0;i<n/2;i++){
    res = (res*2) % mod;
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define MAXN 100005
#define mod 998244353
#define INF 0x3f3f3f3f
#define ld long double
using namespace std;
vector<ll>ans[20];
vector<ll>as;
int main(){
    ios::sync_with_stdio(false);
    #define int ll
    int n;
    cin>>n;
    for(int i=1;i<10;i++){
        ans[1].push_back(i);
        as.push_back(i);
    }
    int s=9;
    for(int i=2;i<20;i++){
        for(int j=0;j<ans[i-1].size();j++){
            int tp=ans[i-1][j]%10;
            int temp;
            if(tp==0){
                temp=ans[i-1][j]*10;
                ans[i].push_back(temp);
                as.push_back(temp);
                temp+=1;
                ans[i].push_back(temp);
                as.push_back(temp);
            }
            else if(tp==9){
                temp=ans[i-1][j]*10+8;
                ans[i].push_back(temp);
                as.push_back(temp);
                temp+=1;
                ans[i].push_back(temp);
                as.push_back(temp);
            }
            else{
                temp=ans[i-1][j]*10+tp-1;
                ans[i].push_back(temp);
                as.push_back(temp);
                temp+=1;
                ans[i].push_back(temp);
                as.push_back(temp);
                temp+=1;
                ans[i].push_back(temp);
                as.push_back(temp);
            }
        }
        s+=ans[i].size();
    //    cout<<ans[i].size()<<' '<<i<<endl;
        if(s>n){
            break;
        }
    }
    sort(as.begin(),as.end());
    cout<<as[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 4464